Inside3D!
     

Kill messages

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



Joined: 28 Mar 2007
Posts: 367
Location: Long Island, New York

PostPosted: Mon Nov 23, 2009 3:32 pm    Post subject: Kill messages Reply with quote

In ClientObit(), how would you call the players that are not involved in the kill?

I'm trying to centerprint to the "other" players informing them of the kill.

I tried: centerprint (other, "blah, blah, blah")

It compiles with no error, but it doesn't work?

Any suggestions?
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Mon Nov 23, 2009 4:45 pm    Post subject: Reply with quote

self is the person who died, and self.enemy is the person who killed
them, maybe run a loop thru the player entities, and if not self and not self.enemy then print the message.

Code:

void (entity killer, entity victim) obit_notify_players =
{
   local entity oldself;

   oldself = self;
   self = find(world, classname, "player");
   while (self)
   {
       if ((self != killer) && (self != victim))
            centerprint4(self,killer.name," has fragged ",victim.name,"\n");
      self = find(self, classname, "player");
   }
   self = oldself;
};


you can actually call this function from
Code:

void(entity targ, entity attacker) Killed =
{
...

   self.enemy = attacker;
   obit_notify_players(self.enemy,self);
...
       
Back to top
View user's profile Send private message
redrum



Joined: 28 Mar 2007
Posts: 367
Location: Long Island, New York

PostPosted: Tue Nov 24, 2009 3:36 pm    Post subject: Reply with quote

very cool, works perfect.

I just want to understand the code a little better.

I don't understand what "oldself" does, why is it needed?
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Tue Nov 24, 2009 5:34 pm    Post subject: Reply with quote

In your case you might not need if unless you add more stats or entity functions in that loop.

Here's an example of how I use it more effectively:
Some functions passed thru "dofunc" specifically alter the self global, so we just need to save it out.

Code:

void (void () dofunc) utils_do_arena_players =
{
   local entity oldself;

   oldself = self;
   self = find(world, classname, "player");
   while (self)
   {
      if ((self.style & CA_CONNECTED) && (self.next_team))
         dofunc ();
      self = find(self, classname, "player");
   }
   self = oldself;
};


then if i call elsewhere:

Code:

utils_do_arena_players(arena_refresh_player);

it will execute void () arena_refresh_player for every player in the arena.

in all passing thru functions like that it's best to preserve the last "self" as it's a global entity that's used quite often.

here's a piece of code by J.P.Grossman that is very entertaining,
Code:

entity (void() think_function, float think_time) utils_make_scheduled_event =
{
   local entity temp;

   temp = spawn();
   temp.classname = "scheduled_event";
   temp.owner = self;
   temp.nextthink = time + think_time;
   temp.think = think_function;
   return temp;
};


this allows you to schedule the execution of loading configs, or setting off triggers or effects etc.. quite useful. one note though, in the think function it needs to remove(self) of the local entity "temp" as this will create an overflow eventually.
Back to top
View user's profile Send private message
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