AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Delete trigger (https://forums.alliedmods.net/showthread.php?t=184211)

RapZzw3rR 05-02-2012 09:04

Delete trigger
 
I want to know if I can delete the triggers.
If yes, how?

Liverwiz 05-02-2012 09:11

Re: Delete trigger
 
You can block a trigger's hook from executing. But it really depends on what you're trying to do.

Can you elaborate?

RapZzw3rR 05-02-2012 09:21

Re: Delete trigger
 
Trivial example:
Command "say /zones" will create some triggers and command "say /removezones" will delete these triggers.

But I want to create a plugin wherewith I can detected where is some player. (If some player type in chat "/where" the triggers will be created, will be show some message in chat with player's position and I want after to delete triggers because the map will be full with triggers and the server will be lagged.)

Liverwiz 05-02-2012 10:02

Re: Delete trigger
 
I would say it is very dangerous to make a trigger volitile like that. Might i suggest using a toggle of some sort; turning off the trigger when you want it "disabled." The triggers that are created within the source are going to be there, weather enabled or not. Also: once the map changes all triggers will be deleted because AMXX isn't persistent, unless done through a file. If you're that worried about lag from users creating so many triggers...i'd suggest only allowing a single user to create so many (1 or 2) that way you'd have a max of 64.

But then again.....i'm just spurting crap. I don't know exactly what you'er trying to do. Code might help me.

RapZzw3rR 05-02-2012 10:46

Re: Delete trigger
 
Here I created two small zones for tests..
PHP Code:

#include <amxmodx>
#include <engine>
#include <ColorChat>

#define PLUGIN "HNS Where"
#define VERSION "1.0"
#define MAX_ZONES 2
#define MAX_SOUNDS 1
#pragma semicolon 1

new bool:RoofMap false;

new 
bool:Sound[33];
new 
bool:Message[33];

new 
cvar_tag;

static const 
Where_Ent[] = "trigger_where";

new const 
FloatMins[MAX_ZONES][3] =
{
    {-
445.2386.71025.0},
    {-
477.7, -1112.5641.5}
};

new const 
FloatMaxs[MAX_ZONES][3] =
{
    {-
323.2444.71027.0},
    {-
455.7, -1090.5643.5}
};

new const 
Types[MAX_ZONES] =
{
     
12
};

new const 
Messages[MAX_ZONES+1][] =
{
    
"",
    
"Boxes, pop dog",
    
"Box, umbrellas"
};

public 
plugin_precache()
{
    new 
mapName[33];
    
get_mapname(mapName32);
    
    if(!
equali(mapName"awp_rooftops"12) || equali(mapName"awp_rooftops_remake"19))
    {
        
RoofMap false;
    }
    else
    
RoofMap true;
}

public 
plugin_init()
{
    if(!
RoofMap)
    {
        new 
pluginName[33];
        
format(pluginName32"%s dezactivated"PLUGIN);
        
register_plugin(pluginNameVERSION"Rap");
        
pause("ade");
    }
    else if(
RoofMap)
    {
        
register_plugin(PLUGINVERSION"Rap");
        
register_clcmd"say""hook_say" );
        
register_touch(Where_Ent"player""FwdTriggerTouch");
        
register_concmd("amx_where""cmdWhere"ADMIN_ALL"<name>");
        
cvar_tag register_cvar("where_tag""[Where]");
    }
}

public 
CreateWhereZones()
{
    for (new 
0MAX_ZONESi++)
    {
        
CreateTrigger(Types[i], Mins[i], Maxs[i]);
    }
}

CreateTrigger(const EntType, const Float:flMins[3], const Float:flMaxs[3])
{
    new 
iEntity create_entity("info_target");
    
    if(!
is_valid_ent(iEntity))
    {
        return 
0;
    }
    
    
entity_set_string(iEntityEV_SZ_classnameWhere_Ent);
    
entity_set_int(iEntityEV_INT_iuser1EntType);
    
entity_set_int(iEntityEV_INT_movetypeMOVETYPE_NONE);
    
entity_set_int(iEntityEV_INT_solidSOLID_TRIGGER);
    
entity_set_size(iEntityflMinsflMaxs);
    
    return 
iEntity;
}

public 
DeleteWhereZones()
{
    
//HERE I REALLY NEED HELP!
    //HERE I REALLY NEED HELP!
    //HERE I REALLY NEED HELP!
    //HERE I REALLY NEED HELP!
}

public 
WhereMenu(id)
{
    new 
WhereMenuMsg[64];
    
formatex(WhereMenuMsg63"\rHide'N'Seek Where");
    new 
MenuWhere menu_create(WhereMenuMsg"WhereMenuHandler"0);
    
    new 
wheremsg[64], wheresound[64];
    
formatex(wheremsg63"\yMessages: %s"Message[id] ? "\w Activated" "\d Dezactivated");
    
formatex(wheresound63"\ySounds: %s"Sound[id] ? "\w Activated" "\d Dezactivated");
    
    
menu_additem(MenuWherewheremsg"1"0);
    
menu_additem(MenuWherewheresound"2"0);
    
    
    
menu_setprop(MenuWhereMPROP_EXITNAME"\yExit");
    
menu_display(idMenuWhere0);
    
    return 
1;
}

public 
WhereMenuHandler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        return 
1;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key) {
        case 
1: {
            
WhereMsg(id);
            
WhereMenu(id);
        }
        case 
2: {
            
WhereSound(id);
            
WhereMenu(id);
        }
    }
    
    return 
1;
}

public 
WhereMsg(id)
{
    new 
tag[32];
    
get_pcvar_string(cvar_tagtagsizeof(tag) -1);
    
    if(
Message[id])
    {
        
Message[id] = false;
        
ColorChat(idRED"^x04%s^x01 The messages are now^x03 dezactivated^x01!"tag);
        return 
PLUGIN_HANDLED;
    }
    else if(!
Message[id])
    {
        
Message[id] = true;
        
ColorChat(idBLUE"^x04%s^x01 The messages are now^x03 activated^x01!"tag);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_HANDLED;
}

public 
WhereSound(id)
{
    new 
tag[32];
    
get_pcvar_string(cvar_tagtagsizeof(tag) -1);
    
    if(
Sound[id])
    {
        
Sound[id] = false;
        
ColorChat(idRED"^x04%s^x01 The sounds are now^x03 dezactivated^x01!"tag);
        return 
PLUGIN_HANDLED;
    }
    else if(!
Sound[id])
    {
        
Sound[id] = true;
        
ColorChat(idBLUE"^x04%s^x01 The sounds are now^x03 activated^x01!"tag);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_HANDLED;
}

public 
FwdTriggerTouch(const iEntity, const id)
{
    if(
is_user_ok(id))
    {
        static 
Type;
        
Type entity_get_int(iEntityEV_INT_iuser1);
        
        new 
Players[32], name[32], tag[32];
        new 
PlayersNumplayer;
        
        
get_pcvar_string(cvar_tagtagsizeof(tag) -1);
        
get_user_name(idnamesizeof(name) - 1);
    
        
get_players(PlayersPlayersNum"ch");        
        for(new 
i=0i<PlayersNumi++)
        {
            
player Players[i];
            if(
Message[player])
            {
                
ColorChat(playerRED"^x04%s^x03 %s^x01 is now[^x04 %s^x01]!",tagnameMessages[Type]);
            }
            if(
Sound[player])
            {
                
client_cmd(player,"spk vox/doop");
            }
        }
        
DeleteWhereZones();
    }
    return 
0;
}

public 
cmdWhere(id)
{
    
CreateWhereZones();
    return 
1;
}

public 
hook_say(id)
{
    static 
args[192], command[192];
    
read_args(args,charsmax(args));
    
    if(!
args[0]) {
        return 
PLUGIN_CONTINUE;
    }    
    
remove_quotes(args[0]);
    if(
equal(args"/where"strlen("/where")))
    {
        
replace(args,charsmax(args), "/""" );
        
formatexcommandcharsmax(command) , "amx_%s"args );
        
client_cmd(idcommand);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

stock is_user_ok(id)
{
    if(
is_user_alive(id) && is_user_connected(id) && !is_user_bot(id))
        return 
1;
        
    return 
0;



Liverwiz 05-02-2012 11:30

Re: Delete trigger
 
Code:

public DeleteWhereZones()
{
    remove_entity("info_target");
}

Maybe?

There are way more elegant ways to write this. You should think about re-doing it. Most noteably....you can compress a lot of your many functions into one. And remove plugin_prechace; putting that functionality into plugin_init. I'm gonna be honest....that code confused the hell out of me.

<VeCo> 05-02-2012 11:31

Re: Delete trigger
 
It should be
PHP Code:

remove_entity_name("trigger_where"


Liverwiz 05-02-2012 11:36

Re: Delete trigger
 
Quote:

Originally Posted by <VeCo> (Post 1700492)
It should be
PHP Code:

remove_entity_name("trigger_where"


So it should....my mistake.

Might i also suggest dabbeling in hamsandwich. It offers a LOT of functionality for entities.

RapZzw3rR 05-02-2012 12:14

Re: Delete trigger
 
In scripting I'm noob and I don't know lot ways to write a script.
Thanks for all, and Liverwiz, only if you want, you can tell me what you don't like in my script excluding plugin_precache and what would you do in my place?
And again thanks.

Devil259 05-02-2012 18:41

Re: Delete trigger
 
PHP Code:

new const szTrigger[ ] = "trigger_where";
new 
iEnt = -1;
while( ( 
iEnt find_ent_by_class( -1szTrigger ) ) > )
{
    
remove_entityiEnt );




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

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