Forum

Kill messages

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Kill messages

Postby redrum » Mon Nov 23, 2009 3:32 pm

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: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby r00k » Mon Nov 23, 2009 4:45 pm

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: Select all
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: Select all
void(entity targ, entity attacker) Killed =
{
...

   self.enemy = attacker;
   obit_notify_players(self.enemy,self);
...
       
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby redrum » Tue Nov 24, 2009 3:36 pm

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: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby r00k » Tue Nov 24, 2009 5:34 pm

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: Select all
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: Select all
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: Select all
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.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest