Solved Shared Palette Based on Parent Entity

Question that is answered or resolved.

maxman

Well-known member
I know using spawnframe and custentity works well with this kind in onspawnscript. This works for some (e.g. UDD, because of the specific engine used that works?), but it doesn't work for others (including my SF project, because I use one of the older versions for it?).

C:
void main(){
    changePalette();
}

void changePalette(){
    void self = getlocalvar("self");
    void parent = getentityproperty(self, "parent");
    int Pmap = getentityproperty(parent, "map");

    if(Pmap){
        changeentityproperty(self, "map", Pmap);
    }
}

It doesn't work on mine, but I want it to spawn its shared palette based on the parent/source entity itself. spawn01map works well, but what I really want is to spawn it directly (counting) as a screen offset like the 5th parameter as 1 in spawnframe. It works like spawning Hadoken with specified palette.

I tried these with the same shared palettes but spawning one doesn't share the same colors (custentity-spawnframe). Let alone being only shown with the default palette.

Code:
name ARyu
type player
health 100
speed 14
icon data/chars/aryu/ryu.png 1

palette data/chars/aryu/pal.png
alternatepal data/chars/aryu/palettes/alt01.png
alternatepal data/chars/aryu/palettes/alt02.png
alternatepal data/chars/aryu/palettes/alt03.png
alternatepal data/chars/aryu/palettes/alt04.png
alternatepal data/chars/aryu/palettes/alt05.png
alternatepal data/chars/aryu/palettes/alt06.png
alternatepal data/chars/aryu/palettes/alt07.png

Code:
anim follow15 #YOU LOSE!
    offset 97 177
    delay 9
    #spawnframe 6 91 182 0 1
    #custentity ARyuCont
    frame data/CHARS/ARyu/loss01.png
    frame data/CHARS/ARyu/loss02.png
    frame data/CHARS/ARyu/loss03.png
    frame data/CHARS/ARyu/loss04.png
    frame data/CHARS/ARyu/loss05.png
    delay 339
    frame data/CHARS/ARyu/loss06.png
    @cmd suicide
    @cmd spawn01map "ARyuCont" 0 0 0
    frame data/CHARS/ARyu/loss06.png

Code:
name ARyuCont
type npc
health 10
shadow 0
speed 10
nomove 1
antigravity 100
death 1
nopain 1
facing 1
subject_to_minz 0
subject_to_maxz 0
subject_to_wall 0
subject_to_platform 0
subject_to_obstacle 0
nodieblink 2

palette data/chars/aryu/pal.png
alternatepal data/chars/aryu/palettes/alt01.png
alternatepal data/chars/aryu/palettes/alt02.png
alternatepal data/chars/aryu/palettes/alt03.png
alternatepal data/chars/aryu/palettes/alt04.png
alternatepal data/chars/aryu/palettes/alt05.png
alternatepal data/chars/aryu/palettes/alt06.png
alternatepal data/chars/aryu/palettes/alt07.png

Code:
anim idle
    loop 1
    offset 97 177
    delay 30
    bbox 74 81 40 96
    frame data/CHARS/ARyu/dizzy00.png
    frame data/CHARS/ARyu/dizzy01.png
    frame data/CHARS/ARyu/dizzy02.png
    frame data/CHARS/ARyu/dizzy03.png
    frame data/CHARS/ARyu/dizzy04.png
    frame data/CHARS/ARyu/dizzy05.png

This is spawn01map:
C:
void spawn01map(void vName, float fX, float fY, float fZ)
{
    //spawn01 (Generic spawner)
    //Damon Vaughn Caskey + Douglas Baldan
    //07/06/2007
    //
    //Spawns entity next to caller.
    //
    //vName: Model name of entity to be spawned in.
    //fX: X location adjustment.
    //fZ: Y location adjustment.
      //fY: Z location adjustment.

    void self = getlocalvar("self"); //Get calling entity.
    int  iMap = getentityproperty(self, "map"); // Get caller's remap.
    void vSpawn; //Spawn object.
    int  iDirection = getentityproperty(self, "direction");

    clearspawnentry(); //Clear current spawn entry.
      setspawnentry("name", vName); //Acquire spawn entity by name.

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

      fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
      fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
      fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
    
    vSpawn = spawn(); //Spawn in entity.

    changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
    changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
    changeentityproperty(vSpawn, "map", iMap); //Set map.
  
    return vSpawn; //Return spawn.
}

What I'm trying to make is for it to spawn like using spawnframe and custentity by counting screen offset but spawning one entity which shares the same color palette as the player. How can I do it? I can't use spawnframe and custentity/subentity for this.
 
Solution
Basically, you can get this "spawn06" function - which works as you want - and add the map code:

C-like:
void spawn06(void vName, float fX, float fY, float fZ)
{
    //Spawns entity based on left screen edge and z axis
    //Auto adjust with camera's position
    //vName: Model name of entity to be spawned in.
    //fX: X distance relative to left edge
    //fY: Y height from ground
      //fZ: Z coordinate

    void self = getlocalvar("self"); //Get calling entity.
    void vSpawn; //Spawn object.
    int Direction = getentityproperty(self, "direction");
        int XPos = openborvariant("xpos"); //Get screen edge's position
        int YPos = openborvariant("ypos"); // Get camera position
        int Screen =...
Basically, you can get this "spawn06" function - which works as you want - and add the map code:

C-like:
void spawn06(void vName, float fX, float fY, float fZ)
{
    //Spawns entity based on left screen edge and z axis
    //Auto adjust with camera's position
    //vName: Model name of entity to be spawned in.
    //fX: X distance relative to left edge
    //fY: Y height from ground
      //fZ: Z coordinate

    void self = getlocalvar("self"); //Get calling entity.
    void vSpawn; //Spawn object.
    int Direction = getentityproperty(self, "direction");
        int XPos = openborvariant("xpos"); //Get screen edge's position
        int YPos = openborvariant("ypos"); // Get camera position
        int Screen = openborvariant("hResolution"); // Get screen width

    clearspawnentry(); //Clear current spawn entry.
      setspawnentry("name", vName); //Acquire spawn entity by name.

   if (Direction == 0){ //Is entity facing left?                 
      fX = Screen-fX; //Reverse X direction to match facing and screen length
   }

    vSpawn = spawn(); //Spawn in entity.
  if (vSpawn){// safe check

    changeentityproperty(vSpawn, "position", fX + XPos, fZ + YPos, fY); //Set spawn location.
  changeentityproperty(vSpawn, "parent", self); //Set parent.
    return vSpawn; //Return spawn
  }
}
 
Solution
Basically, you can get this "spawn06" function - which works as you want - and add the map code:

C-like:
void spawn06(void vName, float fX, float fY, float fZ)
{
    //Spawns entity based on left screen edge and z axis
    //Auto adjust with camera's position
    //vName: Model name of entity to be spawned in.
    //fX: X distance relative to left edge
    //fY: Y height from ground
      //fZ: Z coordinate

    void self = getlocalvar("self"); //Get calling entity.
    void vSpawn; //Spawn object.
    int Direction = getentityproperty(self, "direction");
        int XPos = openborvariant("xpos"); //Get screen edge's position
        int YPos = openborvariant("ypos"); // Get camera position
        int Screen = openborvariant("hResolution"); // Get screen width

    clearspawnentry(); //Clear current spawn entry.
      setspawnentry("name", vName); //Acquire spawn entity by name.

   if (Direction == 0){ //Is entity facing left?               
      fX = Screen-fX; //Reverse X direction to match facing and screen length
   }

    vSpawn = spawn(); //Spawn in entity.
  if (vSpawn){// safe check

    changeentityproperty(vSpawn, "position", fX + XPos, fZ + YPos, fY); //Set spawn location.
  changeentityproperty(vSpawn, "parent", self); //Set parent.
    return vSpawn; //Return spawn
  }
}

D'oh! 🤦‍♂️ I thought I didn't have it, and I forgot that I have spawn06 (in spawn.h). I just copied that code, added map, and renamed it spawn06map. It's really working fine as I wanted. Thanks, buddy!
 
Back
Top Bottom