AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help menu if you have players add glow (https://forums.alliedmods.net/showthread.php?t=242459)

Toallin 06-20-2014 00:08

Help menu if you have players add glow
 
I come to ask for some help

What happens is that players have a menu to give glow
As I can add to the list when I give a glow next to your name and a Tag (glow) exit.

example:

without glow:
1. zoolk

con glow
1. zoolk (glow)

How to add the tag to the side of the name

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /giveglow""menu_glow")
}

public 
menu_glow(id

    if (
cs_get_user_team(id) != CS_TEAM_CT
    {  
        new 
menu menu_create("\rGlow Menu:""glow"); 
        
        new 
players[32], pnumtempid
        new 
szName[32], szTempid[10]; 
        
        
get_players(playerspnum"a"); 
        
        for( new 
0pnumi++ ) 
        { 
            
tempid players[i]; 
            
            if (
cs_get_user_team(tempid) != CS_TEAM_CT
                continue;
            
            
get_user_name(tempidszName31); 
            
num_to_str(tempidszTempid9); 
            
menu_additem(menuszNameszTempid0); 
        } 
        
        
menu_display(idmenu); 
        return 
PLUGIN_HANDLED
    }
    else
    {
        
client_print(idprint_chat"not have access to this command")
    }
    return 
PLUGIN_HANDLED;
}

public 
glow(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdata,5iName63callback)
    
    new 
tempid str_to_num(data); 
    new 
szName[32], szName2[32]; 
    
get_user_name(idszName31); 
    
get_user_name(idszName231);

        
set_user_rendering(tempidkRenderFxGlowShell25500kRenderNormal)

        
client_print(id,print_chat,"Player %s Give glow to %s"szNameszName2)
        
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED;


Whoever can help me thanks

Flick3rR 06-20-2014 09:51

Re: Help menu if you have players add glow
 
Here it is. I made some optimisations over there, too.
- You don't have to check the tempid's team when you make the menu. Just use the "e" flag in get_players() and then put team "CT"
- You have wrong index here
PHP Code:

    new szName[32], szName2[32]; 
    
get_user_name(idszName31); 
    
get_user_name(idszName231); 

I think the second index should be "tempid"
- Also, you may not make num_to_str when making the menu, and then get menu info in the handler, but just use the "item" variable to get the index... But this is not something big, so I won't change it.
- Avoid hardcoding, use charsmax insted of just typing the number in the function.

Now how to add that tag. I think it's the best way to create a boolean, which will be true if the user has glow, and false when the user hasn't glow. We create it false by deafult
PHP Code:

new bool:HasGlow[33] = false 

Then we set it to true in the function where we give rendering. Also, to make the menu like when user already has glow, it will show "glow" in the menu. And when you choose a player which already has glow, his glowing will be removed. For that we have to set the opposite value of the bool. In other words, if it's true - we set false, if it's false - we set true. This is made easily with this simple function:
PHP Code:

HasGlow[tempid] = !HasGlow[tempid

This setting opposite value we need to put in the function, where we set the glow. Here:
PHP Code:

public glow(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], iName[64], accesscallback 
    menu_item_getinfo
(menuitemaccessdata,charsmax(data), iNamecharsmax(iName), callback)
    
    new 
tempid str_to_num(data
    
    new 
szName[32], szName2[32
    
get_user_name(idszNamecharsmax(szName)) 
    
get_user_name(tempidszName2charsmax(szName2))

    
//Here we set the rendering. Pay attention to the specific value - if the bool is true, it means 
    //the user already has rendering, so then we remove it and set value 0.
    //If the bool is false, it means the user hasn't got glow, so we set him the glow
    //And everyone is happy :D
    
set_user_rendering(tempidkRenderFxGlowShellHasGlow[tempid] ? 25500kRenderNormal)
    
//Here we set the opposite value of the bool
    
HasGlow[tempid] = !HasGlow[tempid]

    
//We need to change and the chat message depending on the bool of user.
    
client_print(id,print_chat,"Player %s %s %s"szNameHasGlow[tempid] ? "gave glow to" "took glow from"szName2)
         
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED


Okay, the setting of the bool is finished. Now we need to change the player's name in the menu with the tag. It's easy. We put a condition in the "any" parameter of the formatex function, where we check the bool and set the tag if it's true. We can make it like this:
PHP Code:

for( new 0pnumi++ ) 
    { 
        
tempid players[i
            
        
get_user_name(tempidszNamecharsmax(szName)) 
        
        
//Here we formatex the name with the tag if the bool is true.
        
formatex(szNamecharsmax(szName), "%s%s"szNameHasGlow[tempid] ? " \r(Glow)" "")
        
        
num_to_str(tempidszTempidcharsmax(szTempid)) 
        
menu_additem(menuszNameszTempid0)
    } 





Here is the whole redacted code.
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <cstrike>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new bool:HasGlow[33] = false

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /giveglow""menu_glow")
}

public 
menu_glow(id

    if (
cs_get_user_team(id) != CS_TEAM_CT
    {  
        
client_print(idprint_chat"Only CTs have access to that command!")
        return 
PLUGIN_HANDLED
    
}
    new 
menu menu_create("\rGlow Menu:""glow"
        
    new 
players[32], pnumtempid 
    
new szName[32], szTempid[10
        
    
get_players(playerspnum"aeh""CT"
        
    for( new 
0pnumi++ ) 
    { 
        
tempid players[i
            
        
get_user_name(tempidszNamecharsmax(szName)) 
        
        
formatex(szNamecharsmax(szName), "%s%s"szNameHasGlow[tempid] ? " \r(Glow)" "")
        
        
num_to_str(tempidszTempidcharsmax(szTempid)) 
        
menu_additem(menuszNameszTempid0)
    } 
        
    
menu_display(idmenu
    
    return 
PLUGIN_HANDLED
}

public 
glow(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], iName[64], accesscallback 
    menu_item_getinfo
(menuitemaccessdata,charsmax(data), iNamecharsmax(iName), callback)
    
    new 
tempid str_to_num(data
    
    new 
szName[32], szName2[32
    
get_user_name(idszNamecharsmax(szName)) 
    
get_user_name(tempidszName2charsmax(szName2))

        
    
set_user_rendering(tempidkRenderFxGlowShell25500kRenderNormal)
    
HasGlow[tempid] = !HasGlow[tempid]

    
client_print(id,print_chat,"Player %s Give glow to %s"szNameszName2)
        
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED



Toallin 06-20-2014 12:42

Re: Help menu if you have players add glow
 
good Flick3rR thaks voy very much

Flick3rR 06-20-2014 13:35

Re: Help menu if you have players add glow
 
Well, you have changed something. Post your code.


All times are GMT -4. The time now is 21:14.

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