AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random player (https://forums.alliedmods.net/showthread.php?t=61923)

purple nurple 10-14-2007 02:17

Random player
 
Can someone help me with this. I want a random person to be choosen at the beginning of the round or sometime around then. I want it like this so it chooses one person out of everyone in the server and gives them stuff.

PHP Code:

public event_round_start(id)
{
    
set_task(5.0,"random_person",id)
}

public 
random_person(id)
{
    
//random person code in here.
}

public 
person(id)
{
    
//e.g.
    
cs_set_user_health(id,1000)
    
//other stuff to


Thats how i want it. If you can help me thanks alot.

Arkshine 10-14-2007 02:41

Re: Random player
 
Humm, maybe something like :

Code:
    #include <amxmodx>     #include <fakemeta>     public plugin_init()     {         register_plugin( "", "1.0", "Amxx Community" );         register_event( "HLTV", "eNew_round", "a", "1=0", "2=0" );     }         public eNew_round()     {         give_extra( random_person() );     }         random_person()     {         new iRandom_id = random_num( 1, get_playersnum() );                 return is_user_alive( iRandom_id ) ? iRandom_id : random_person();     }         give_extra( id )     {         set_pev( id, pev_health, 1000.0 );     }

New Round is happen at the freeze time start.

Quote:

or sometime around then
Use that. You can choose an interval.

Code:
    public eNew_round()     {         set_task( random_float( 2.0, 6.0 ), "random_person" );     }



EDIT: hm. I have a doubt about something. You can use this if above doesn't work well.

Code:
    random_person()     {         new iPlayers[32], iNum         get_players( iPlayers, iNum, "a" );                 return iPlayers[ random( iNum ) ];     }

purple nurple 10-14-2007 19:46

Re: Random player
 
Quote:

random_person()
{
new iPlayers[32], iNum
get_players( iPlayers, iNum, "a" );

return iPlayers[ random( iNum ) ];
}
could i have alittle more help on the second one you gave me how do I make it so it gives stuff to the random player?

Arkshine 10-14-2007 22:03

Re: Random player
 
It retrieves a player list (alive) and return a random player id.

Of course you have to replace this function by the other above.


Code:
    #include <amxmodx>     #include <fakemeta>     public plugin_init()     {         register_plugin( "", "1.0", "Amxx Community" );         register_event( "HLTV", "eNew_round", "a", "1=0", "2=0" );     }         public eNew_round()     {         give_extra( random_person() );     }         random_person()     {         new iPlayers[32], iNum         get_players( iPlayers, iNum, "a" );                 return iPlayers[ random( iNum ) ];     }         give_extra( id )     {         set_pev( id, pev_health, 1000.0 );     }


All times are GMT -4. The time now is 01:23.

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