Raised This Month: $ Target: $400
 0% 

Random Function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sibox
Member
Join Date: Apr 2009
Location: Bulgaria
Old 11-21-2010 , 13:46   Random Function
Reply With Quote #1

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
sibox is offline
Send a message via Skype™ to sibox
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-21-2010 , 13:48   Re: Random Function
Reply With Quote #2

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 }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sibox
Member
Join Date: Apr 2009
Location: Bulgaria
Old 11-21-2010 , 13:58   Re: Random Function
Reply With Quote #3

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
sibox is offline
Send a message via Skype™ to sibox
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-21-2010 , 14:04   Re: Random Function
Reply With Quote #4

You are getting the random player incorrectly.
Also, you can't save the number of players are plugin start because it will change.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sibox
Member
Join Date: Apr 2009
Location: Bulgaria
Old 11-21-2010 , 14:07   Re: Random Function
Reply With Quote #5

1.Can you tell me how to get the random player correctly
2. I will move it to StartRound
sibox is offline
Send a message via Skype™ to sibox
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-21-2010 , 14:11   Re: Random Function
Reply With Quote #6

https://forums.alliedmods.net/showthread.php?t=74666
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sibox
Member
Join Date: Apr 2009
Location: Bulgaria
Old 11-21-2010 , 14:22   Re: Random Function
Reply With Quote #7

Thanks but how can i get the username of the player from your TUT
sibox is offline
Send a message via Skype™ to sibox
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-21-2010 , 15:35   Re: Random Function
Reply With Quote #8

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.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sibox
Member
Join Date: Apr 2009
Location: Bulgaria
Old 11-23-2010 , 12:18   Re: Random Function
Reply With Quote #9

Thank you. You've helped me sooo much !
sibox is offline
Send a message via Skype™ to sibox
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 11:19.


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