Raised This Month: $51 Target: $400
 12% 

Random Choice ? ..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zaidbt
Senior Member
Join Date: Jun 2014
Location: Morroco
Old 03-30-2015 , 16:58   Random Choice ? ..
Reply With Quote #1

Hey again ,

how to do a random choice in a Classmenu from 1 to 5 if player don't chose after 10 secs ? Ty
__________________
http://steamcommunity.com/profiles/76561198044821965
=========Working On Naruto Mod========
Zaidbt is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-30-2015 , 19:36   Re: Random Choice ? ..
Reply With Quote #2

If this "classmenu" to which you are referring is a menu created in a plugin then you would simply set a task when you show the menu for the function that does the random choice. When they do choose, remove the task. Also, in your "random choice" function, you would want to remove the menu from the screen (which you can find in the notes of the "New Menus" tutorial).
__________________
fysiks is offline
Zaidbt
Senior Member
Join Date: Jun 2014
Location: Morroco
Old 03-31-2015 , 14:47   Re: Random Choice ? ..
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
If this "classmenu" to which you are referring is a menu created in a plugin then you would simply set a task when you show the menu for the function that does the random choice. When they do choose, remove the task. Also, in your "random choice" function, you would want to remove the menu from the screen (which you can find in the notes of the "New Menus" tutorial).
Exemple pls ?
__________________
http://steamcommunity.com/profiles/76561198044821965
=========Working On Naruto Mod========
Zaidbt is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-01-2015 , 02:57   Re: Random Choice ? ..
Reply With Quote #4

Wow, have you even tried? Fysiks pretty much gave you a step-by-step tutorial.
mottzi is offline
Send a message via MSN to mottzi
Zaidbt
Senior Member
Join Date: Jun 2014
Location: Morroco
Old 04-01-2015 , 07:14   Re: Random Choice ? ..
Reply With Quote #5

Quote:
Originally Posted by mottzi View Post
Wow, have you even tried? Fysiks pretty much gave you a step-by-step tutorial.
No really -_- ...

any way :
Quote:
Originally Posted by fysiks View Post
If this "classmenu" to which you are referring is a menu created in a plugin then you would simply set a task when you show the menu for the function that does the random choice. When they do choose, remove the task. Also, in your "random choice" function, you would want to remove the menu from the screen (which you can find in the notes of the "New Menus" tutorial).
Setting a task , here
PHP Code:
public plugin_init()      
    
register_event("HLTV""EventHLTV""a""1=0""2=0"); 

public 
EventHLTV()    
    
set_task(8.0"Classmenu");
public 
Classmenuid )     
{     

    new 
menu menu_create"Class menu""menu_handler" )     
    
    
menu_additemmenu"\\w Gaara \\y[ Fly + Speed]""");  
    
menu_additemmenu"\\w Naruto \\y[ Speed +Hp+Shadow-Clone]""");  
    
menu_additemmenu"\\r Madara \\y[ Grab + Speed O.Admins]"""ADMIN_BAN );  
    
menu_additemmenu"\\w Pain \\y[ No Clip +low hp]""");
    
menu_additemmenu"\\r Sasuke \\y[ Portals + Speed ]""");    
    
    
menu_setpropmenuMPROP_EXITMEXIT_ALL )          
    
menu_displayidmenu)         
}     

public 
menu_handleridmenuitem )     
{          
    switch( 
item )     
    {     
        case 
0:     
        {     
            
client_printidprint_chat"You Are now Gaara " )                  
            
set_user_health(idget_user_healthid ) + 300);  
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE10
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Gaara")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell00300kRenderGlow20);                  
            
Hasxxx[id] = false
            Hasx
[id] = false
        
}     
        case 
1:     
        {     
            
client_printidprint_chat" You are now Naruto" );  
            
set_user_health(idget_user_healthid ) + 450);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE10
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE10)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Naruto")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxFadeFast00250kRenderGlow80); 
            
Hasxxx[id] = false
            Hasx
[id] = false
        
}     
        case 
2:     
        {     
            
client_printidprint_chat"You have selected Madara" ); 
            
set_user_health(idget_user_healthid ) + 350);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Madara"
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell00340kRenderGlow20); 
            
Hasxxx[id] = false
            Hasx
[id] = false
            
        
}     
        case 
3:     
        {     
            
client_printidprint_chat"You have selected Pain" ); 
            
set_user_health(idget_user_healthid ) + 150);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"pain"
            
set_user_noclip(id1)
            
set_user_rendering(idkRenderFxGlowShell0098kRenderGlow10);   
            
Hasxxx[id] = false
            Hasx
[id] = true
            
        
}     
        case 
4:     
        {     
            
client_printidprint_chat"You have selected Sasuke" );
            
client_printidprint_chat"Use Bind X portal_entrance & bind x2 portal_exit" ); 
            
set_user_health(idget_user_healthid ) + 350);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Sasuke")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell00200kRenderGlow20);  
            
Hasxxx[id] = true
            Hasx
[id] = false
        
}    
        
        case 
MENU_EXIT:     
        {     
            
client_printidprint_chat"You exited the menu , we'll select for you a Random Class... " )     
        }     
    }     
    
    
    
menu_destroymenu )     
    return 
PLUGIN_HANDLED     

Then for the random Fct it should be something like this ?
PHP Code:
new rand random_num(1,6)



switch(
rand)
{
case 
1
case 
2
case 
3
case 
4
case 
5
case 
6
  

But what to write in Case 1-2..6 ? that's what i dont know :S
__________________
http://steamcommunity.com/profiles/76561198044821965
=========Working On Naruto Mod========
Zaidbt is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-01-2015 , 07:56   Re: Random Choice ? ..
Reply With Quote #6

please note the coloring...

Quote:
you would simply set a task when you show the menu for the function that does the random choice. When they do choose, remove the task. Also, in your "random choice" function, you would want to remove the menu from the screen (which you can find in the notes of the "New Menus" tutorial).
Code:
public menu_class(id)      
{      
    ...
 
    menu_display(id, menu, 0)    
    set_task(10.0, "randomChoice", id + 1337)      
}      
public menu_handler(id, menu, item)      
{ 
    if(item == MENU_EXIT)
        return PLUGIN_HANDLED;
 
    if(task_exists(id + 1337))
        remove_task(id + 1337);
 
    switch(item)
    {
        case 0:
        {
        }
        ...
    }   
}  
public randomChoice(id)
{
    id -= 1337;
 
    show_menu(id, 0, "^n", 1);
 
    switch(random_num(0, 4))
    {
        case 0:
        {
        }
        ...
    }
}
mottzi is offline
Send a message via MSN to mottzi
Zaidbt
Senior Member
Join Date: Jun 2014
Location: Morroco
Old 04-01-2015 , 08:31   Re: Random Choice ? ..
Reply With Quote #7

Quote:
Originally Posted by mottzi View Post
please note the coloring...


Code:
public menu_class(id)      
{      
    ...
 
    menu_display(id, menu, 0)    
    set_task(10.0, "randomChoice", id + 1337)      
}      
public menu_handler(id, menu, item)      
{ 
    if(item == MENU_EXIT)
        return PLUGIN_HANDLED;
 
    if(task_exists(id + 1337))
        remove_task(id + 1337);
 
    switch(item)
    {
        case 0:
        {
        }
        ...
    }   
}  
public randomChoice(id)
{
    id -= 1337;
 
    show_menu(id, 0, "^n", 1);
 
    switch(random_num(0, 4))
    {
        case 0:
        {
        }
        ...
    }
}
That's awesome Bro ty . Why 1337 pls ? Sry for being too heavy
I did that n, but i dont know what's wrong xD
PHP Code:
public onSpawnPost(id)   
    
Classmenu(id)    

public 
Classmenuid )     
{     
    
    new 
menu menu_create"Class menu""menu_handler" )     
    
    
menu_additemmenu"\\w Gaara \\y[ Fly + Speed]""");  
    
menu_additemmenu"\\w Naruto \\y[ Speed +Hp+Shadow-Clone]""");  
    
menu_additemmenu"\\r Madara \\y[ Grab + Speed O.Admins]"""ADMIN_BAN );  
    
menu_additemmenu"\\w Pain \\y[ No Clip +low hp]""");
    
menu_additemmenu"\\r Sasuke \\y[ Portals + Speed ]""");    
    
    
menu_setpropmenuMPROP_EXITMEXIT_ALL )          
    
menu_displayidmenu)   
    
set_task(7.0"randomChoice"id 1337)
}     

public 
menu_handleridmenuitem )     
{     
    if(
item == MENU_EXIT)
        return 
PLUGIN_HANDLED;
 
    if(
task_exists(id 1337))
        
remove_task(id 1337);     
    switch( 
item )     
    {     
        case 
0:     
        {     
            
client_printidprint_chat"You Are now Gaara " )                  
            
set_user_health(idget_user_healthid ) + 300);  
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE10
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Gaara")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell153760kRenderGlow50);                   
            
Hasxxx[id] = false
            Hasx
[id] = false
        
}     
        case 
1:     
        {     
            
client_printidprint_chat" You are now Naruto" );  
            
set_user_health(idget_user_healthid ) + 450);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE10
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE10)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Naruto")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell255690kRenderGlow200);  
            
Hasxxx[id] = false
            Hasx
[id] = false
        
}     
        case 
2:     
        {     
            
client_printidprint_chat"You have selected Madara" ); 
            
set_user_health(idget_user_healthid ) + 350);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Madara"
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell05555kRenderGlow200); 
            
Hasxxx[id] = false
            Hasx
[id] = false
            
        
}     
        case 
3:     
        {     
            
client_printidprint_chat"You have selected Pain" ); 
            
set_user_health(idget_user_healthid ) + 150);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"pain"
            
set_user_noclip(id1)
            
set_user_rendering(idkRenderFxGlowShell0128255kRenderGlow10);   
            
Hasxxx[id] = false
            Hasx
[id] = true
            
        
}     
        case 
4:     
        {     
            
client_printidprint_chat"You have selected Sasuke" );
            
client_printidprint_chat"Use Bind X portal_entrance & bind x2 portal_exit" ); 
            
set_user_health(idget_user_healthid ) + 350);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Sasuke")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell1020102kRenderGlow100);  
            
Hasxxx[id] = true
            Hasx
[id] = false
        
}    
        
        case 
MENU_EXIT:     
        {     
            
client_printidprint_chat"You exited the menu , we'll select for you a Random Class... " )     
        }     
    }     
    
    
    
menu_destroymenu )     
    return 
PLUGIN_HANDLED     

public 
randomChoice(id)
{
    
id -= 1337;
 
    
show_menu(id0"^n"1);
 
    switch(
random_num(04))
    {
        case 
0:     
        {     
            
client_printidprint_chat"You Are now Gaara " )                  
            
set_user_health(idget_user_healthid ) + 300);  
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE10
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Gaara")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell153760kRenderGlow50);                   
            
Hasxxx[id] = false
            Hasx
[id] = false
        
}     
        case 
1:     
        {     
            
client_printidprint_chat" You are now Naruto" );  
            
set_user_health(idget_user_healthid ) + 450);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE10
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE10)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Naruto")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell255690kRenderGlow200);  
            
Hasxxx[id] = false
            Hasx
[id] = false
        
}     
        case 
2:     
        {     
            
client_printidprint_chat"You have selected Madara" ); 
            
set_user_health(idget_user_healthid ) + 350);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Madara"
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell05555kRenderGlow200); 
            
Hasxxx[id] = false
            Hasx
[id] = false
            
        
}     
        case 
3:     
        {     
            
client_printidprint_chat"You have selected Pain" ); 
            
set_user_health(idget_user_healthid ) + 150);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"pain"
            
set_user_noclip(id1)
            
set_user_rendering(idkRenderFxGlowShell0128255kRenderGlow10);   
            
Hasxxx[id] = false
            Hasx
[id] = true
            
        
}     
        case 
4:     
        {     
            
client_printidprint_chat"You have selected Sasuke" );
            
client_printidprint_chat"Use Bind X portal_entrance & bind x2 portal_exit" ); 
            
set_user_health(idget_user_healthid ) + 350);
            
give_item(id"weapon_hegrenade"
            
give_item(id"weapon_smokegrenade"
            
cs_set_user_bpammo(idCSW_HEGRENADE5
            
cs_set_user_bpammo(idCSW_SMOKEGRENADE5)
            
set_user_maxspeed(id850.0); 
            
cs_set_user_model(id"Sasuke")
            
set_user_noclip(id0)
            
set_user_rendering(idkRenderFxGlowShell1020102kRenderGlow100);  
            
Hasxxx[id] = true
            Hasx
[id] = false
        
}    
        
        case 
MENU_EXIT:     
        {     
            
client_printidprint_chat"You exited the menu , we'll select for you a Random Class... " )     
        }     
    
    
        

__________________
http://steamcommunity.com/profiles/76561198044821965
=========Working On Naruto Mod========

Last edited by Zaidbt; 04-01-2015 at 09:17.
Zaidbt is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-01-2015 , 09:15   Re: Random Choice ? ..
Reply With Quote #8

Each task can be identified through its id; if you want a player specific task you normaly take a random value and add the player id to it, this value is then the task id. By subtracting the random value, you get the player id again.

Quote:
random value: 100
player id: 5
PHP Code:
set_task(10.0"function"100 id// task id is 105

public function(id// this id is 105
{
    
id -= 100// now id is 5 again, we can use it as player id now
    
set_user_health(id200)

You normaly want to do this if you know your plugins will need more than 1 player specific task, so you don't create multiple tasks with the same taskid.
mottzi is offline
Send a message via MSN to mottzi
Zaidbt
Senior Member
Join Date: Jun 2014
Location: Morroco
Old 04-01-2015 , 09:39   Re: Random Choice ? ..
Reply With Quote #9

Quote:
Originally Posted by mottzi View Post
Each task can be identified through its id; if you want a player specific task you normaly take a random value and add the player id to it, this value is then the task id. By subtracting the random value, you get the player id again.



PHP Code:
set_task(10.0"function"100 id// task id is 105

public function(id// this id is 105
{
    
id -= 100// now id is 5 again, we can use it as player id now
    
set_user_health(id200)

You normaly want to do this if you know your plugins will need more than 1 player specific task, so you don't create multiple tasks with the same taskid.
Got it , Ty but why i doesnt work ? what'swrong pls ?
__________________
http://steamcommunity.com/profiles/76561198044821965
=========Working On Naruto Mod========
Zaidbt is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 04-01-2015 , 11:11   Re: Random Choice ? ..
Reply With Quote #10

What doesn't work? You should debug your code.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd 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 15:23.


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