Help: Weird problem with weapon damage and finding my 'self'
Moderator: InsideQC Admins
4 posts
• Page 1 of 1
Help: Weird problem with weapon damage and finding my 'self'
[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
]
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, "
[Note: I'm still a newbie so please don't hesitate to 'dumb down' all explanations
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, "
- OneManClan
- Posts: 243
- Joined: Sat Feb 28, 2009 2:38 pm
"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, "
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, "
Apathy Now!
-

MauveBib - Posts: 634
- Joined: Thu Nov 04, 2004 1:22 am
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
- OneManClan
- Posts: 243
- Joined: Sat Feb 28, 2009 2:38 pm
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.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest