I created the same script for the cpu partner.

Steven1985

Active member
The following script I have adapted it for the cpu-controlled character. Is it OK?
C:
anim    attack3
@script
    if(frame == 0) {
        if (readKey("b")) { changeState("GRABBACKWARD"); } 
        else if (readKey("f")) { changeState("GRABFORWARD"); }
    }
@end_script   
    
    #fastattack    1
    hitfx    data/sounds/beat3.wav
    loop    0
    offset    238 177
    bbox    222 102 33 76
    sound    data/sounds/punisher08.wav
    delay    3
    frame    data/chars/players/punisher/a301.gif
    frame    data/chars/players/punisher/a302.gif
    frame    data/chars/players/punisher/a303.gif
    sound    data/sounds/vuu3.wav
    delay    10
    attack    240 105 69 60 20 1 0 0 30 15
    frame    data/chars/players/punisher/a304.gif
    attack    0     0     0     0     0     0     0     0     0
    delay    4
    frame    data/chars/players/punisher/a305.gif
    frame    data/chars/players/punisher/a306.gif
    frame    data/chars/players/punisher/a307.gif

C:
anim attack3
@script
if(frame == 0) {
     int randomAction = rand()%3; // Generate a random number between 0 and 2
        
     if (randomAction == 0) {
         changeentityproperty(self, "animation", openborconstant("ANI_GRABBACKWARD"));
     } else if (randomAction == 1) {
         changeentityproperty(self, "animation", openborconstant("ANI_GRABFORWARD"));
     }
 }
@end_script
 #fastattack    1
    hitfx    data/sounds/beat3.wav
    loop    0
    offset    238 177
    bbox    222 102 33 76
    sound    data/sounds/punisher08.wav
    delay    3
    frame    data/chars/players/punisher/a301.gif
    frame    data/chars/players/punisher/a302.gif
    frame    data/chars/players/punisher/a303.gif
    sound    data/sounds/vuu3.wav
    delay    10
    attack    240 105 69 60 20 1 0 0 30 15
    frame    data/chars/players/punisher/a304.gif
    attack    0     0     0     0     0     0     0     0     0
    delay    4
    frame    data/chars/players/punisher/a305.gif
    frame    data/chars/players/punisher/a306.gif
    frame    data/chars/players/punisher/a307.gif
 
This is not OK:
C:
int randomAction = rand()%3; // Generate a random number between 0 and 2

rand()%3 generates random number between -3 to 3.
This causes the NPC to rarely performs GRABFORWARD or GRABBACKWARD.
To solve this, you'd need to change the script into this:
C:
  int rA = rand()%3+3; // Generate a random number between 0 and 6

     if (rA%3 == 0) {
         changeentityproperty(self, "animation", openborconstant("ANI_GRABBACKWARD"));
     } else if (rA%3 == 1) {
         changeentityproperty(self, "animation", openborconstant("ANI_GRABFORWARD"));
     }
 
This is not OK:
C:
int randomAction = rand()%3; // Generate a random number between 0 and 2

rand()%3 generates random number between -3 to 3.
This causes the NPC to rarely performs GRABFORWARD or GRABBACKWARD.
To solve this, you'd need to change the script into this:
C:
  int rA = rand()%3+3; // Generate a random number between 0 and 6

     if (rA%3 == 0) {
         changeentityproperty(self, "animation", openborconstant("ANI_GRABBACKWARD"));
     } else if (rA%3 == 1) {
         changeentityproperty(self, "animation", openborconstant("ANI_GRABFORWARD"));
     }
Thank you very much :)
 
Oh I forgot to inspect the whole script.
It should be like this:
C:
anim attack3
@script
  if(frame == 0) {
    void self = getlocalvar("self"); //Get calling entity
    int rA = rand()%3+3; // Generate a random number between 0 and 6

    if(rA%3 == 0) {
      changeentityproperty(self, "animation", openborconstant("ANI_GRABBACKWARD"));
    } else if (rA%3 == 1) {
      changeentityproperty(self, "animation", openborconstant("ANI_GRABFORWARD"));
    }
  }
@end_script
...
 
Oh I forgot to inspect the whole script.
It should be like this:
C:
anim attack3
@script
  if(frame == 0) {
    void self = getlocalvar("self"); //Get calling entity
    int rA = rand()%3+3; // Generate a random number between 0 and 6

    if(rA%3 == 0) {
      changeentityproperty(self, "animation", openborconstant("ANI_GRABBACKWARD"));
    } else if (rA%3 == 1) {
      changeentityproperty(self, "animation", openborconstant("ANI_GRABFORWARD"));
    }
  }
@end_script
...
Thank you now it works :)!
 
Back
Top Bottom