Inside3D!
     

Help: Weird problem with weapon damage and finding my 'self'

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
OneManClan



Joined: 28 Feb 2009
Posts: 62

PostPosted: Thu May 07, 2009 5:10 pm    Post subject: Help: Weird problem with weapon damage and finding my 'self' Reply with quote

[Note: This problem refers to CustomTF, where a player can have up to three 'Grunties', soldier bots, which he personally controls]

[Note: I'm still a newbie so please don't hesitate to 'dumb down' all explanations Smile]

There's something weird going on with something I'm trying to code. It's too complex to go into ALL the code here, so I'll give an alternative, simplified, demonstration version:

Let's say we have a function which makes the Player's Grunty say something every time his owner damages him:
Code:
void(entity Grunty) OuchMessage1 =
{
sprint(self, #PRINT_HIGH, Grunty.netname, " ","Stop ",self.netname, ", I'm on your side!!!\n");

};

and we put the function call in TF_T_Damage (an expanded version of T_Damage, used in CustomTF) as follows:
Code:

   if ((!IsMonsterNonArmy(targ)) && (targ.real_owner == attacker) && (targ.real_owner.health > 0))
         {
// targ is the grunty
         OuchMessage1(targ);
         }

Ok, I tested this, and it works PERFECTLY for the following weapons:

LIST A
    knife
    single barrel SG
    Double Barrel SG
    Sniper Rifle
    Assault Cannon
    Axe
    Light Assault
    Lightning Gun

But NOT for the following weapons!:

LIST B
    Rocket Launcher
    Tranq
    Railgun
    Nailgun
    Super Nailgun
    Daedelus
    Incendiary Cannon
    Flamethrower
    Grenade thrower
    pipebomb


Instead, every time damage is inflicted with a weapon from List B, we get the following message in the cpqwsv.exe (server software)screen:
tried to sprint to a non-client

'Self' must be ....changing (?)...depending on the type of damage being inflicted...? Surprised I did a debugging sprint to output 'self', and here's what I got:

List A weapon damage: self.netname = OneManClan
List B weapon damage: self.netname =

Blank! Surprised

Can someone please explain what's going on?


OneManClan
ps I didnt even know what to put as the 'subject' this is so complex..
Back to top
View user's profile Send private message
MauveBib



Joined: 04 Nov 2004
Posts: 602

PostPosted: Thu May 07, 2009 5:51 pm    Post subject: Reply with quote

"self" changes all the time, it refers to the entity which causes the function to be run (by a .touch or .think usually, or by any of the engine-run functions ). In the case of the T_Damage function, "self" will be the entity which causes the damage, so for direct fire weapons like shotguns and axes it will be the player, but for projectile/model based weapons "self" will be the projectile entity.

Presumably the "Grunties" will have their .owner field set to the player who owns them, so something like this should work:

Code:

void(entity Grunty) OuchMessage1 =
{
sprint(Grunty.owner, #PRINT_HIGH, Grunty.netname, " ","Stop ",Grunty.owner.netname, ", I'm on your side!!!\n");

};


Otherwise the solution is to feed the "attacker" entity to your new function as a second parameter, and use that instead of "self".
_________________
Apathy Now!
Back to top
View user's profile Send private message
OneManClan



Joined: 28 Feb 2009
Posts: 62

PostPosted: Tue May 12, 2009 8:26 am    Post subject: Reply with quote

MauveBib wrote:
"self" changes all the time...<snip> ... for direct fire weapons like shotguns and axes it will be the player, but for projectile/model based weapons "self" will be the projectile entity.


Yes, yes, it all makes sense now. I got confused, because I saw this thing called 'self' declared globally, and I thought it was the players personal 'identity' throughout the code; yet it's more like a generic entity, used within functions as a 'local variable' almost (?). Though how multiple 'self's' could all run at the same time without conflicting is inconceivable to me, at this stage in my Quake C comprehension.

MauveBib wrote:

.<snip>..Otherwise the solution is to feed the "attacker" entity to your new function as a second parameter, and use that instead of "self".


Done, and it works perfectly!



thanks!


OneManClan
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Wed May 13, 2009 12:40 am    Post subject: Reply with quote

Try to imagine Quake's entities as C-like data structures holding info about every dynamic element in the game (a player, a monster, a rocket, a flesh gib). The game can have hundreds of entities (at least 600 in vanilla Quake, more in other engines). "self" is a pointer to the entity which the engine is currently processing, so it changes every interaction the game makes through the active entities list. "other" usually is a pointer to an entity that collided with (or used/activated) "self". "world" is a reference to the entity 0, which represents the loaded level. Keeping those concepts in mind helps a lot to understand what's going on in QuakeC.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group