This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Ham_Use and Button id's (HELP)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-30-2016 , 13:54   Ham_Use and Button id's (HELP)
Reply With Quote #1

This is the code I recently wrote:

Code:
#pragma tabsize 0 #include <amxmodx> #include <hamsandwich> #include <fakemeta> #include <engine> public plugin_init() {     register_plugin("Some Buttons Shitties", "1.0", "No one .. for now!")         if( engfunc(EngFunc_FindEntityByString,-1 ,"classname", "func_button"))         RegisterHam(Ham_Use, "func_button", "fwButtonUsed")     if(engfunc(EngFunc_FindEntityByString,-1 ,"classname","func_rot_button"))         RegisterHam(Ham_Use, "func_rot_button", "fwButtonUsed")             if(engfunc(EngFunc_FindEntityByString,-1 ,"classname", "button_target"))         RegisterHam(Ham_Use, "button_target", "fwButtonUsed") } public fwButtonUsed(ent, idcaller, idactivator, use_type, Float:value) {     if(idcaller != idactivator) return HAM_IGNORED         client_print(idcaller, print_chat, "%i", ent)         new szMapName[32]         get_mapname(szMapName,charsmax(szMapName))         if(ent == 116 && equali("deathrun_arctic", szMapName))         user_kill(idcaller, 1)         return HAM_IGNORED }

This line:

Code:
client_print(idcaller, print_chat, "%i", ent)

I get the button ID I just pushed on the map. Then I add it at the check:

Code:
if(ent == 116 && equali("deathrun_arctic", szMapName))

If check is completed - button ID matches and the currentmap is equal to some map I set do the code in the brackets.
All works.

But I have a few questions before do 40 checks for 40 maps.

1. Is there a better and more efficient way to do this ?
2. Is there a faster way to do this?
3. Will that make the server lag if there are hundreds of checks while pressing an button?


Eat that bacon :p --
Thanks in advance.
KaLoIaN is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 06-30-2016 , 14:29   Re: Ham_Use and Button id's (HELP)
Reply With Quote #2

Do the map check at plugin start, pause the plugin if the current map is not on the list.

EDIT: I don't know how (deathrun?) works, do you want to use an specific button ID? You could do the map and entity check at plugin start and then, if true, register Ham_Use to that specific button with RegisterHamFromEntity.
__________________

Last edited by gabuch2; 06-30-2016 at 14:36.
gabuch2 is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 06-30-2016 , 14:59   Re: Ham_Use and Button id's (HELP)
Reply With Quote #3

I will show you good way but i have question.

Do you want to check the same button on 40 maps (or more) or different buttons on different maps?

And if different buttons then every map will have single button or will have more than 1 button that will do userkill?
siriusmd99 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-30-2016 , 18:27   Re: Ham_Use and Button id's (HELP)
Reply With Quote #4

Take a look at this - https://forums.alliedmods.net/showthread.php?p=2423324
It allows you to mark buttons on the map and those buttons cannot be uses by CT players. No need to kill the player, simply block the button.

Last edited by OciXCrom; 06-30-2016 at 18:28.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 07-02-2016 , 03:08   Re: Ham_Use and Button id's (HELP)
Reply With Quote #5

Thanks for your replies.
First - the code user_kill I added was just an example
Second - the deathrun map was also just an example because the DR maps are more known (and they have buttons lol)

I want at every different map an single button when press it to show me an HUD for example.
It is not the same button on every map.. I don't know... I think the ent id should be different? But I want on every map one button when pressed execute the code in brackets - so yes : different buttons on different maps
So 40 maps = 40 checks and I want to know is there a better way. I just want to get know the method to do this.

Last edited by KaLoIaN; 07-02-2016 at 03:12.
KaLoIaN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-02-2016 , 07:00   Re: Ham_Use and Button id's (HELP)
Reply With Quote #6

Use the plugin that I gave you. It saves button IDs in a file depending on the mapname, so different map = different buttons. It uses only 1 check and not 40 maps = 40 checks. Just change this code to make it do something else rather than block its function:

PHP Code:
public eventUseButton(iEntid)
{
    if(
pev_valid(iEnt) && get_user_team(id) == SAFE_TEAM && pev(iEntpev_iuser2) != MARKED_BUTTON)
    {
        
ColorChat(id"%s %L"g_szPrefixLANG_PLAYER"CTSAFE_NOTALLOWED")
        
        
#if defined SOUND_CLICK
            
client_cmd(id"spk %s"SOUND_CLICK)
        
#endif
        
        
return HAM_SUPERCEDE
    
}
    
    return 
HAM_IGNORED

=>

PHP Code:
public eventUseButton(iEntid)
{
    if(
pev_valid(iEnt) && pev(iEntpev_iuser2) == MARKED_BUTTON)
    {
        
// this is one of your buttons, so do stuff here
        
set_hudmessage(...)
        
show_hudmessage(id, ...)
        
        return 
HAM_SUPERCEDE
        
// use HAM_SUPERCEDE to block the button's target after being used, or HAM_IGNORED for a normal handle
    
}
    
    return 
HAM_IGNORED


Last edited by OciXCrom; 07-02-2016 at 07:01.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-02-2016 , 08:26   Re: Ham_Use and Button id's (HELP)
Reply With Quote #7

I made it in the most efficient way.
You have a file dr_buttons.ini (you can change it's location in define) where you will write mapname and button id
Like this:

;Map Buttonid
deathrun_temple 134
deathrun_green 111

This is just an example , i don't know if these maps have buttons with id 134 or 111.


So it reads map and button from every line of the cofiguration file and it hooks "button use" only if current map has been found in the file and if button has been found on current map.
You also have amx_log for every case.

You can download config file and plugin down below.
Attached Files
File Type: ini dr_buttons.ini (178 Bytes, 247 views)
File Type: sma Get Plugin or Get Source (dr_buttons.sma - 887 views - 1.9 KB)
siriusmd99 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 07-02-2016 , 09:31   Re: Ham_Use and Button id's (HELP)
Reply With Quote #8

Quote:
Originally Posted by siriusmd99 View Post
I made it in the most efficient way.
You have a file dr_buttons.ini (you can change it's location in define) where you will write mapname and button id
Like this:

;Map Buttonid
deathrun_temple 134
deathrun_green 111

This is just an example , i don't know if these maps have buttons with id 134 or 111.


So it reads map and button from every line of the cofiguration file and it hooks "button use" only if current map has been found in the file and if button has been found on current map.
You also have amx_log for every case.

You can download config file and plugin down below.
Does not work. It writes that id 116 hasn't been found on the map. But in real it is there, I found it out with my plugin (in the first post).. And when press the button nothing happens.

This I've changed in your code:
Code:
public fwButtonUsed(ent, idcaller, idactivator, use_type, Float:value) {     new szPlayerName[32]     get_user_name(idactivator, szPlayerName, charsmax(szPlayerName))         ColorChat(idactivator, NORMAL, "%s", ent)         if(idcaller == idactivator && ent == g_Button)         ColorChat(idactivator, NORMAL, "^4[SERVER] ^1%s pressed an sweet button :D", szPlayerName[idactivator])         return HAM_IGNORED }

Last edited by KaLoIaN; 07-02-2016 at 09:32.
KaLoIaN is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-02-2016 , 09:57   Re: Ham_Use and Button id's (HELP)
Reply With Quote #9

Try this then:
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <engine>
#include <colorchat>

#define DR_BUTTONS_FILE "addons/amxmodx/configs/dr_buttons.ini" 

new g_Button;

public 
plugin_init()
{
    
register_plugin("Map Secret Button""1.0""siriusmd99");
    
    new 
pFile fopen(DR_BUTTONS_FILE"r");
    
    if(!
pFile)
    {
        
log_amx("[ Dr Buttons ]: File %s not found. Check your directory."DR_BUTTONS_FILE); 
        return 
PLUGIN_CONTINUE;
    }    
    
    new 
szCurrentMap[45];
    
get_mapname(szCurrentMapcharsmax(szCurrentMap));
    
    new 
szString[64], szMap[45], szButton[7];
    new 
iButton = -1;
    
    while( 
fgets(pFileszStringcharsmax(szString) ) )
    {
        if(
szString[0] == ';')
            continue;
        
        
trim(szString); 
        
parse(szString,szMap,charsmax(szMap),szButton,charsmax(szButton));
        
        if(
equali(szMapszCurrentMap))
        {
            
iButton str_to_num(szButton);
            break;
        }
    }    
    
    
fclose(pFile);
    
    if(
iButton == -1)
    { 
        
log_amx("[ Dr Buttons ]: Current Map (%s) hasn't been found in configuration file."szCurrentMap); 
        return 
PLUGIN_CONTINUE;
    }
    else
    {
        if(
iButton == 0)
        {
            
log_amx("[ Dr Buttons ]: Invalid Button - %s. Check your configuration file."szButton); 
            return 
PLUGIN_CONTINUE;
        }
    }
    
    new const 
CLASS_NAME[][] = { "func_button",  "func_rot_button""button_target" };
    new 
ient = -1;
    
    for(
0sizeof(CLASS_NAME); i++)
    {
        
        
ent = -1
        
while((ent find_ent_by_class(entCLASS_NAME[i])))
        {
            if(
ent == iButton)
            {
                
g_Button iButton;
                break;  
            }
        }        
    }
    
    if(!
g_Button)
    {
        
log_amx("[ Dr Buttons ]: Button %s hasn't been found on this map (%s)."szButtonszCurrentMap ); 
        return 
PLUGIN_CONTINUE;
    }
    
    
RegisterHam(Ham_UseCLASS_NAME[i], "fwButtonUsed");
    
    return 
PLUGIN_CONTINUE;
}

public 
fwButtonUsed(entidcalleridactivatoruse_typeFloat:value)
{
    if(
idcaller == idactivator && ent == g_Button)
    {     
        new 
szPlayerName[32]
        
get_user_name(idactivatorszPlayerNamecharsmax(szPlayerName))
        
ColorChat(0NORMAL"^4[SERVER] ^1%s pressed an sweet button :D"szPlayerName)
    }

Changed function which finds button by id.
siriusmd99 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 07-02-2016 , 10:04   Re: Ham_Use and Button id's (HELP)
Reply With Quote #10

I will try it and leave feedback.
In this code you provided - is it possible to :
1. add 3-4 buttons on 1 map
2. if 3-4 buttons can be added on 1 map is it possible show different hud for example at different maps?
KaLoIaN 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 11:16.


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