AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Making a menu to two differents index? (https://forums.alliedmods.net/showthread.php?t=132344)

#8 SickneSS 07-14-2010 10:01

Making a menu to two differents index?
 
Example...

PHP Code:

//Global
new Killler,Victim

//Init
   
register_event("DeathMsg","EventDeathMsg","a")

//EventDeathMsg
   
Killer read_data(1)
   
Victim read_data(2)

   if(
Killer != Victim)
   {
      
ShowMenu(Killer)
   }

//Menu
ShowMenu(Killer
{
        
//Menu Items
}
//Handler
{
      if(
Choice)
      { 
         
ShowMenu(Looser)
      }
   
//And continue with the same...if choice looser,openmenu to killer...


Is that possible?

wrecked_ 07-14-2010 10:22

Re: Making a menu to two differents index?
 
Yes, there are a few ways to go about doing this:
  1. You can store Loser in a global variable, easier but not the best way.
  2. Pass both the Killer and Loser id's into the ShowMenu function. Once you've done that, you can use the Loser's player index as the data for one of the menu items, and retrieve it in the handler function.

    ex:
    Code:
    ShowMenu( Killer, Loser ) {     new menu = menu_create( "", "" )     menu_additem( menu, "Do This", "0" )     new szId[3]     num_to_str( Loser, szId, 2 )     menu_additem( menu, "Do Other Thing With Loser", szId )     // ... } public Handler( id, menu, item ) {     new access, callback, data[3]     menu_item_getinfo( menu, item, access, data, 2, _, _, callback )     new choice = str_to_num( data )     // choice holds 0 if they chose option #1     // holds loser's ID if they chose option #2     // ... }

#8 SickneSS 07-14-2010 11:58

Re: Making a menu to two differents index?
 
Thanks wreked,I made the first way,here is the code..(Sorry if is redundant,it's the first time I made something like this...)
Compiles good but don't show the menu
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Knife Fight"
#define VERSION "1.0"
#define AUTHOR "#8 SickneSS"

/* Players */
new MaxPlayers

/* Players Index */
new Winner
new Looser
new iIndexz

/* Booleans */
new bool:KnifeFight
new bool:Choosing[33]

/* Buy Commands */ /*By fezh */
new BuyCommands[][] = 
{
    
"usp""glock""deagle""p228""elites""fn57""m3""xm1014""mp5""tmp""p90""mac10""ump45""ak47"
    
"galil""famas""sg552""m4a1""aug""scout""awp""g3sg1""sg550""m249""vest""vesthelm""flash""hegren",
    
"sgren""defuser""nvgs""shield""primammo""secammo""km45""9x19mm""nighthawk""228compact""12gauge",
    
"autoshotgun""smg""mp""c90""cv47""defender""clarion""krieg552""bullpup""magnum""d3au1""krieg550",
    
"buyammo1""buyammo2"
}

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
/* Command */
    
register_clcmd("say /kf","cmdKnifeFight",ADMIN_CFG)
    
    
/* Block Buy */
    
for (new 0sizeof (BuyCommands); i++)
        
register_clcmd(BuyCommands[i], "BlockBuyCommands")
    
    
/* Event */
    
register_event("DeathMsg","EventDeathMsg","a")
    
    
/* Ham Registration */
    
RegisterHam(Ham_Spawn,"player","HamSpawnPlayer",1)
    
    
/* Players */
    
MaxPlayers get_maxplayers()
}

public 
cmdKnifeFight(id,level,cid)
{
    if(!
cmd_access(id,level,cid,1))
        return 
PLUGIN_HANDLED
    
    
new name[32]
    
get_user_name(id,name,31)
    
    
KnifeFight true
    client_print
(0,print_chat,"ADMIN %s has make an knife fight",name)
    
server_cmd("sv_restart 1")
    
    return 
PLUGIN_HANDLED
}

public 
EventDeathMsg() 
{    
    if(
KnifeFight)
    {
        
Winner read_data(1)
        
Looser read_data(2)
        
        
iIndexz Winner+Looser
        
        
if(Winner MaxPlayers 
        
|| cs_get_user_team(Winner) == cs_get_user_team(Looser)) 
        return 
PLUGIN_HANDLED
        
        
new szWeapon[20]
        
szWeapon get_user_weapon2(Winner)
        
        if(
Winner != Looser && equal(szWeapon,"knife"))
        {
            
Choosing[Winner] = true
            ShowMenu
(iIndexz)
        }
        
        
KnifeFight false
    
}
    return 
PLUGIN_HANDLED
}

public 
HamSpawnPlayer(id
{
    
    if(
KnifeFight)
    {
        if(
is_user_connected(id))
        {
            
strip_user_weapons(id)
            
ham_strip_weapon(id,"CSW_C4")
            
give_item(id,"weapon_knife")
            
give_item(id,"item_kevlar")
        }
    }
}

public 
BlockBuyCommands(id
{
    
    if(
KnifeFight)
        return 
PLUGIN_HANDLED
    
    
return PLUGIN_CONTINUE
}


public 
ShowMenu(iIndexz)
{
    new 
Menu menu_create("Choose a teammate","MenuHandler")
    
    new 
name[32]
    new 
item[32]
    
    new 
Players[32]
    new 
Num
    get_players
(Players,Num)
    
    for(new 
0;Num;i++)
    {
        if(
is_user_connected(i) && cs_get_user_team(i) == CS_TEAM_SPECTATOR)
        {
            
get_user_name(i,name,31)
            
num_to_str(i,item,31)
            
            
menu_additem(Menu,name,item,_,menu_makecallback("MenuCallback")) 
        }
    }

    new 
temp[51]
    
    if(
Choosing[Winner] && Looser)
    {
        
get_user_name(Winner,name,31)
    
        
format(temp,50,"Waiting to %s",name)
    }
    else if(
Choosing[Looser] && Winner)
    {
        
get_user_name(Looser,name,31)
        
        
format(temp,50,"Waiting to %s",name)
    }
    
menu_setprop(Menu,MPROP_EXITNAME,temp)
    
    if(
Choosing[Winner] || Choosing[Looser])
        
menu_setprop(Menu,MPROP_EXITNAME,"Random")
    
    
menu_display(iIndexz,Menu)
}
public 
MenuCallback(iIndexz,Menu,item)
{
    if(
Choosing[Winner] && Looser)
        return 
ITEM_DISABLED
    
else if(Choosing[Looser] && Winner)
        return 
ITEM_DISABLED
    
    
return ITEM_ENABLED    
}
public 
MenuHandler(iIndexz,Menu,item)
{
    new 
name[32]
    
    if(
item == MENU_EXIT)
    {
        if(
Choosing[Winner])
        {
            
get_user_name(Winner,name,31)
            
RandomPlayer(Winner)
            
client_print(0,print_chat,"%s has made a random choice",name)
        }
        else if(
Choosing[Looser])
        {
            
get_user_name(Looser,name,31)
            
RandomPlayer(Looser)
            
client_print(0,print_chat,"%s has made a random choice",name)
        }
    }
    
    new 
iData[6]
    new 
iName[64]
    new 
Access
    
new Callback
    menu_item_getinfo
(Menu,item,Access,iData,5,iName,63,Callback)
    
    new 
Choosed str_to_num(iData)
    
    if(
Choosed && Winner)
    {
        
get_user_name(Winner,name,31)
        
        
cs_set_user_team(Choosed,cs_get_user_team(Winner))
        
client_print(0,print_chat,"%s has choosed %s",name,iName)
        
        
Choosing[Winner] = false
        Choosing
[Looser] = true
    
}
    else if(
Choosed && Looser)
    {
        
get_user_name(Looser,name,31)
        
        
cs_set_user_team(Choosed,cs_get_user_team(Looser))
        
client_print(0,print_chat,"%s has choosed %s",name,iName)
        
        
Choosing[Winner] = true
        Choosing
[Looser] = false
    
}
    
    if(
is_user_connected(iIndexz))
        
ShowMenu(iIndexz)        
}

stock RandomPlayerIndex /* By Bugsy */

    
    new 
Players32 ] , Num id;
    new 
bool:Checked32 ] , NumChecked;
    
    
get_playersPlayers Num );
        
    while ( 
NumChecked Num)
    {
        
id PlayersrandomNum ) ];
            
        if( !
Checkedid ] )
        {
            if ( ( 
id != Index ) && ( cs_get_user_teamid ) == CS_TEAM_SPECTATOR ) )
            {
                
cs_set_user_teamid cs_get_user_teamIndex ) )
                break;
            }
            else
            {
                
Checkedid ] = true;
                
NumChecked++;
            }
        }
    }
}              
            
stock ham_strip_weapon(const id,const weapon[]) /* By XxAvalanchexX */

    
    if(!
equal(weapon,"weapon_",7)) return 0;
    
    new 
wId get_weaponid(weapon);
    if(!
wId) return 0;
    
    new 
wEnt;
    while((
wEnt engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
    if(!
wEnt) return 0;
    
    if(
get_user_weapon(id) == wIdExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
    
    if(!
ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
    
ExecuteHamB(Ham_Item_Kill,wEnt);
    
    
set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));
    
    if(
wId == CSW_C4)
    {
        
cs_set_user_plant(id,0,0);
        
cs_set_user_bpammo(id,CSW_C4,0);
    }
    else if(
wId == CSW_SMOKEGRENADE || wId == CSW_FLASHBANG || wId == CSW_HEGRENADE)
        
cs_set_user_bpammo(id,wId,0);
    
    return 
1;
}

stock get_user_weapon2id /* By xPaw */

    
    new 
szWeapon[20]; 
    
get_weaponname(get_user_weapon(id), szWeaponcharsmax(szWeapon)); 
    
replace(szWeaponcharsmax(szWeapon), "weapon_"""); 
    
    return 
szWeapon;



wrecked_ 07-14-2010 12:12

Re: Making a menu to two differents index?
 
Remove
PHP Code:

new iIndexz 

from the top.

#8 SickneSS 07-14-2010 12:14

Re: Making a menu to two differents index?
 
If I do that,how I can make menu display?

#8 SickneSS 07-27-2010 16:44

Re: Making a menu to two differents index?
 
bump

Alucard^ 07-27-2010 17:38

Re: Making a menu to two differents index?
 
You are doing

iIndexz = winner + looser

If for example winner have id 10 and looser 5 you have id 15 so that is another player that has nothing to do with this... or maybe if an id have 20 and another 21 you have 41 that is not a valid id... If you want to do with a global variable you should do something like this:

Code:
enum {     Winner,     Looser }; new TwoIndex[2]; public function() {     TwoIndex[Winner] = winner;     TwoIndex[Looser] = Looser;         ShowMenu(TwoIndex[Winner], TwoIndex[Looser]); }

fysiks 07-27-2010 20:56

Re: Making a menu to two differents index?
 
Quote:

Originally Posted by Alucard^ (Post 1253463)
Code:
    ShowMenu(TwoIndex[Winner], TwoIndex[Looser]);

Ummm . . . no.

And, why did you make it so complicated for no reason?
PHP Code:

ShowMenu(Winner)
ShowMenu(Loser

if you want to show them both the same menu.

Alucard^ 07-27-2010 23:07

Re: Making a menu to two differents index?
 
Why not? But yeah, my example is if he don't want to show the same menu.

fysiks 07-28-2010 17:48

Re: Making a menu to two differents index?
 
Quote:

Originally Posted by Alucard^ (Post 1253795)
Why not? But yeah, my example is if he don't want to show the same menu.

Look at how ShowMenu is defined: public ShowMenu(iIndexz). Do you see two arguments there?

If they are to see the same menu then you could modify ShowMenu() to show the same menu to both players with two arguments.


All times are GMT -4. The time now is 07:13.

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