Raised This Month: $ Target: $400
 0% 

How to get 1 player from X


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eNz0
Member
Join Date: Feb 2010
Location: Lithuania
Old 05-04-2010 , 10:27   How to get 1 player from X
Reply With Quote #1

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)
...

Last edited by eNz0; 05-04-2010 at 10:29.
eNz0 is offline
biscuit628
Senior Member
Join Date: Jun 2007
Location: 香港HongKong
Old 05-04-2010 , 13:45   Re: How to get 1 player from X
Reply With Quote #2

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)

__________________
My Plugins

C4man with fun

Sniper Skill bonus
-------------------------
Sorry for my poor English!

Last edited by biscuit628; 05-04-2010 at 14:23.
biscuit628 is offline
grimvh2
Veteran Member
Join Date: Nov 2007
Location: Fishdot Nation
Old 05-04-2010 , 13:50   Re: How to get 1 player from X
Reply With Quote #3

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

__________________
I am out of order!
grimvh2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-04-2010 , 13:55   Re: How to get 1 player from X
Reply With Quote #4

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

__________________
Bugsy is offline
grimvh2
Veteran Member
Join Date: Nov 2007
Location: Fishdot Nation
Old 05-04-2010 , 14:59   Re: How to get 1 player from X
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
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?
__________________
I am out of order!
grimvh2 is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-04-2010 , 15:34   Re: How to get 1 player from X
Reply With Quote #6

Quote:
Originally Posted by grimvh2 View Post
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.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-04-2010 , 16:34   Re: How to get 1 player from X
Reply With Quote #7

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.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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