Raised This Month: $ Target: $400
 0% 

Loop And Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 12-29-2018 , 11:18   Loop And Menu
Reply With Quote #1

What's wrong with this code i'm trying to loop through all alive terrorist player and add them on menu then adding gOn[tempid] = true; on that particular terrorist selected in menu

PHP Code:
public hu()
{
    
    new 
menu menu_create("Menu","h_handler");
    new 
name[32],text[32]
    
    new 
Players[32]  
    new 
playerCountiszTempid,player  
    get_players
(PlayersplayerCount"che","TERRORIST" )  
    for (
i=0i<playerCounti++) 
    { 
        
player Players[i]  
    

        
get_user_name(playername31
    
num_to_strplayerszTempid)  

        
format(text31"%s - %s"name
        
menu_additemmenunameszTempid);
    }; 

 
    
menu_display(humenu0)     
    return 
PLUGIN_HANDLED;
}   
   
public 
h_handler(id,menu,item)
{
if( 
item == MENU_EXIT )
    {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    new 
data], iName64 ];
    new 
accesscallback;
    
menu_item_getinfomenuitemaccessdata,5iName63callback );

    new 
tempid str_to_numdata );
    if( !
is_user_bottempid ) )
        
gOn[tempid] = true;
    
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;


Last edited by Awesome_man; 12-29-2018 at 11:20.
Awesome_man is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 12-29-2018 , 12:32   Re: Loop And Menu
Reply With Quote #2

1. You've passed only one argument in string formation.
Code:
 format(text, 31, "%s - %s", name)
2. You have 'c' flag in get_players which means you wont get bots
so using is_user_bot is not required in handler, but you
should use is_user_connected cause before selecting an item
from menu (target) player may disconnect from the game

================
For efficiency do not convert player index to string and vice versa.
Use following style:

=> SET
new ItemInfo[2];
ItemInfo[0] = <PlayerIndex>;
menu_additem(...., ...., ItemInfo, ...)
=> GET
new ItemInfo[2];
menu_item_getinfo(..., ..., ..., ItemInfo, charsmax(ItemInfo), ....);
<PlayerIndex> = ItemInfo[0];
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 12-29-2018 at 12:37.
Ghosted is offline
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 12-29-2018 , 23:14   Re: Loop And Menu
Reply With Quote #3

Quote:
Originally Posted by Ghosted View Post
1. You've passed only one argument in string formation.
Code:
 format(text, 31, "%s - %s", name)
2. You have 'c' flag in get_players which means you wont get bots
so using is_user_bot is not required in handler, but you
should use is_user_connected cause before selecting an item
from menu (target) player may disconnect from the game

================
For efficiency do not convert player index to string and vice versa.
Use following style:

=> SET
new ItemInfo[2];
ItemInfo[0] = <PlayerIndex>;
menu_additem(...., ...., ItemInfo, ...)
=> GET
new ItemInfo[2];
menu_item_getinfo(..., ..., ..., ItemInfo, charsmax(ItemInfo), ....);
<PlayerIndex> = ItemInfo[0];
can you please show this in main code i'm very beginner in scripting and trying my best but it's somehow not working. Thank you
Awesome_man is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 12-30-2018 , 03:47   Re: Loop And Menu
Reply With Quote #4

Quote:
Originally Posted by Awesome_man View Post
can you please show this in main code i'm very beginner in scripting and trying my best but it's somehow not working. Thank you
Code:
 format(text, 31, "%s - %s", name)

What do you want to show here, i see two '%s'-s in code so you want to show two strings? one is player name and another!?
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted is offline
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 12-30-2018 , 04:00   Re: Loop And Menu
Reply With Quote #5

Quote:
Originally Posted by Ghosted View Post
Code:
 format(text, 31, "%s - %s", name)

What do you want to show here, i see two '%s'-s in code so you want to show two strings? one is player name and another!?
I want to apply gOn[tempid] = true; if i select a specific player and if i again select that player it should gOn[tempid] = false;
Awesome_man is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 12-30-2018 , 05:03   Re: Loop And Menu
Reply With Quote #6

Code:
#include <amxmodx>
#include <amxmisc>

new gOn[33];

public ShowMenu(Caller)
{
	new Menu = menu_create("Menu", "Handler_Menu");
	new Players[32], PlayerCount, Target, Name[32], Text[32 + 2], ItemInfo[2];
	get_players(Players, PlayerCount, "che", "TERRORIST")  ;
	
	for (new Index = 0; Index < PlayerCount; Index++)
	{
		Target = Players[Index];
		ItemInfo[0] = Target;
		get_user_name(Target, Name, charsmax(Name));
		formatex(Text, charsmax(Text), "%s%s", gOn[Target] ? "\r" : "\y", Name);
		menu_additem(Menu, Text, ItemInfo);
	}
	
	menu_display(Caller, Menu);
}

public Handler_Menu(PlayerID, MenuID, ItemID)
{
	if (ItemID < 0)
		goto Ignore;
	
	new ItemInfo[2];
	menu_item_getinfo(MenuID, ItemID, _, ItemInfo, charsmax(ItemInfo));
	new Target = ItemInfo[0];
	
	if (!is_user_connected(Target))
		goto Ignore;
	
	gOn[Target] = !gOn[Target];
	
Ignore:
	menu_destroy(MenuID);
}
Not Tested But Compilable (1.8.3+)

RED Name = gOn = true
YELLOW Name = gOn = false
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 12-30-2018 at 05:03.
Ghosted is offline
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 12-30-2018 , 07:05   Re: Loop And Menu
Reply With Quote #7

Quote:
Originally Posted by Ghosted View Post
Code:
#include <amxmodx>
#include <amxmisc>

new gOn[33];

public ShowMenu(Caller)
{
	new Menu = menu_create("Menu", "Handler_Menu");
	new Players[32], PlayerCount, Target, Name[32], Text[32 + 2], ItemInfo[2];
	get_players(Players, PlayerCount, "che", "TERRORIST")  ;
	
	for (new Index = 0; Index < PlayerCount; Index++)
	{
		Target = Players[Index];
		ItemInfo[0] = Target;
		get_user_name(Target, Name, charsmax(Name));
		formatex(Text, charsmax(Text), "%s%s", gOn[Target] ? "\r" : "\y", Name);
		menu_additem(Menu, Text, ItemInfo);
	}
	
	menu_display(Caller, Menu);
}

public Handler_Menu(PlayerID, MenuID, ItemID)
{
	if (ItemID < 0)
		goto Ignore;
	
	new ItemInfo[2];
	menu_item_getinfo(MenuID, ItemID, _, ItemInfo, charsmax(ItemInfo));
	new Target = ItemInfo[0];
	
	if (!is_user_connected(Target))
		goto Ignore;
	
	gOn[Target] = !gOn[Target];
	
Ignore:
	menu_destroy(MenuID);
}
Not Tested But Compilable (1.8.3+)

RED Name = gOn = true
YELLOW Name = gOn = false
PHP Code:
public ShowMenu(Caller)
{
    new 
Menu menu_create("Menu""Handler_Menu");
    new 
Players[32], PlayerCountTargetName[32], Text[32 2], ItemInfo[2];
    
get_players(PlayersPlayerCount"che""TERRORIST")  ;
    
    for (new 
Index 0Index PlayerCountIndex++)
    {
        
Target Players[Index];
        
ItemInfo[0] = Target;
        
get_user_name(TargetNamecharsmax(Name));
        
formatex(Textcharsmax(Text), "%s%s"gOn[Target] ? "\r" "\y"Name);
        
menu_additem(MenuTextItemInfo);
    }
    
    
menu_display(CallerMenu);
}


public 
Handler_Menu(PlayerIDMenuIDItemID)
{
    if (
ItemID 0)
        goto 
Ignore;
    
    new 
ItemInfo[2];
    
menu_item_getinfo(MenuIDItemID_ItemInfocharsmax(ItemInfo));
    new 
Target ItemInfo[0];
    
    if (!
is_user_connected(Target))
        goto 
Ignore;
    
    
gOn[Target] = !gOn[Target];
    
Ignore:
    
menu_destroy(MenuID);

2 compile error
Awesome_man is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-30-2018 , 07:49   Re: Loop And Menu
Reply With Quote #8

What are they?
__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 12-30-2018 , 08:01   Re: Loop And Menu
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
What are they?
Error: Argument does not have a default value (argument 3) on line 42
Error: Number of arguments does not match definition on line 42
Awesome_man is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-30-2018 , 08:16   Re: Loop And Menu
Reply With Quote #10

The code that ghosted gave you doesnt have a line 42

Show the code of that line if it exists.
__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 12-30-2018 at 08:17.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply


Thread Tools
Display Modes

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 19:23.


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