|
Veteran Member
Join Date: Dec 2008
Location: Belgrade, Serbia
|

01-03-2010
, 12:18
Re: removinq one entity of a kind while others remain
|
#5
|
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_plugin( PLUGIN, VERSION, AUTHOR ); register_cvar( "kit_on_body", VERSION, FCVAR_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_model( MODEL_KIT ); precache_sound( SOUND_KIT ); } public drop_kit() { new chance =random_num(0,2) if( get_pcvar_num( gToggleKitEnable ) == 0 || gKitCounter > MAX_KITS || chance==1 ) { return PLUGIN_HANDLED; } new victim = read_data( 2 ); static Float:origin[ 3 ]; pev( victim, pev_origin, origin ); new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) ); origin[ 2 ] -= 36; engfunc( EngFunc_SetOrigin, ent, origin ); if( !pev_valid( ent ) ) { return PLUGIN_HANDLED; } set_pev( ent, pev_classname, gMedKitClassname ); engfunc( EngFunc_SetModel, ent, MODEL_KIT ); dllfunc( DLLFunc_Spawn, ent ); set_pev( ent, pev_solid, SOLID_BBOX ); set_pev( ent, pev_movetype, MOVETYPE_NONE ); engfunc( EngFunc_SetSize, ent, MEDKIT_MINSZ, MEDKIT_MAXSZ ); engfunc( EngFunc_DropToFloor, ent ); set_pev( ent, pev_iuser1, gKitNumber ) set_task(get_pcvar_float(gRemoveTime),"kitremove",gKitNumber) gKitNumber++ gKitCounter++ if( get_pcvar_num( gToggleGlowShow ) == 1 ) { fm_set_rendering( ent, kRenderFxGlowShell, 255, 255, 255, kRenderFxNone, 27 ); } return PLUGIN_HANDLED; } public touched( ent, id ) { if( !pev_valid( ent ) || get_pcvar_num( gToggleKitEnable ) == 0 ) { return FMRES_IGNORED; } new health = get_user_health( id ); new cvarhealth = get_pcvar_num( gKitHealthCvar ); new maxhealth = get_pcvar_num( gLimitHealthCvar ); if( health >= maxhealth ) { set_hudmessage( 255, 255, 255, -1.0, 0.83, 0, 6.0, 3.0 ); show_hudmessage( id, "You must have less then %d HP to take the kit.", maxhealth ); return FMRES_IGNORED; }
set_hudmessage( 255, 255, 255, -1.0, 0.83, 0, 6.0, 3.0 ); show_hudmessage( id, "You received %d HP", cvarhealth ); fm_set_user_health( id, health + cvarhealth ); emit_sound( id, CHAN_ITEM, SOUND_KIT, VOL_NORM, ATTN_NORM ,0 , PITCH_NORM ); if( get_pcvar_num( gToggleFadeEnable ) == 1 ) { message_begin( MSG_ONE_UNRELIABLE, gGMsgFade , {0,0,0}, id ); write_short( 1<<10 ); write_short( 1<<10 ); write_short( FFADE_IN ); write_byte( 255 ); write_byte( 0 ); write_byte( 0 ); write_byte( 75 ); message_end(); } engfunc( EngFunc_RemoveEntity, ent ); new info = pev(ent, pev_iuser1) remove_task(info) gKitCounter-- return FMRES_IGNORED; } public kitremove(id) { new hkit = FM_NULLENT; while ( ( hkit = fm_find_ent_by_class( hkit, gMedKitClassname ) ) ) { new info = pev(hkit, pev_iuser1) if(id == info) { engfunc( EngFunc_RemoveEntity, hkit ); 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_plugin( PLUGIN, VERSION, AUTHOR ); register_cvar( "kit_on_body", VERSION, FCVAR_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_model( MODEL_KIT ); precache_sound( SOUND_KIT ); } public drop_kit() { new chance =random_num(0,2) if( get_pcvar_num( gToggleKitEnable ) == 0 || gKitCounter > MAX_KITS || chance==1 ) { return PLUGIN_HANDLED; } new victim = read_data( 2 ); static Float:origin[ 3 ]; pev( victim, pev_origin, origin ); new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) ); origin[ 2 ] -= 36; engfunc( EngFunc_SetOrigin, ent, origin ); if( !pev_valid( ent ) ) { return PLUGIN_HANDLED; } set_pev( ent, pev_classname, gMedKitClassname ); engfunc( EngFunc_SetModel, ent, MODEL_KIT ); dllfunc( DLLFunc_Spawn, ent ); set_pev( ent, pev_solid, SOLID_BBOX ); set_pev( ent, pev_movetype, MOVETYPE_NONE ); engfunc( EngFunc_SetSize, ent, MEDKIT_MINSZ, MEDKIT_MAXSZ ); engfunc( EngFunc_DropToFloor, ent ) static Float: s_glbtime global_get(glb_time, s_glbtime) set_pev(ent ,pev_nextthink, s_glbtime + get_pcvar_float(gRemoveTime)) gKitCounter++ if( get_pcvar_num( gToggleGlowShow ) == 1 ) { fm_set_rendering( ent, kRenderFxGlowShell, 255, 255, 255, kRenderFxNone, 27 ); } return PLUGIN_HANDLED; } public touched( ent, id ) { if( !pev_valid( ent ) || get_pcvar_num( gToggleKitEnable ) == 0 ) { return FMRES_IGNORED; } new health = get_user_health( id ); new cvarhealth = get_pcvar_num( gKitHealthCvar ); new maxhealth = get_pcvar_num( gLimitHealthCvar ); if( health >= maxhealth ) { set_hudmessage( 255, 255, 255, -1.0, 0.83, 0, 6.0, 3.0 ); show_hudmessage( id, "You must have less then %d HP to take the kit.", maxhealth ); return FMRES_IGNORED; }
set_hudmessage( 255, 255, 255, -1.0, 0.83, 0, 6.0, 3.0 ); show_hudmessage( id, "You received %d HP", cvarhealth ); fm_set_user_health( id, health + cvarhealth ); emit_sound( id, CHAN_ITEM, SOUND_KIT, VOL_NORM, ATTN_NORM ,0 , PITCH_NORM ); if( get_pcvar_num( gToggleFadeEnable ) == 1 ) { message_begin( MSG_ONE_UNRELIABLE, gGMsgFade , {0,0,0}, id ); write_short( 1<<10 ); write_short( 1<<10 ); write_short( FFADE_IN ); write_byte( 255 ); write_byte( 0 ); write_byte( 0 ); write_byte( 75 ); message_end(); } engfunc( EngFunc_RemoveEntity, ent ); gKitCounter-- return FMRES_IGNORED; } public kitremove(hkit) { hkit = FM_NULLENT; engfunc( EngFunc_RemoveEntity, hkit ); gKitCounter-- }
__________________

|
|