Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Damaged Message Troubles...
Damaged Message Troubles...
2004-08-25, 8:13 PM #1
I've read up a bit on the damaged message, but I'm still confused. How does it work? I read that SourceRef is the attacker, and SenderRef is the victim. I wanna make a protected mode so that you can damage a player, but you get killed, damaged back, or something like that.

Code:
damaged:
   player = GetLocalPlayerThing();
      AttackerDude = GetSourceRef();
   if(AttackerDude == player) Return;
   // insert commands here for consequences


[This message has been edited by Sabre_Wulf (edited August 25, 2004).]
2004-08-25, 8:46 PM #2
For my example I'll use item_shields.cog because player damage is routed through there, but isn't controlled by a force power (if you want it to be, you add a damaged message to the force power then add the correct flag to the bin in items.dat so it gets the damaged messages).
Code:
flex damage=-1 local
thing player=-1 local
thing damager=-1 local
int damagerType=0 local
template projectile_exp=+sequencer_exp local // This will be used to send damage back to the thing that hurt you
message damaged

damaged:
   damage = GetParam(0); // How much damage you took
   player = GetSenderRef(); // This is you getting hurt
   damager = GetSourceRef(); // This is what damaged you

   damagerType = GetThingType(damager); // This is important, you only want to send damage back to a thing

   if((damagerType == 3) || (damagerType == 6)) damager = GetThingParent(damager);
   damagerType = GetThingType(damager); // Repeated in case we move to a weapon's parent

   if((damagerType == 3) || (damagerType == 6)) damager = GetThingParent(damager);
   damagerType = GetThingType(damager); // Repeated again for good measure

   if((damagerType == 2) || (damagerType == 10)) TeleportThing(FireProjectile(player, projectile_exp, -1, -1, '0 0 0', '0 0 0', damage / 100, 0x2, 0.0, 0.0), damager);
   // You teleport an explosion onto them, so you get credit for the damage done
   // The 0x2 flag scales the damage of the explosion, damage / 100 because the base damage of the explosion is 100

   ReturnEx(damage); // or ReturnEx(0); if you don't want to take any damage
   Return;


Totally untested, but should work...

QM

[This message has been edited by Quib Mask (edited August 26, 2004).]

↑ Up to the top!