Forced Palette Change

aL BeasTie

Well-known member
I have playable chars that spawnbind entities, I want to share these with different chars to avoid multiple entities.  I need something that will make these entities spawn with the same palette as the current char.

I remember not long ago someone replied to me and posted a simple script method, but I can't seem to find it now. :(


Basically I have chars that share sprites, but have different palettes.  I have system where enemies/players can be decapitated, they spawn a head entity that bounces rolls along the ground.  I simply need the head entity to switch palette based on the entity that spawned it.  Otherwise I will need entities for each palette.  I have a few mods that could really use this script.

I know someone gave a nice solution, but it was just a reply in a WIP topic  or something, I can't find it now :(
 
This might do the trick:

void shooter(void Shot, float dx, float dy, float Vx, float Vy)
{ // Shooting special projectile with speed control
  void self = getlocalvar("self");
  int Direction = getentityproperty(self, "direction");
  void vShot;

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

  vShot = spawn01(Shot, dx, dy, 0);
  changeentityproperty(vShot, "velocity", Vx, 0, Vy);
  return vShot;
}

void shooterM(void Shot, float dx, float dy, float Vx, float Vy)
{ // Shooting special projectile with speed control and matches its map with own's map
  void self = getlocalvar("self");
  int map = getentityproperty(self,"map");
  void Spawn;

  Spawn = shooter(Shot, dx, dy, Vx, Vy);
  changeentityproperty(Spawn, "map", map);
}

shooterM is the function you should be using. It will shoot defined entity with defined speed and with same map as spawner's map
Both functions shoot spawned entity with defined speed. If you want to spawn something without the speed, just set speed parameters 0
This function requires spawn01 function BTW

I don't know how you set palette for the spawner. If you set it in level texts, then it's good to go. But if you use default palette change trick, you'll have to disable that trick and change it with palette change script like this:

anim spawn
@script
    if(frame == 0){
      void self = getlocalvar("self");

      changeentityproperty(self, "map", 1); // assuming forced palette is 1st map
    }
@end_script
...

HTH
 
There's a more dynamic and powerful way to do this. So long as the head and main model were made with same the color table, you can assign the main model's current colors directly to the head and bypass maps altogether. This relieves you from making multiple palettes for the shared head and having to worrying about matching up the palette numbers. Tons simpler to deal with.

Just grab the main entity's current table and slap it on the spawn like this:

Code:
ent = getentityproperty("self);
table = getentityproperty(ent, "colourmap");

spawn = <new spawn.. the head or whatever>

changedrawmethod(spawn, "table", table);

I use this method for decaps, split bodies and in the example below (yes, I use this one a lot), to generate enemy icons.

http://youtu.be/JossdCHwwIw

DC
 
Beastie, I just remembered that I shared those functions from 2D game I was making. That's why it doesn't have parameter to control z movement
If you're happy with those, then fine. But if you need to control z movement too, just tell me :)
 
Thanks again guys.

@Bloodbane - Cheers, this works fine for projectiles that need to match.  Thou I'm confused how I should try to implement the rest .

@DC

I think originally the trick I was shown was more like what you posted.  Makes sense for this mod, all the sprites use the same palette, about 16 colours.  Everything else is done by changing palettes. 


I'm not sure what the best way would be to set this up, let me explain in more detail.


player.gif

PLAYER SPRITE - This is using Default palette (FOR ALL SPRITES, including weapon models)
they will also use alternate palettes/remaps.

remap_troll.png

PLAYER SPRITE (WITH NEW PALETTE) New model with different palette declared

enemy.gif

ENEMY SPRITE (NEW PALETTE) New model with different palette declared

When you decapitate an enemy you can pickup the head and throw it as a weapon.  The weapon model is the default palette, need to force palette to match the palette the player has.  The head entity will spawn the weapon pickup once it hit's the ground and stops rolling

image.png

The head entity and weapon pickup for the head that spawn's needs to match the enemies palette.

..and finally when the head is thrown it has to match the enemies palette.  If the head doesn't hit an enemy after being thrown, it will roll along the ground and you can pick it up again.  It just spawns a new head item again.
image.png


This weapon system is coded, I just trying to fix the problem with palettes, to avoid too many extra models.

Any help is appreciated.  ;)  I'm not sure how to implement DC's method, but it would seem like the best solution.

Cheers
 
Damon's explanation looks rather straightforward to me.  What exactly are you having trouble with?
 
Plombo said:
Damon's explanation looks rather straightforward to me.  What exactly are you having trouble with?
Not quite sure where to start.

Check my other post, it's not just a matter of throwing the head to match the current palette.  Once it's picked up again it must still match the palette of the entity that the head came from.  So I'm not sure about this part at all, seems like I will need to store values or something.

So I chop off an enemies head, it rolls on the ground.  I pickup the head and throw it as a weapon.  I need it to match the enemies palette, not the players.


Bloodbane said:
I think we need to see your weapon code to insert palette change into it
  Hmm it's just a standard entity thou, nothing special.
 
I haven't tested any of this, since the problem is rather specific to your game, but hopefully this will point you in the right direction.

I'm going to assume that you're spawning the head entity in the death animation of the enemy, and spawning the weapon pickup in some animation of the head entity.  I'm also going to assume that you're currently spawning both entities using a regular command like spawnframe rather than script.

Put (or import) these functions in the animationscripts of every model that needs them.  Again, I haven't tested these, so they might need some minor changes, but they should be mostly right.
Code:
void setEntityPalette(void ent, void otherEnt)
{
	changedrawmethod(ent, "table", getentityproperty(otherEnt, "colourmap"));
}

void spawnWithExistingEntPalette(char name, int x, int z, int a, void existingEnt)
{
	clearspawnentry();
	setspawnentry("name", name);
	setspawnentry("coords", x, z, a);
	// if you need to set more spawn properties, do it here

	void ent = spawn();
	setEntityPalette(ent, existingEnt);
	setentityvar(ent, "original_palette", getentityproperty(existingEnt, "colourmap"));
}

Now, instead of using a regular command to spawn the new entities, run this script call on the animation frame where you want to spawn them:
Code:
@cmd spawnWithExistingEntPalette "name" x z a getlocalvar("self")

Obviously, you should replace "name" and x/z/a above with the actual model name and coordinates of the spawn.  Then the command will spawn the requested entity with the palette of the entity that spawned it.

I don't know the details of your grapple system, but you'll want to call the setEntityPalette function in the code where the head is picked up and thrown.  You just call
Code:
setEntityPalette(headEnt, playerEnt)
to set the head's palette to the player's.  To set it back to the palette of the enemy that spawned it (when the player throws it), you'd use the call
Code:
changedrawmethod(headEnt, "table", getentityvar(headEnt, "original_palette"))
.

Does that help at all? :)
 
Thanks heaps Plombo, 

so far with testing, nothing is spawning thou using spawnWithExistingPalette. :(

I'm going to assume that you're spawning the head entity in the death animation of the enemy, and spawning the weapon pickup in some animation of the head entity.
Yes  :)

I'm also going to assume that you're currently spawning both entities using a regular command like spawnframe rather than script.

Nah I'm using scripts, spawn01 and toss

toss script for launching the head, spawn01 to spawn the weapon pickup.  I've modified toss script to create tossM script based off Bloodbane's shooterM script.

tossM
Code:
void tossM(void Bomb, float dx, float dy, float dz)
{ // Tossing bomb and matches its map with own's map
   void self = getlocalvar("self");
   int map = getentityproperty(self,"map");
   void Spawn;
   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
   }

   Spawn = projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
   changeentityproperty(Spawn, "map", map);
}

Now the head projectile is spawning with the proper palette using tossM, but when it spawns the weapon pickup with SpawnWithExistingEntPalette nothing is showing up.

I made another script editing Ispawn script to spawn the item with the right palette.  That seems to work, thou I'm not sure how well I made the script, but I can at least see it working in game for now.

I don't know the details of your grapple system, but you'll want to call the setEntityPalette function in the code where the head is picked up and thrown.
I'll try this part next (gotta break to eat).  No grapple system, just using weapon models and edited sprites. 
 
Back
Top Bottom