Raised This Month: $ Target: $400
 0% 

automatically start a random button


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pillowCloud
Member
Join Date: Aug 2015
Location: AlliedModders
Old 03-05-2016 , 06:05   automatically start a random button
Reply With Quote #1

I'm looking for a way to start a random button from the all buttons that exist in map.

for example: If this a deathrun mod, so traps will be started automatically by their buttons.

Thanks in advance
pillowCloud is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-05-2016 , 06:37   Re: automatically start a random button
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Use Random Button"
#define VERSION "1.0.0"
#define AUTHOR "KliPPy"


new Array: g_aButtons;
new 
g_iButtonsCount;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_aButtons ArrayCreate();
    
g_iButtonsCount FindAllButtons();
    
    
register_clcmd("say !randombutton""Cmd_Say_randombutton");
}

FindAllButtons() {
#if AMXX_VERSION_NUM < 183
    
new iEnt get_maxplayers() + 1;
#else
    
new iEnt MaxClients 1;
#endif
    
while((iEnt engfunc(EngFunc_FindEntityByStringiEnt"classname""func_button")) > 0) {
        
ArrayPushCell(g_aButtonsiEnt);
    }
    
    return 
ArraySize(g_aButtons);
}

public 
Cmd_Say_randombutton() {
     new 
iEnt ArrayGetCell(g_aButtonsrandom(g_iButtonsCount));
     if(
pev_valid(iEnt)) {
         
dllfunc(DLLFunc_UseiEnt0);
     }

This plugin will let a player write "!randombutton" in chat and will activate a random button on the map. Tested and works fine.
I made it like so because you didn't explain it good enough what you need. When do you need buttons to activate? All of them or just one of them? Et cetera...
klippy is offline
pillowCloud
Member
Join Date: Aug 2015
Location: AlliedModders
Old 03-05-2016 , 06:47   Re: automatically start a random button
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
PHP Code:
#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Use Random Button"
#define VERSION "1.0.0"
#define AUTHOR "KliPPy"


new Array: g_aButtons;
new 
g_iButtonsCount;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_aButtons ArrayCreate();
    
g_iButtonsCount FindAllButtons();
    
    
register_clcmd("say !randombutton""Cmd_Say_randombutton");
}

FindAllButtons() {
#if AMXX_VERSION_NUM < 183
    
new iEnt get_maxplayers() + 1;
#else
    
new iEnt MaxClients 1;
#endif
    
while((iEnt engfunc(EngFunc_FindEntityByStringiEnt"classname""func_button")) > 0) {
        
ArrayPushCell(g_aButtonsiEnt);
    }
    
    return 
ArraySize(g_aButtons);
}

public 
Cmd_Say_randombutton() {
     new 
iEnt ArrayGetCell(g_aButtonsrandom(g_iButtonsCount));
     if(
pev_valid(iEnt)) {
         
dllfunc(DLLFunc_UseiEnt0);
     }

This plugin will let a player write "!randombutton" in chat and will activate a random button on the map. Tested and works fine.
I made it like so because you didn't explain it good enough what you need. When do you need buttons to activate? All of them or just one of them? Et cetera...
That's just what i needed.

Thank you very very much!

edit:
I'm experiencing problem when the func_button is tied to a camera.
when it do, the players gets the camera view.

there is any possibility to fix this?

Thanks again.

Last edited by pillowCloud; 03-07-2016 at 19:36.
pillowCloud is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-08-2016 , 04:08   Re: automatically start a random button
Reply With Quote #4

Try this one. Untested, but I guess it should work. It should ignore triggering of any "trigger_camera" that's been triggered by a randomly used button.

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "Use Random Button"
#define VERSION "1.0.0"
#define AUTHOR "KliPPy"


new Array: g_aButtons;
new 
g_iButtonsCount;
new 
g_iButtonInUse;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_aButtons ArrayCreate();
    
g_iButtonsCount FindAllButtons();
    
    
RegisterHam(Ham_Use"trigger_camera""TriggerCamera_Use"false);
    
    
register_clcmd("say !randombutton""Cmd_Say_randombutton");
}

FindAllButtons() {
#if AMXX_VERSION_NUM < 183
    
new iEnt get_maxplayers() + 1;
#else
    
new iEnt MaxClients 1;
#endif

    
while((iEnt engfunc(EngFunc_FindEntityByStringiEnt"classname""func_button")) > 0) {
        if(
pev_valid(iEnt)) {
            
ArrayPushCell(g_aButtonsiEnt);
        }
    }
    
    return 
ArraySize(g_aButtons);
}

// iActivator - one that triggered the chain
// iCaller - previous one in the chain
public TriggerCamera_Use(thisiActivatoriCalleriUseTypeFloatfValue) {
    if(
iActivator == g_iButtonInUse) {
        return 
HAM_SUPERCEDE;
    }
    
    return 
HAM_IGNORED;
}

public 
Cmd_Say_randombutton() {
    new 
iEnt ArrayGetCell(g_aButtonsrandom(g_iButtonsCount));
     
    if(
pev_valid(iEnt)) {
        
g_iButtonInUse iEnt;
        
dllfunc(DLLFunc_UseiEntiEnt);
        
g_iButtonInUse FM_NULLENT;
    }
    


Last edited by klippy; 03-08-2016 at 04:10.
klippy is offline
pillowCloud
Member
Join Date: Aug 2015
Location: AlliedModders
Old 03-25-2016 , 14:24   Re: automatically start a random button
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
Try this one. Untested, but I guess it should work. It should ignore triggering of any "trigger_camera" that's been triggered by a randomly used button.

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "Use Random Button"
#define VERSION "1.0.0"
#define AUTHOR "KliPPy"


new Array: g_aButtons;
new 
g_iButtonsCount;
new 
g_iButtonInUse;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_aButtons ArrayCreate();
    
g_iButtonsCount FindAllButtons();
    
    
RegisterHam(Ham_Use"trigger_camera""TriggerCamera_Use"false);
    
    
register_clcmd("say !randombutton""Cmd_Say_randombutton");
}

FindAllButtons() {
#if AMXX_VERSION_NUM < 183
    
new iEnt get_maxplayers() + 1;
#else
    
new iEnt MaxClients 1;
#endif

    
while((iEnt engfunc(EngFunc_FindEntityByStringiEnt"classname""func_button")) > 0) {
        if(
pev_valid(iEnt)) {
            
ArrayPushCell(g_aButtonsiEnt);
        }
    }
    
    return 
ArraySize(g_aButtons);
}

// iActivator - one that triggered the chain
// iCaller - previous one in the chain
public TriggerCamera_Use(thisiActivatoriCalleriUseTypeFloatfValue) {
    if(
iActivator == g_iButtonInUse) {
        return 
HAM_SUPERCEDE;
    }
    
    return 
HAM_IGNORED;
}

public 
Cmd_Say_randombutton() {
    new 
iEnt ArrayGetCell(g_aButtonsrandom(g_iButtonsCount));
     
    if(
pev_valid(iEnt)) {
        
g_iButtonInUse iEnt;
        
dllfunc(DLLFunc_UseiEntiEnt);
        
g_iButtonInUse FM_NULLENT;
    }
    

Thank you so much!!
I saw many ppl saying +Karma
so, +Karma
pillowCloud 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 10:56.


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