AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   removinq one entity of a kind while others remain (https://forums.alliedmods.net/showthread.php?t=114236)

Jack86 01-02-2010 21:49

removinq one entity of a kind while others remain
 
How could i remove this, to remove from map one specific entity and not to remove others that are identical, can i add some parameter upon its creation and find it later by it ?

Arkshine 01-03-2010 04:48

Re: removinq one entity of a kind while others remain
 
Is this entity has a field with a specific value ( pev_model, pev_classname, etc.. ) ? If not, yes, you can could as you said by storing a specific value in a field ( like pev_iuser* or what you want actually like classname too ; it's depending what is this entity )

Jack86 01-03-2010 07:02

Re: removinq one entity of a kind while others remain
 
Here's a code, i dont know what field can i use here at drop_kit and compare it later at kitremove. Also will 10 tasks at same time cause any extra load on server ?

PHP Code:


#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <fakemeta_util>

#define PLUGIN "Healthkit on dead body"
#define AUTHOR "tuty"
#define VERSION "3.0b"

#define MEDKIT_MINSZ Float:{ -23.160000, -13.660000, -0.050000 }
#define MEDKIT_MAXSZ Float:{ 11.470000, 12.780000, 6.720000 }
#define MODEL_KIT "models/w_medkit.mdl"
#define SOUND_KIT "items/smallmedkit1.wav" 
#define FFADE_IN 0x0000
#define MAX_KITS 10

new gKitCounter
new gToggleKitEnable;
new 
gToggleGlowShow;
new 
gGMsgFade;
new 
gToggleFadeEnable;
new 
gRemoveTime;
new 
gKitHealthCvar;
new 
gLimitHealthCvar;

new const 
gMedKitClassname[] = "medkit_entity";

public 
plugin_init()
{    
    
register_pluginPLUGINVERSIONAUTHOR );
    
register_cvar"kit_on_body"VERSIONFCVAR_SERVER FCVAR_SPONLY );
    
register_event"DeathMsg","drop_kit","a" );
    
register_touch("medkit_entity","player","touched");
    
    
gToggleKitEnable register_cvar"kit_enable""1" );
    
gToggleGlowShow register_cvar"kit_glow""0" );
    
gToggleFadeEnable register_cvar"kit_fade""1" );
    
gRemoveTime register_cvar"kit_remove""10.0" );
    
gKitHealthCvar register_cvar"kit_health""25" );
    
gLimitHealthCvar register_cvar"kit_limit_health""45" );
    
    
gGMsgFade get_user_msgid"ScreenFade" );
    
gKitCounter 0
}
public 
plugin_precache()
{
    
precache_modelMODEL_KIT );
    
precache_soundSOUND_KIT );
}
public 
drop_kit()
{
    new 
chance =random_num(0,2// 33% chance ??
    
if( get_pcvar_numgToggleKitEnable ) == || gKitCounter MAX_KITS || chance==)
    {
        return 
PLUGIN_HANDLED;
    }    
    
    new 
victim read_data);
    
    static 
Float:origin];
    
pevvictimpev_originorigin );
    
    new 
ent engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocString"info_target" ) );
    
origin] -= 36
    
engfuncEngFunc_SetOriginentorigin );
    
    if( !
pev_valident ) )
    {
        return 
PLUGIN_HANDLED;
    }
    
    
set_peventpev_classnamegMedKitClassname );
    
engfuncEngFunc_SetModelentMODEL_KIT );
    
dllfuncDLLFunc_Spawnent );
    
set_peventpev_solidSOLID_BBOX );
    
set_peventpev_movetypeMOVETYPE_NONE );
    
engfuncEngFunc_SetSizeentMEDKIT_MINSZMEDKIT_MAXSZ );
    
engfuncEngFunc_DropToFloorent );
    
gKitCounter++
    if( 
get_pcvar_numgToggleGlowShow ) == )
    {
        
fm_set_renderingentkRenderFxGlowShell255255255kRenderFxNone27 );
    }
    
set_task(get_pcvar_float(gRemoveTime),"kitremove")
    return 
PLUGIN_HANDLED;
}
public 
touchedentid )
{
    if( !
pev_valident ) || get_pcvar_numgToggleKitEnable ) == )
    {
        return 
FMRES_IGNORED;
    }
    
    new 
health get_user_healthid );
    new 
cvarhealth get_pcvar_numgKitHealthCvar );
    new 
maxhealth get_pcvar_numgLimitHealthCvar );
    
    if( 
health >= maxhealth )
    {
        
set_hudmessage25500, -1.00.8326.03.0 );
        
show_hudmessageid"You must have less then %d HP to take the kit."maxhealth );
        return 
FMRES_IGNORED;
    }

    
set_hudmessage25500, -1.00.8326.03.0 );
    
show_hudmessageid"You received %d HP"cvarhealth );
    
    
fm_set_user_healthidhealth cvarhealth );
    
emit_soundidCHAN_ITEMSOUND_KITVOL_NORMATTN_NORM ,PITCH_NORM );
    
    if( 
get_pcvar_numgToggleFadeEnable ) == )
    {
        
        
message_beginMSG_ONE_UNRELIABLEgGMsgFade , {0,0,0}, id );
        
write_short1<<10 );
        
write_short1<<10 );
        
write_shortFFADE_IN );
        
write_byte255 );
        
write_byte);
        
write_byte); 
        
write_byte75 );
        
message_end();
    }
    
engfuncEngFunc_RemoveEntityent );
    
gKitCounter--
    return 
FMRES_IGNORED;
}
public 
kitremove()
{
    new 
hkit FM_NULLENT;
    while ( ( 
hkit fm_find_ent_by_classhkitgMedKitClassname ) ) )
    {
        
engfuncEngFunc_RemoveEntityhkit )
        
gKitCounter--
    }
    



Arkshine 01-03-2010 07:27

Re: removinq one entity of a kind while others remain
 
You can use pev_iuser1 for example. This plugin is not well coded there is unnecessary code when you know that this entity exists in CS.

Jack86 01-03-2010 12:18

Re: removinq one entity of a kind while others remain
 
Quote:

This plugin is not well coded there is unnecessary code when you know that this entity exists in CS.
Could you tell me in more detail what to do, i dont know what part is bad.

I did this and it works

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <fakemeta_util>

#define PLUGIN "Healthkit on dead body"
#define AUTHOR "tuty"
#define VERSION "3.0b"

#define MEDKIT_MINSZ Float:{ -23.160000, -13.660000, -0.050000 }
#define MEDKIT_MAXSZ Float:{ 11.470000, 12.780000, 6.720000 }
#define MODEL_KIT "models/w_medkit.mdl"
#define SOUND_KIT "items/smallmedkit1.wav" 
#define FFADE_IN 0x0000
#define MAX_KITS 10

new gKitNumber
new gKitCounter
new gToggleKitEnable;
new 
gToggleGlowShow;
new 
gGMsgFade;
new 
gToggleFadeEnable;
new 
gRemoveTime;
new 
gKitHealthCvar;
new 
gLimitHealthCvar;

new const 
gMedKitClassname[] = "medkit_entity";

public 
plugin_init()
{    
    
register_pluginPLUGINVERSIONAUTHOR );
    
register_cvar"kit_on_body"VERSIONFCVAR_SERVER FCVAR_SPONLY );
    
register_event"DeathMsg","drop_kit","a" );
    
register_logevent"kitremove"2"1=Round_Start" );
    
register_touch("medkit_entity","player","touched");
    
    
gToggleKitEnable register_cvar"kit_enable""1" );
    
gToggleGlowShow register_cvar"kit_glow""0" );
    
gToggleFadeEnable register_cvar"kit_fade""1" );
    
gRemoveTime register_cvar"kit_remove""10.0" );
    
gKitHealthCvar register_cvar"kit_health""25" );
    
gLimitHealthCvar register_cvar"kit_limit_health""45" );
    
    
gGMsgFade get_user_msgid"ScreenFade" );
    
gKitCounter 1
    gKitNumber 
1
}
public 
plugin_precache()
{
    
precache_modelMODEL_KIT );
    
precache_soundSOUND_KIT );
}
public 
drop_kit()
{
    new 
chance =random_num(0,2)
    if( 
get_pcvar_numgToggleKitEnable ) == || gKitCounter MAX_KITS || chance==)
    {
        return 
PLUGIN_HANDLED;
    }    
    
    new 
victim read_data);
    
    static 
Float:origin];
    
pevvictimpev_originorigin );
    
    new 
ent engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocString"info_target" ) );
    
origin] -= 36
    
engfuncEngFunc_SetOriginentorigin );
    
    if( !
pev_valident ) )
    {
        return 
PLUGIN_HANDLED;
    }
    
    
set_peventpev_classnamegMedKitClassname );
    
engfuncEngFunc_SetModelentMODEL_KIT );
    
dllfuncDLLFunc_Spawnent );
    
set_peventpev_solidSOLID_BBOX );
    
set_peventpev_movetypeMOVETYPE_NONE );
    
engfuncEngFunc_SetSizeentMEDKIT_MINSZMEDKIT_MAXSZ );
    
engfuncEngFunc_DropToFloorent );
    
set_peventpev_iuser1gKitNumber )
    
set_task(get_pcvar_float(gRemoveTime),"kitremove",gKitNumber)
    
gKitNumber++
    
gKitCounter++
    if( 
get_pcvar_numgToggleGlowShow ) == )
    {
        
fm_set_renderingentkRenderFxGlowShell255255255kRenderFxNone27 );
    }
    
    return 
PLUGIN_HANDLED;
}
public 
touchedentid )
{
    if( !
pev_valident ) || get_pcvar_numgToggleKitEnable ) == )
    {
        return 
FMRES_IGNORED;
    }
    
    new 
health get_user_healthid );
    new 
cvarhealth get_pcvar_numgKitHealthCvar );
    new 
maxhealth get_pcvar_numgLimitHealthCvar );
    
    if( 
health >= maxhealth )
    {
        
set_hudmessage255255255, -1.00.8306.03.0 );
        
show_hudmessageid"You must have less then %d HP to take the kit."maxhealth );
        return 
FMRES_IGNORED;
    }

    
set_hudmessage255255255, -1.00.8306.03.0 );
    
show_hudmessageid"You received %d HP"cvarhealth );
    
    
fm_set_user_healthidhealth cvarhealth );
    
emit_soundidCHAN_ITEMSOUND_KITVOL_NORMATTN_NORM ,PITCH_NORM );
    
    if( 
get_pcvar_numgToggleFadeEnable ) == )
    {
        
        
message_beginMSG_ONE_UNRELIABLEgGMsgFade , {0,0,0}, id );
        
write_short1<<10 );
        
write_short1<<10 );
        
write_shortFFADE_IN );
        
write_byte255 );
        
write_byte);
        
write_byte); 
        
write_byte75 );
        
message_end();
    }
    
engfuncEngFunc_RemoveEntityent );
    new 
info pev(entpev_iuser1)
    
remove_task(info)
    
gKitCounter--
    return 
FMRES_IGNORED;
}
public 
kitremove(id)
{
    new 
hkit FM_NULLENT;
    while ( ( 
hkit fm_find_ent_by_classhkitgMedKitClassname ) ) )
    {
        new 
info pev(hkitpev_iuser1)
        if(
id == info)
        {
            
engfuncEngFunc_RemoveEntityhkit );
            
gKitCounter--
        }
    }
    


but then i read this tutorial http://forums.alliedmods.net/showthread.php?t=43049

and when i tried to do it like this nothing gets removed, what am i doing wrong ?

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <fakemeta_util>

#define PLUGIN "Healthkit on dead body"
#define AUTHOR "tuty"
#define VERSION "3.0b"

#define MEDKIT_MINSZ Float:{ -23.160000, -13.660000, -0.050000 }
#define MEDKIT_MAXSZ Float:{ 11.470000, 12.780000, 6.720000 }
#define MODEL_KIT "models/w_medkit.mdl"
#define SOUND_KIT "items/smallmedkit1.wav" 
#define FFADE_IN 0x0000
#define MAX_KITS 10

new gKitCounter
new gToggleKitEnable;
new 
gToggleGlowShow;
new 
gGMsgFade;
new 
gToggleFadeEnable;
new 
gRemoveTime;
new 
gKitHealthCvar;
new 
gLimitHealthCvar;

new const 
gMedKitClassname[] = "medkit_entity";

public 
plugin_init()
{    
    
register_pluginPLUGINVERSIONAUTHOR );
    
register_cvar"kit_on_body"VERSIONFCVAR_SERVER FCVAR_SPONLY );
    
register_event"DeathMsg","drop_kit","a" );
    
register_logevent"kitremove"2"1=Round_Start" );
    
register_touch("medkit_entity","player","touched");
    
register_think(gMedKitClassname,"kitremove")

    
    
gToggleKitEnable register_cvar"kit_enable""1" );
    
gToggleGlowShow register_cvar"kit_glow""0" );
    
gToggleFadeEnable register_cvar"kit_fade""1" );
    
gRemoveTime register_cvar"kit_remove""10.0" );
    
gKitHealthCvar register_cvar"kit_health""25" );
    
gLimitHealthCvar register_cvar"kit_limit_health""45" );
    
    
gGMsgFade get_user_msgid"ScreenFade" );
    
gKitCounter 1
}
public 
plugin_precache()
{
    
precache_modelMODEL_KIT );
    
precache_soundSOUND_KIT );
}
public 
drop_kit()
{
    new 
chance =random_num(0,2)
    if( 
get_pcvar_numgToggleKitEnable ) == || gKitCounter MAX_KITS || chance==)
    {
        return 
PLUGIN_HANDLED;
    }    
    
    new 
victim read_data);
    
    static 
Float:origin];
    
pevvictimpev_originorigin );
    
    new 
ent engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocString"info_target" ) );
    
origin] -= 36
    
engfuncEngFunc_SetOriginentorigin );
    
    if( !
pev_valident ) )
    {
        return 
PLUGIN_HANDLED;
    }
    
    
set_peventpev_classnamegMedKitClassname );
    
engfuncEngFunc_SetModelentMODEL_KIT );
    
dllfuncDLLFunc_Spawnent );
    
set_peventpev_solidSOLID_BBOX );
    
set_peventpev_movetypeMOVETYPE_NONE );
    
engfuncEngFunc_SetSizeentMEDKIT_MINSZMEDKIT_MAXSZ );
    
engfuncEngFunc_DropToFloorent )
    
    static 
Floats_glbtime
    global_get
(glb_times_glbtime)
    
set_pev(ent ,pev_nextthinks_glbtime get_pcvar_float(gRemoveTime))
    
gKitCounter++
    
    if( 
get_pcvar_numgToggleGlowShow ) == )
    {
        
fm_set_renderingentkRenderFxGlowShell255255255kRenderFxNone27 );
    }
    
    return 
PLUGIN_HANDLED;
}
public 
touchedentid )
{
    if( !
pev_valident ) || get_pcvar_numgToggleKitEnable ) == )
    {
        return 
FMRES_IGNORED;
    }
    
    new 
health get_user_healthid );
    new 
cvarhealth get_pcvar_numgKitHealthCvar );
    new 
maxhealth get_pcvar_numgLimitHealthCvar );
    
    if( 
health >= maxhealth )
    {
        
set_hudmessage255255255, -1.00.8306.03.0 );
        
show_hudmessageid"You must have less then %d HP to take the kit."maxhealth );
        return 
FMRES_IGNORED;
    }

    
set_hudmessage255255255, -1.00.8306.03.0 );
    
show_hudmessageid"You received %d HP"cvarhealth );
    
    
fm_set_user_healthidhealth cvarhealth );
    
emit_soundidCHAN_ITEMSOUND_KITVOL_NORMATTN_NORM ,PITCH_NORM );
    
    if( 
get_pcvar_numgToggleFadeEnable ) == )
    {
        
        
message_beginMSG_ONE_UNRELIABLEgGMsgFade , {0,0,0}, id );
        
write_short1<<10 );
        
write_short1<<10 );
        
write_shortFFADE_IN );
        
write_byte255 );
        
write_byte);
        
write_byte); 
        
write_byte75 );
        
message_end();
    }
    
engfuncEngFunc_RemoveEntityent );
    
gKitCounter--
    return 
FMRES_IGNORED;
}
public 
kitremove(hkit)
{
    
hkit FM_NULLENT;
    
engfuncEngFunc_RemoveEntityhkit );
    
gKitCounter--



Arkshine 01-03-2010 13:45

Re: removinq one entity of a kind while others remain
 
I understand what you are trying to do.
Let me do a simplified version.

Mxnn 01-03-2010 14:03

Re: removinq one entity of a kind while others remain
 
I delete a entity with this method:
PHP Code:

remove_entity(find_ent_by_class(-1"name"

In this case name will be gMedKitClassname

EDIT: I have a question.. Which kind of data saves "ent" ?
Because i have 1 function for 3 touchs and i need to know which package was touched but i don't know how to know it :(

Jack86 01-03-2010 14:06

Re: removinq one entity of a kind while others remain
 
@Arkshine
Go ahead, all i can say is tyvm, ur very helpfull.

Arkshine 01-05-2010 09:31

Re: removinq one entity of a kind while others remain
 
What features you want to see ?
Just to know. I've finished a code so maybe you want to add something.

Jack86 01-05-2010 20:51

Re: removinq one entity of a kind while others remain
 
Yay , i thought u forgot :D. No special features are needed, just to work like i tried above.


All times are GMT -4. The time now is 04:02.

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