Projectile's palette according the parent's one

16-bit Fighter

Active member
In my mod a char uses the projectile command and I'd like the projectile's palette to be according the char's one.

I created an onspawnscript for the projectile's entity but nothing happens:

C:
void main ()

{

    void self = getlocalvar("self");

    void parent = getentityproperty(self, "parent");

    int PMap = getentityproperty(parent, "map");

    if(parent!=NULL()){

    changeentityproperty(self, "map", PMap);

    }

}

Any idea about the problem please?
 
Solution
@Kratus:
It makes OB shut down.

The log:
I looked the code again and added a necessary step, please try this new one.

C:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
    void vShot;
    void self = getlocalvar("self");
    int Direction = getentityproperty(self, "direction");
    int x = getentityproperty(self, "x");
    int y = getentityproperty(self, "a");
    int z = getentityproperty(self, "z");
    int map = getentityproperty(self, "map");

    if (Direction == 0){ //Is entity facing left?                
        dx = -dx; //Reverse X direction to match facing
    }
    vShot = projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
    changeentityproperty(vShot, "map", map);
    return...
How are you spawning your projectile?
I was wrong, sorry, I actually use the command toss, not projectile:

C:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }

   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}
 
This is how I do it when spawning a projectile, but both projectile and parent need to have their colors in the same color table. I have not tried it with separate color tables for each of those two, but this is all I know.

Remove that if condition from it, so you let that changeentityproperty function be outside along with those.

BTW the script looks similar to what I did weeks ago. I can spawn it with spawnframe or spawning scripts.

default-png.3811


EDIT:
C:
void main ()
{
    void self = getlocalvar("self");
    void parent = getentityproperty(self, "parent");
    int PMap = getentityproperty(parent, "map");

    changeentityproperty(self, "map", PMap);
}
 
Last edited:
This SHOULD work - its how I use on my scripts:

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }

   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
   changeentityproperty(Bomb,"parent",self); // <--- ADDED
}
 
Thanks guys but it doesn't work yet.

EDIT:
C:
void main ()
{
    void self = getlocalvar("self");
    void parent = getentityproperty(self, "parent");
    int PMap = getentityproperty(parent, "map");

    changeentityproperty(self, "map", PMap);
}
There's no change with this script.


This SHOULD work - its how I use on my scripts:

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?                
      dx = -dx; //Reverse X direction to match facing
   }

   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
   changeentityproperty(Bomb,"parent",self); // <--- ADDED
}
When the char performs the function the program shuts down. Here is the log:
Function changeentityproperty must have a valid entity handle.Script function 'changeentityproperty' returned an exception, check the manual for details.
parameters: "hishoken", 133, #124009480,
 
weird, try changing the order like this:

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?               
      dx = -dx; //Reverse X direction to match facing
   }
   changeentityproperty(Bomb,"parent",self); // <--- ADDED
   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}

We can even add a safe check

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?               
      dx = -dx; //Reverse X direction to match facing
   }
if (vShot){// safe check
   changeentityproperty(Bomb,"parent",self); // <--- ADDED
}
   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}

I have two versions of this script, and the second one has this parent part:

C-like:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");


   if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }


   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}


void toss2(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting projectile
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;


      if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }


    vShot = projectile(Shot, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
    if (vShot){// safe check
    changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
  
   return vShot;
 }
}
 
I'm stuck, nothing changes. And with the your script below, @O Ilusionista , OB shuts down from loading.

C:
    [CODE=clike]void toss(void Bomb, float dx, float dy, float dz)

    { // Tossing bomb

       void self = getlocalvar("self");

       int Direction = getentityproperty(self, "direction");

       int x = getentityproperty(self, "x");

       int y = getentityproperty(self, "a");

       int z = getentityproperty(self, "z");


       if (Direction == 0){ //Is entity facing left?           

          dx = -dx; //Reverse X direction to match facing

       }

    if (vShot){// safe check

       changeentityproperty(Bomb,"parent",self); // <--- ADDED

    }

       projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);

    }

Here is the log:
Script compile error in 'Andy'': vShot line 906, column 4

********** An Error Occurred **********
* Shutting Down *

Can't compile script 'Andy'' data/chars/andy'/Andy'.txt
Total Ram: 8276971520 Bytes
Free Ram: 2121977856 Bytes
Used Ram: 35569664 Bytes

Release level data...........
Done!

Release graphics data........ Done!
Release game data............


Release game data............ Done!
Release timer................ Done!
Release input hardware....... Done!
Release sound system......... Done!
Release FileCaching System... Done!

**************** Done *****************

Can't compile script 'Andy'' data/chars/andy'/Andy'.txt
 
Last edited:
Tested what you suggested but when the function is activated OB shuts down.
The script, just in case I don't understand you:

C:
void toss(void Bomb, float dx, float dy, float dz)

    { // Tossing bomb

       void self = getlocalvar("self");

       int Direction = getentityproperty(self, "direction");

       int x = getentityproperty(self, "x");

       int y = getentityproperty(self, "a");

       int z = getentityproperty(self, "z");


       if (Direction == 0){ //Is entity facing left?           

          dx = -dx; //Reverse X direction to match facing

       }

    if (Bomb){// safe check

       changeentityproperty(Bomb,"parent",self); // <--- ADDED

    }

       projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);

    }

The log:
Function changeentityproperty must have a valid entity handle.Script function 'changeentityproperty' returned an exception, check the manual for details.
parameters: "hishoken", 133, #126247624,
 
Tested what you suggested but when the function is activated OB shuts down.
The script, just in case I don't understand you:

C:
void toss(void Bomb, float dx, float dy, float dz)

    { // Tossing bomb

       void self = getlocalvar("self");

       int Direction = getentityproperty(self, "direction");

       int x = getentityproperty(self, "x");

       int y = getentityproperty(self, "a");

       int z = getentityproperty(self, "z");


       if (Direction == 0){ //Is entity facing left?          

          dx = -dx; //Reverse X direction to match facing

       }

    if (Bomb){// safe check

       changeentityproperty(Bomb,"parent",self); // <--- ADDED

    }

       projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);

    }

The log:
Please try this one
C:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?                 
      dx = -dx; //Reverse X direction to match facing
   }
   changeentityproperty(Bomb, "parent", self);
   projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
}
 
Please try this one
Its pretty much what I posted above :)

@16-bit Fighter here, I've tested it and it works - I made a different function to not clash with your previous function:

C-like:
void tossParent(void Bomb, float dx, float dy, float dz)
{ // Toss bomb with parent
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void vShot;


      if (Direction == 0){ //Is entity facing left?                
      dx = -dx; //Reverse X direction to match facing
   }


    vShot = projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
    if (vShot){// safe check
    changeentityproperty(vShot,"parent",self);
 
   return vShot;
 }
}

The usage is the same, just keep in mind the function name is tossParent

Probably, the issue was the lack of "return".
 
@16-bit Fighter here, I've tested it and it works - I made a different function to not clash with your previous function:
Thanks but it still doesn't work. I don't know where I make an error. I renamed the tossParent function in toss in exchange for the previous toss function. The player can perform the move but the projectile is with the palette 0 no matter the number of char's palette.
What should I check according to you?

Edit: Well, if I use my the function in the anim itself it works but the onspawnscript function doesn't. Strange...
 
Last edited:
Thanks but it still doesn't work. I don't know where I make an error. I renamed the tossParent function in toss in exchange for the previous toss function. The player can perform the move but the projectile is with the palette 0 no matter the number of char's palette.
What should I check according to you?
@16-bit Fighter
The methods @O Ilusionista and @pudu posted should work, I use the same in some SORX scripts. But as an alternative, you can define the spawn map directly without getting a parent's map, I use this method too.

C:
void toss(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb
    void self = getlocalvar("self");
    int Direction = getentityproperty(self, "direction");
    int x = getentityproperty(self, "x");
    int y = getentityproperty(self, "a");
    int z = getentityproperty(self, "z");
    int map = getentityproperty(self, "map");

    if (Direction == 0){ //Is entity facing left?                 
        dx = -dx; //Reverse X direction to match facing
    }
    projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
    changeentityproperty(Bomb, "map", map);
}
 
@16-bit Fighter
The methods @O Ilusionista and @pudu posted should work, I use the same in some SORX scripts. But as an alternative, you can define the spawn map directly without getting a parent's map, I use this method too.[/CODE]
Thank you but I edited my previous post just before your wrote yours. I said:
Edit: Well, if I use my the function in the anim itself it works but the onspawnscript function doesn't. Strange...
 
I'd really prefer the onswpanscript to work instead of my current solution. Because it makes more sense and my script in the animation itself works only from the second frame, which makes me have to make the first frame having delay 1 if I want the problem not to be noticed. :(

With the onspawnscript (not working):
C:
void main ()

{

    void self = getlocalvar("self");

    void parent = getentityproperty(self, "parent");

        int PMap = getentityproperty(parent, "map");

    if(parent!=NULL()){

    changeentityproperty(self, "map", PMap);

    }

}

With the animation (working but just form the 2nd frame):
C:
anim idle

    delay    7

    offset    31 31

    loop    1 1 // 1 1

    followanim    1

    followcond    1

    attack3    3 2 59 62 18 0 0 0 8 17 //

    forcedirection    -1

    @script

    void self = getlocalvar("self");

    void parent = getentityproperty(self, "parent");

        int PMap = getentityproperty(parent, "map");

    if(parent!=NULL()){

    changeentityproperty(self, "map", PMap);

    }

    @end_script

    @cmd    antiwallCollide 10 "ANI_FOLLOW2"

    frame    data/chars/andy'/hishoken01.png

    delay    7

    @cmd    antiwallCollide 10 "ANI_FOLLOW2"

    frame    data/chars/andy'/hishoken02.png

    @cmd    antiwallCollide 10 "ANI_FOLLOW2"

    frame    data/chars/andy'/hishoken01.png

    @cmd    antiwallCollide 10 "ANI_FOLLOW2"

    frame    data/chars/andy'/hishoken02.png

If I use the condition below instead of the one above, it doesn't work:
C:
if(frame == 0 && parent!=NULL())

Is there someone who sees an error?
 
Back
Top Bottom