Scriptvar settings

jonsilva

New member
hello
i wanted to alter a Scriptvar value in the entity .txt file
for exemple
in animation script.c
@cmd damchg will make the entity change to a follow anim if its health in lower than 90 and Scriptvar is less than number
void damchg()
{
    void self = getlocalvar("self");
  int Flag = getscriptvar("Flag" + self);
    int MHealth = getentityproperty(self,"maxhealth"); //get max hp
    int PHealth = 100*getentityproperty(self,"health")/MHealth; //work out hp percentage
if(Flag == NULL()){
  Flag=0;  // <---- Scriptvar is set to 0
}
if(PHealth<=90 && Flag < 1){performattack(self, openborconstant("ANI_FOLLOW10"));
}
else if(PHealth<=70 && Flag < 2){performattack(self,openborconstant("ANI_FOLLOW11"));
}
}

Is there a way to rename the value in Scriptvar flag from 1 to 2 so that it will play anim follow11 once its health reaches lower than 70%

entity .txt
anim idle
loop 1
delay 3
offset 100 189
bbox 79 97 50 91
frame data/chars/beyond/3overlord/idle39.gif
@cmd damchg
frame data/chars/beyond/3overlord/idle43.gif

anim follow10
@script
    void self = getlocalvar("self");
    if(frame==100){ // set variable at 1st frame
      setscriptvar("Flag" + self,1); <---- Flag should change from 0 to 1
    }
@end_script
loop 0
delay 12
offset 100 189
bbox 0 0 0 0
landframe 110 dust
frame data/chars/beyond/3overlord/chg01.gif

the problem here is that the entity keeps playing follow10 once he goes to idle
Scriptvar value should be 1 once it finishes playing anim follow10...



script var will then remain until the entity is removed from play
Entity vars remain until manually removed or the engine is shut down
 
Code:
 if(frame==100){ // set variable at 1st frame
      setscriptvar("Flag" + self,1); <---- goes from 0 to 1
}

The flag is set to 1 on frame 100. Are you sure this is what you want ? (because this is not what the right comment says).
 
its not very well explained... in damchg animations script Flag is set to 0...
if(Flag == NULL()){
Flag=0;  // <---- Scriptvar starts at 0

---------------------//--------------------------------------------

in  (follow10 anim) scriptvar Flag should change from 0 to 1... so that the anim wont play again....
if(frame==100){ // set variable at 1st frame
      setscriptvar("Flag" + self,1); <---- goes from 0 to 1
}

-----------------------------------------//---------------------------------
in script follow10 anim should only play if its less than 1
}
if(PHealth<=90 && Flag < 1 ){performattack(self, openborconstant("ANI_FOLLOW10"));
}
 
Yes I think I got that, I was just pointing out what seemed to be the problem ; that is the setscriptvar call in follow10 triggering on frame 100. 100 frames seems a lot, so I thought it was a typo which explained why the whole thing did not work properly (~ the flag was never set to 1).
 
I think I spotted couple stuffs which need improvement

if(Flag == NULL()){
  Flag=0;  // <---- Scriptvar is set to 0
}

This only sets Flag with 0 value. It doesn't do anything with the respective script var. You need to add another line to set that like this:

if(Flag == NULL()){
  Flag=0;
  setscriptvar("Flag" + self,0); // <---- Scriptvar is set to 0
}

Now the 2nd one,
if(PHealth<=90 && Flag < 1){performattack(self, openborconstant("ANI_FOLLOW10"));
}else if(PHealth<=70 && Flag < 2){performattack(self,openborconstant("ANI_FOLLOW11"));
}

The reason why the latter is never performed is because it's easier to get HP below 90% than 70%. Script checks the first condition first before going to 2nd and if the first condition is true, it will run the code even though 2nd condition is true too. It's best to type it like this:

if(PHealth<=70 && Flag < 2){performattack(self, openborconstant("ANI_FOLLOW11"));
}else if(PHealth<=90 && Flag < 1){performattack(self,openborconstant("ANI_FOLLOW10"));
}

Is there a way to rename the value in Scriptvar flag from 1 to 2 so that it will play anim follow11 once its health reaches lower than 70%

Well, you're the one who designed the script so you should be the one also who defined that ;)
 
thanks
it seems to be working now i think the problem was in the order follow anims were set.
ive only changed "Flag" to "flagg"
and had to removed the
if(Flag == NULL()){
  Flag=0;
  setscriptvar("Flag" + self,0); // <---- Scriptvar is set to 0
}
for some reason this if was causing a crash in log

this is how it looks now
animation script
void damchg()
{
    void self = getlocalvar("self");
    int MHealth = getentityproperty(self,"maxhealth"); //get max hp
    int PHealth = 100*getentityproperty(self,"health")/MHealth; //work out hp percentage
    float change = getscriptvar("flagg" + self);


if(PHealth<=45 && change == 3){performattack(self, openborconstant("ANI_FOLLOW17"));
}
else if(PHealth<=70 && change == 2){performattack(self,openborconstant("ANI_FOLLOW16"));
}
else if(PHealth<=90 && change == 1){performattack(self,openborconstant("ANI_FOLLOW15"));
}
}

entity.txt
anim spawn
@script
void self = getlocalvar("self");
setscriptvar("flagg" + self,1);
@end_script
loop 0
delay 2
offset 100 189
bbox 0 0 0 0
#-------------------------//------------------//--------------------------
anim idle
loop 1
delay 3
offset 100 189
bbox 79 97 50 91
      #@cmd clearL <----slamstart
frame data/chars/beyond/3overlord/idle39.gif
@cmd damchg
frame data/chars/beyond/3overlord/idle43.gif
#-------------------------//------------------//--------------------------
anim follow15
@script
void self = getlocalvar("self");
setscriptvar("flagg" + self,2);
@end_script
loop 0
delay 12
offset 100 189
bbox 0 0 0 0
#-------------------------//------------------//--------------------------
anim follow16
@script
void self = getlocalvar("self");
setscriptvar("flagg" + self,3);
@end_script
loop 0
delay 12
offset 100 189
bbox 0 0 0 0
#-------------------------//------------------//--------------------------
anim follow17
@script
void self = getlocalvar("self");
setscriptvar("flagg" + self,NULL());
@end_script
loop 0
delay 12
offset 100 189
bbox 0 0 0 0

but i also had to remove the clearL in idle...
it seems clearL is also cleaning scriptvars apart from localvariables...
i was trying to use diferent variables so i could give the slams more stability....

ive made this small change in killgun script
but i dont know if its working i cant see the variables anywere even if the entity is killed
void killgun(int Num, int Flag)
{ // Kill bound gun based on number
    void self = getlocalvar("self");
    void Gun = getentityvar(self, Num);

    if(Gun!=NULL()){
      bindentity(Gun, NULL());
      if(Flag==1){
        damageentity(Gun, self, 10000, 0, openborconstant("ATK_NORMAL"));
setentityvar(self, Num, NULL());
      } else {
        killentity(Gun);
setentityvar(self, Num, NULL());
      }
    }
}
ive made it so it could release that entityvar Num from memory
it seems entityvars stay in memory until the engine exits to Windows...
by using the script spawngun in almost every entity i could end up with a lot of entityvars after 1/2 hours of gameplay...
i dont dont know if this is right but 500 entityvars occupy 500mb memory?






 
Back
Top Bottom