AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get 1 player from X (https://forums.alliedmods.net/showthread.php?t=125986)

eNz0 05-04-2010 10:27

How to get 1 player from X
 
Hi again. I am making a plugin, which makes server assign player classes for players (automatic). I have 6 classes, but normally server assigns only 5 of them. 6th is much better, and i need a code which chooses only 1 player from server and gives him 6th class.
Optional: When player with 6th class dies, other player gets 6th class.
Examples:

new g_Player_Class[33]

g_Player_Class[id] = random_num(1, 5)

if(g_Player_Class[id] == 1)
...

biscuit628 05-04-2010 13:45

Re: How to get 1 player from X
 
PHP Code:

new g_Player_Class[33]
new 
p_MaxPlayers


public plugin_init()
{
    
register_event("DeathMsg","event_deathmsg","a");
    
p_MaxPlayers get_maxplayers()
}

public 
event_deathmsg()
{
    new 
victim read_data(2)
    if(
g_Player_Class[victim] == 6)
    {
        
set_next_pl(victim)
    }
}

public 
set_next_pl(id)
{
    new 
random_num(1,p_Maxplayers)
    
    
g_Player_Class[id] = random_num(15)
    
    if(
is_user_connected(r) && != id)
        
g_Player_Class[r] = 6
    
else
        
set_next_pl(id)



grimvh2 05-04-2010 13:50

Re: How to get 1 player from X
 
PHP Code:

RandomPlayer()
{
    new 
players[32], pnum;
    
get_players(playerspnum);
    
    if( !
pnum ) return 0;
    
    return 
players[random(pnum)];



Bugsy 05-04-2010 13:55

Re: How to get 1 player from X
 
PHP Code:

RandomPlayer()
{
    new 
players[32], pnum;
    
get_players(playerspnum);
    
    return 
pnum players[random(pnum)] : 0;



grimvh2 05-04-2010 14:59

Re: How to get 1 player from X
 
Quote:

Originally Posted by Bugsy (Post 1170400)
PHP Code:

RandomPlayer()
{
    new 
players[32], pnum;
    
get_players(playerspnum);
    
    return 
pnum players[random(pnum)] : 0;



Hmm, if pnum is 0, my code will return 0 to, not?

wrecked_ 05-04-2010 15:34

Re: How to get 1 player from X
 
Quote:

Originally Posted by grimvh2 (Post 1170479)
Hmm, if pnum is 0, my code will return 0 to, not?

If pnum is 0, then that means there are no players and 0 will be returned, yes.

grimvh2 05-04-2010 16:17

Re: How to get 1 player from X
 
Quote:

Originally Posted by wrecked_ (Post 1170523)
If pnum is 0, then that means there are no players and 0 will be returned, yes.

Then bugsy failed to correct me :p ( my opinion )

wrecked_ 05-04-2010 16:34

Re: How to get 1 player from X
 
He was just making it simpler and condensed. It's the same as yours, but he just used the ? : operators. He wasn't trying to prove you wrong.


All times are GMT -4. The time now is 03:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.