move script help

Gurtag

Active member
hey guys i have been using script to replace move command as it is unreliable at the times.. but say script lacks some control.. wantedt to ask how can i mod it so it afects more than one frame at the time and also set at what frame stop if needed.....

this is the code..

Code:
void mover(int dx, int dz,int da)
{ // Moves entity freely and ignores obstacles
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int z = getentityproperty(self,"z"); //Get character's z coordinate
    int a = getentityproperty(self,"a"); //Get character's a coordinate
    int dir = getentityproperty(self,"direction"); //Get character's facing direction

     if(dir==0){ // Facing left?
      changeentityproperty(self, "position", x-dx, z+dz, a+da); //Move
     }
     else if(dir==1){ // Facing right?
      changeentityproperty(self, "position", x+dx, z+dz, a+da); //Move
     }
}

currently i use it like this

Code:
anim    pain5
    loop    0
    delay    8
    @cmd    mover -6 0 0
    bbox    12 1 35 111
    offset    31 129
    frame    data/chars/monk3/5000-20.gif
    @cmd    mover -6 0 0
    frame    data/chars/monk3/5000-20.gif
    @cmd    mover -6 0 0
    offset    29 136
    frame    data/chars/monk3/5000-0.gif
    @cmd    mover -6 0 0
    frame    data/chars/monk3/5000-0.gif

have to put it in every frame i want to move wich is a pita in larger animations...
 
hey guys i have been using script to replace move command as it is unreliable at the times.. but say script lacks some control.. wantedt to ask how can i mod it so it afects more than one frame at the time and also set at what frame stop if needed.....

this is the code..

Code:
void mover(int dx, int dz,int da)
{ // Moves entity freely and ignores obstacles
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int z = getentityproperty(self,"z"); //Get character's z coordinate
    int a = getentityproperty(self,"a"); //Get character's a coordinate
    int dir = getentityproperty(self,"direction"); //Get character's facing direction

     if(dir==0){ // Facing left?
      changeentityproperty(self, "position", x-dx, z+dz, a+da); //Move
     }
     else if(dir==1){ // Facing right?
      changeentityproperty(self, "position", x+dx, z+dz, a+da); //Move
     }
}

currently i use it like this

Code:
anim    pain5
    loop    0
    delay    8
    @cmd    mover -6 0 0
    bbox    12 1 35 111
    offset    31 129
    frame    data/chars/monk3/5000-20.gif
    @cmd    mover -6 0 0
    frame    data/chars/monk3/5000-20.gif
    @cmd    mover -6 0 0
    offset    29 136
    frame    data/chars/monk3/5000-0.gif
    @cmd    mover -6 0 0
    frame    data/chars/monk3/5000-0.gif

have to put it in every frame i want to move wich is a pita in larger animations...
If you want the entire animation to take effect, try adding it to the character's file like this. However, make sure to link the script to the correct file path.
1788598732839.png
 
Last edited:
If you want the entire animation to take effect, try adding it to the character's file like this. However, make sure to link the script to the correct file path.
View attachment 15907
never try that thanks for the tip man...


Why not declare it like this:
C:
anim    pain5
@script
  mover(-6, 0, 0);
@end_script
...

The mover function will be run at each frame.
hey man, i use that one too but it lacks the option to stop at say frame in same animation..
 
You could add frame check like this to control when function is run and when it is not run.
C:
anim    pain5
@script
  if(frame < 4){
    mover(-6, 0, 0);
  }
@end_script
...

if(frame < 4){ means the function is run from first frame to 4th frame.
There's no need to add another function to stop the movement cause if the function isn't run, there would be no movement.
 
You could add frame check like this to control when function is run and when it is not run.
C:
anim    pain5
@script
  if(frame < 4){
    mover(-6, 0, 0);
  }
@end_script
...

if(frame < 4){ means the function is run from first frame to 4th frame.
There's no need to add another function to stop the movement cause if the function isn't run, there would be no movement.
sorry for the late reply didnt have time to test stuf out.. that worked thanks a lot man...
 
There is a way but I find it easier to use dasher function instead. With that function, entity moves smoothly and won't ignore obstacles, platforms and walls.
 
hey guys i have been using script to replace move command as it is unreliable at the times.. but say script lacks some control.. wantedt to ask how can i mod it so it afects more than one frame at the time and also set at what frame stop if needed.....

this is the code..

Code:
void mover(int dx, int dz,int da)
{ // Moves entity freely and ignores obstacles
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int z = getentityproperty(self,"z"); //Get character's z coordinate
    int a = getentityproperty(self,"a"); //Get character's a coordinate
    int dir = getentityproperty(self,"direction"); //Get character's facing direction

     if(dir==0){ // Facing left?
      changeentityproperty(self, "position", x-dx, z+dz, a+da); //Move
     }
     else if(dir==1){ // Facing right?
      changeentityproperty(self, "position", x+dx, z+dz, a+da); //Move
     }
}

currently i use it like this

Code:
anim    pain5
    loop    0
    delay    8
    @cmd    mover -6 0 0
    bbox    12 1 35 111
    offset    31 129
    frame    data/chars/monk3/5000-20.gif
    @cmd    mover -6 0 0
    frame    data/chars/monk3/5000-20.gif
    @cmd    mover -6 0 0
    offset    29 136
    frame    data/chars/monk3/5000-0.gif
    @cmd    mover -6 0 0
    frame    data/chars/monk3/5000-0.gif

have to put it in every frame i want to move wich is a pita in larger animations...
You could probably make this a lot easier by storing the movement values and applying them over a range of frames instead of calling mover manually on every single frame.

One option would be to use a counter with getlocalvar and setlocalvar, tracking how many frames have passed since the movement started. Then you could pass the movement distance, starting frame and stopping frame as parameters, and only move the entity while the counter is within that range.

Just keep in mind that your current function moves the entity by a fixed amount every time it's called. If you want it to move continuously over several frames, you'll need something that gets executed on each frame during the selected interval. Also, be careful with how you track the animation frame, since animation frame indices and elapsed game frames aren't necessarily the same thing.

Depending on which version of OpenBOR you're using, there may already be animation commands or script callbacks that can handle this more cleanly. Which version are you working with? That would help narrow down the best approach without making the script more complicated than it needs to be.
 
You could probably make this a lot easier by storing the movement values and applying them over a range of frames instead of calling mover manually on every single frame.

One option would be to use a counter with getlocalvar and setlocalvar, tracking how many frames have passed since the movement started. Then you could pass the movement distance, starting frame and stopping frame as parameters, and only move the entity while the counter is within that range.

Just keep in mind that your current function moves the entity by a fixed amount every time it's called. If you want it to move continuously over several frames, you'll need something that gets executed on each frame during the selected interval. Also, be careful with how you track the animation frame, since animation frame indices and elapsed game frames aren't necessarily the same thing.

Depending on which version of OpenBOR you're using, there may already be animation commands or script callbacks that can handle this more cleanly. Which version are you working with? That would help narrow down the best approach without making the script more complicated than it needs to be.
hey there thanks a lot for the help, been using dasher function that bloodbane sujested and it works so far but will def study what you explained though i am far from that level yet..
 
Back
Top Bottom