March 29, 2024, 02:18:33 am

Author Topic: Need some help  (Read 1236 times)

0 Members and 1 Guest are viewing this topic.

Inferno

  • Crazy Man
  • *****
  • Posts: 478
  • Frontline-battles! :D
    • View Profile
Need some help
« on: May 18, 2012, 07:57:46 pm »
Well,i am unable to detect all players that are spawned in a specific team.For example like we create a local to detect all players in the server,same way to detect players in a specific team.(axxo advised me to use a loop,is there any other method?) Can someone help me on this?
« Last Edit: May 18, 2012, 07:59:26 pm by Inferno »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


Charley

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 4749
  • Country: 00
    • View Profile
Re: Need some help
« Reply #1 on: May 18, 2012, 08:07:26 pm »
Loop would be the best way.

Code: [Select]

local team1 = 0, team2 = 0, i = 0, m = GetMaxPlayers();
while (i <= m)
{
     local plr = FindPlayer(i);
     if (plr)
     {
         if (plr.Team == 1) team1++;
         else team2++;
     }
      i++;
}

Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

Writer of excessively long posts


Thijn

  • Forum Administrator
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2946
  • Country: nl
    • View Profile
Re: Need some help
« Reply #2 on: May 18, 2012, 08:11:27 pm »
Or if you don't want to count them, but do stuff: (I'm not sure which one you want, hard to tell from your post..)
Code: [Select]
for ( local ID = 0; ID <= GetMaxPlayers( ); ID++ )
{
local plr = FindPlayer( ID );
if ( plr )
{
if ( plr.Team == SOMETEAM )
{
//Do Something here,
//I'm not sure if this is set when the player is not spawned. But you'll figure that out :)
}
}
}
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

I'm not totally useless,
I can be used as an bad example ;)

"Never do Today, What you can do Tomorrow"


morphine

  • Crazy Man
  • *****
  • Posts: 1908
  • Country: lt
    • View Profile
Re: Need some help
« Reply #3 on: May 19, 2012, 12:17:12 am »
Another way is to loop with tables, which I consider just slightly better than regular loops. With regular loops, even if you only had 10 users, the loop would still have to query up to the end (GetMaxPlayers()) whereas a table loop would only query the users that it has in it's table. Less waste, more fresh air!

Code: [Select]
// Table
players <- {};

// Give the player a slot in the table
function onPlayerJoin( player )
{
players.rawset( player.ID, player );
}

// Empty the slot after they leave
function onPlayerPart( player, reason )
{
if( players.rawin( player.ID ) ) players.rawdelete( player.ID );
}

// Here's the loop
function cheesyNamedLoop()
{
foreach( p in players ) // We select every entry (i.e. player) who has been entered
{
if( p.Team == your_team_here )
{
// Do stuff here
}
}
}
« Last Edit: May 19, 2012, 12:26:26 am by Morphine »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


Inferno

  • Crazy Man
  • *****
  • Posts: 478
  • Frontline-battles! :D
    • View Profile
Re: Need some help
« Reply #4 on: May 19, 2012, 11:13:07 am »
To be more clear,i want to send all people in team 5 a pm.Well,does loop lag?
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


Inferno

  • Crazy Man
  • *****
  • Posts: 478
  • Frontline-battles! :D
    • View Profile
Re: Need some help
« Reply #5 on: May 19, 2012, 11:16:35 am »
Sorry for double post,thanks morph,i was looking for a loop with tables thingy,thijn's post helped a bit too! anyways the problem's solved.Ty for help.
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor