AlliedModders

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

sibox 11-21-2010 13:46

Random Function
 
I'm trying to start a random function with this but i can't get it work
Code:

public RandomFunc() {
    new a = random_num(1,3)
    switch(a) {
        case 1:
            { Function1 }
        case 2:
            { Function2 }
        case 3:
            { Function3 }
    }
}

if i try set_task(5.0,RandomFunc) it doesnt do anything? Please help

Exolent[jNr] 11-21-2010 13:48

Re: Random Function
 
Your code is almost right.

Code:
public RandomFunc( ) {     switch( random_num( 1, 3 ) )     {         case 1:         {             Function1( );         }         case 2:         {             Function2( );         }         case 3:         {             Function3( );         }     } } Function1( ) {     // function 1 called } Function2( ) {     // function 2 called } Function3( ) {     // function 3 called }

sibox 11-21-2010 13:58

Re: Random Function
 
Again not working. My all code is
Code:

new players;
new randompl;



public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_logevent("StartRound",2,"1=Round_Start")
    randompl = random_num(1,players)
    players = get_playersnum();
}

public StartRound()
{
    if(players >= 1) {
        new cName[32]
        get_user_name(randompl, cName, 31)
        set_hudmessage(255, 0, 0, -1.0, 0.01)
        show_hudmessage(0, "%s is the Choosen One!", cName)
        set_task(5.0, "RandomFunc")
    }
}



Deagle( const id )
{
    new deagle = give_item(id, "weapon_deagle");
    cs_set_weapon_ammo(deagle, 1)
    client_print(id, print_chat, "You Recieve Deagle")
}

AWP( const id )
{
    new awp = give_item(id, "weapon_awp");
    cs_set_weapon_ammo(awp, 1)
    client_print(id, print_chat, "You Recieve AWP")
}

Health( const id )
{
    set_user_health(id, 150)
    client_print(id, print_chat, "You Recieve Health")
   
}

public RandomFunc( )
{
    switch( random_num( 1, 3 ) )
    {
        case 1:
        {
            Deagle( randompl );
        }
        case 2:
        {
            AWP( randompl );
        }
        case 3:
        {
            Health( randompl );
        }
    }
}

Where is my mistake

Exolent[jNr] 11-21-2010 14:04

Re: Random Function
 
You are getting the random player incorrectly.
Also, you can't save the number of players are plugin start because it will change.

sibox 11-21-2010 14:07

Re: Random Function
 
1.Can you tell me how to get the random player correctly
2. I will move it to StartRound

Exolent[jNr] 11-21-2010 14:11

Re: Random Function
 
https://forums.alliedmods.net/showthread.php?t=74666

sibox 11-21-2010 14:22

Re: Random Function
 
Thanks but how can i get the username of the player from your TUT

Exolent[jNr] 11-21-2010 15:35

Re: Random Function
 
Code:
someFunction( ) {     new iPlayers[ 32 ], iNum;     get_players( iPlayers, iNum, "a" );         new iPlayer = iPlayers[ random( iNum ) ];         // iPlayer is the index of a random alive player }

Use that like you would any other player id.

sibox 11-23-2010 12:18

Re: Random Function
 
Thank you. You've helped me sooo much !


All times are GMT -4. The time now is 11:19.

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