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 → Scrolling through players
Scrolling through players
2005-07-14, 10:56 AM #1
Ok,

I have a cog, and every time I activate it it will select a player name. What I need to know, is how to get all the players in a game, and how to scroll through them by means of every time the cog is activated, a new player is selected. It will be a weapon, so this part will be in secondary fire. Primary fire will do X to the currently chosen victim.

I would really appreciate it if someone could help me with this, it's a little beyond me.

So simplified:

1) Everytime you activate secondary fire you select a different player.
2) When you activate primary, you do something to the player(such as something simple like kill that victim).

- I know how to set up a cog with different things happening in Primary/Secondary fire.

Thanks in advance!

ReT
2005-07-14, 11:24 AM #2
You can try something like this:
Code:
activated:
   mode = GetSenderRef();
   if(mode == 0)               //primary
   {
      <do stuff to player>
   }
   else                        //secondary
   {
      // select a player
      index = index + 1;
      if(index >= GetNumPlayers()) index = 0;
      player = GetPlayerThing(index);

      // now output player name
      jkStringClear();
      jkStringConcatAsciiString("Player ");
      jkStringConcatInt(index);                                    // concatenate player number
      jkStringConcatAsciiString(" selected: ");
      jkStringConcatPlayerName(player);                            // concatenate player name
      jkStringOutput(GetPlayerNum( GetLocalPlayerThing() ), -1);   // output to local player only
   }

   Return;
May the mass times acceleration be with you.
2005-07-14, 12:10 PM #3
That should work, except that you probably should use another name for the targeted player's variable, since "player" is usually already defined in weapon cogs.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-07-14, 6:01 PM #4
Thank you so much! I'm gonna try and test this tonight.

zagibu: I will change it to something like victim, cuz yeah, most cogs already define player as the local player. Thanks!

ReT
2005-07-15, 6:18 PM #5
Quote:
Originally posted by Darth Slaw
Code:
      jkStringOutput(GetPlayerNum( GetLocalPlayerThing() ), -1);   // output to local player only
Just spent the last half hour testing jkStringOutput() and you made a small mistake in its use.

For the code you posted, it needs to be jkStringOutput(-1, -1); or jkStringOutput(GetLocalPlayerThing(), -1);. The first variable is an actual target thing number, not a player's index number, and the DataMaster gives sort of a hazy description on which to use (says to use a destination when it should actually be the player's thing number, not their index number).

So anyway, I made a COG that printed my target's thing number and index number, then tried outputting a string to each, and only the strings sent to the thing number got through, while the ones trying to use the target's index number just printed on my screen. The exception, is in some levels a player's thing number and index number can coincidentally be the same, in which case the target gets the message twice.

QM
2005-07-16, 12:12 AM #6
Like the classic single player walkplayer=thing 0 situation...
Still, I'd think it would make more sense to use an index number rather than thing number... oh well, at least I was close ;)
May the mass times acceleration be with you.

↑ Up to the top!