Raised This Month: $ Target: $400
 0% 

how to trigger an entity which has defined targetname ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
elle
Member
Join Date: Feb 2011
Old 05-07-2012 , 22:43   how to trigger an entity which has defined targetname ?
Reply With Quote #1

how to trigger an entity which has the targetname which defined ?

(or if anyone knows any other way without using amxx , please tell me)


Like in de_maps ,when the bomb exploded ,it triggers the entity
(without any plugin needed )

Code:
{
"model" "*2"
"target" "targeta"
"classname" "func_bomb_target"
}

For example i want to add command to this plugin that when vip escapes , the entity name "targeta" will be triggered


Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#define PLUGIN_NAME "VIP Alternative"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "VEN"
new CVAR_NAME[] = "varmor"
#define CVAR_DEFAULT "100"
#define BIT_ICON_NORMAL (1<<0)
#define BIT_ICON_BLINK (1<<1)
#define BIT_ICON BIT_ICON_NORMAL
#define ICON_R 0
#define ICON_G 0
#define ICON_B 255
#define OFFSET_VIP_32BIT 209
#define OFFSET_VIP_64BIT 242
#define OFFSET_VIP_LINUXDIFF 5
#define BIT_VIP (1<<8)
#if !defined PROCESSOR_TYPE
#if cellbits == 32
#define OFFSET_VIP OFFSET_VIP_32BIT
#else
#define OFFSET_VIP OFFSET_VIP_64BIT
#endif
#else
#if PROCESSOR_TYPE == 0
#define OFFSET_VIP OFFSET_VIP_32BIT
#else
#define OFFSET_VIP OFFSET_VIP_64BIT
#endif
#endif
#define CVAR_POINTERS_AMXX_INIT_VER_NUM 170
#if defined AMXX_VERSION_NUM && AMXX_VERSION_NUM >= CVAR_POINTERS_AMXX_INIT_VER_NUM
#define CVAR_POINTERS
new g_cvar_pointer
#endif
new ICON_NAME[] = "vipsafety"
#define BIT_CENTER_TEXT (1<<2)
new MESSAGE_TEXT[] = "#Cannot_Switch_From_VIP"
new g_msgid_icon
new g_msgid_text
new g_vip_id
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
#if defined CVAR_POINTERS
g_cvar_pointer = register_cvar(CVAR_NAME, CVAR_DEFAULT)
#else
register_cvar(CVAR_NAME, CVAR_DEFAULT)
#endif
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
register_event("ResetHUD", "event_hud_reset", "be")
register_event("StatusIcon", "event_vip_safety", "be", "1=1", "2=vipsafety")
#if defined BIT_ICON
register_event("DeathMsg", "event_death", "a", "2!0")
#endif
register_clcmd("fullupdate", "clcmd_fullupdate")
register_clcmd("chooseteam", "clcmd_role_switch")
register_clcmd("jointeam", "clcmd_role_switch")
g_msgid_icon = get_user_msgid("StatusIcon")
g_msgid_text = get_user_msgid("TextMsg")
}
public event_new_round() {
if (!g_vip_id || !is_user_connected(g_vip_id))
return
new tchar[2]
get_user_team(g_vip_id, tchar, 1)
if (tchar[0] != 'C') {
g_vip_id = 0
return
}
set_player_vip(g_vip_id)
if (get_cvar_value() < 0)
g_vip_id = 0
}
public event_hud_reset(id) {
set_task(0.1, "task_vip_alteration", id)
}
public task_vip_alteration(id) {
if (is_user_alive(id) && set_player_vip(id, false)) {
g_vip_id = id
set_user_health (id, 200)
#if defined BIT_ICON
msg_vip_icon(id)
#endif
}
}
public client_disconnect(id) {
if (id == g_vip_id && !is_player_vip(id)) {
set_player_vip(id)
g_vip_id = 0
}
}
public event_vip_safety(id) {
if (id == g_vip_id)
set_player_vip(id)
}
public event_death() {
new id = read_data(2)
if (id == g_vip_id)
msg_vip_icon(id, false)
}
public clcmd_role_switch(id) {
if (id != g_vip_id)
return PLUGIN_CONTINUE
msg_cant_switch_roles(id)
return PLUGIN_HANDLED
}
public clcmd_fullupdate() {
return PLUGIN_HANDLED
}
stock get_cvar_value() {
#if defined CVAR_POINTERS
return get_pcvar_num(g_cvar_pointer)
#else
return get_cvar_num(CVAR_NAME)
#endif
}
stock is_player_vip(id) {
return (get_pdata_int(id, OFFSET_VIP, OFFSET_VIP_LINUXDIFF) & BIT_VIP)
}
stock bool:set_player_vip(id, bool:vip = true) {
new oldbits = get_pdata_int(id, OFFSET_VIP, OFFSET_VIP_LINUXDIFF)
if (!vip && !(oldbits & BIT_VIP))
return false
new newbits
switch (vip) {
case true : newbits = (oldbits | BIT_VIP)
case false: newbits = (oldbits & ~BIT_VIP)
}
set_pdata_int(id, OFFSET_VIP, newbits, OFFSET_VIP_LINUXDIFF)
return true
}
stock msg_vip_icon(id, bool:show = true) {
message_begin(MSG_ONE, g_msgid_icon, {0, 0, 0}, id)
write_byte((show ? BIT_ICON : 0))
write_string(ICON_NAME)
if (show) {
write_byte(ICON_R)
write_byte(ICON_G)
write_byte(ICON_B)
}
message_end()
}
stock msg_cant_switch_roles(id) {
message_begin(MSG_ONE, g_msgid_text, {0, 0, 0}, id)
write_byte(BIT_CENTER_TEXT)
write_string(MESSAGE_TEXT)
message_end()
}
thanks
elle is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-07-2012 , 22:53   Re: how to trigger an entity which has defined targetname ?
Reply With Quote #2

register_event("BombExplode", "bombGoBoom")
register_event("HostageRescue", "freeTheSlaves") //that isn't racist, is it?
register_event("CT_win", "danceCTdance")
etc.
i think.....not sure the exact events

CSX module also has a function called bomb_explode which is called when the bomb goes off.

P.S. I love the code. Anything to make a programming professor weep is good for me. especially the abundant use of #if

Last edited by Liverwiz; 05-07-2012 at 22:58.
Liverwiz is offline
elle
Member
Join Date: Feb 2011
Old 05-07-2012 , 23:13   Re: how to trigger an entity which has defined targetname ?
Reply With Quote #3

thank you
i only need the command that trigger the defined entity which has defined targetname ,to add to the plugin at the #1 post ,sothat when vip escape , it trigger the entity

I 've already made the entity , all i need is a command that call the trigger function
elle is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-07-2012 , 23:18   Re: how to trigger an entity which has defined targetname ?
Reply With Quote #4

use a register_event handle.
whichever world event is triggered when a VIP escapes. Watch your HLSW console log when people are playing an as_ map. it'll give you all the world events that get triggered when it happens.
Liverwiz is offline
elle
Member
Join Date: Feb 2011
Old 05-08-2012 , 02:26   Re: how to trigger an entity which has defined targetname ?
Reply With Quote #5

thank you ,
but the vip escaped event has been made in the plugin

all i want is a command that trigger a entity,sothat i can add into the plugin
in detail, i want the code that triggers (break) all func_breakable which has the "targetname" field is "bombtargeta" in the map,such as
{
"model" "*36"
"targetname" "bombtargeta"
"rendermode" "4"
"spawnflags" "1"
"renderamt" "255"
"rendercolor" "0 0 0"
"classname" "func_breakable"
}
{
"model" "*37"
"targetname" "bombtargeta"
"rendermode" "4"
"spawnflags" "1"
"renderamt" "255"
"rendercolor" "0 0 0"
"classname" "func_breakable"
}

i use this code

Code:
public event_vip_safety(id) {
if (id == g_vip_id)
{
open_jail(id)
set_player_vip(id)
}
}
public open_jail(id) {
new ent2 =0
while((ent2 = engfunc(EngFunc_FindEntityByString, ent2, "targetname", "bombtargeta"))) {
dllfunc(DLLFunc_Use,ent2,id)
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
the plugin will be like this

Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fun>
#define PLUGIN_NAME "VIP Alternative"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "VEN"
new CVAR_NAME[] = "varmor"
#define CVAR_DEFAULT "100"
#define BIT_ICON_NORMAL (1<<0)
#define BIT_ICON_BLINK (1<<1)
#define BIT_ICON BIT_ICON_NORMAL
#define ICON_R 0
#define ICON_G 0
#define ICON_B 255
#define OFFSET_VIP_32BIT 209
#define OFFSET_VIP_64BIT 242
#define OFFSET_VIP_LINUXDIFF 5
#define BIT_VIP (1<<8)
#if !defined PROCESSOR_TYPE
#if cellbits == 32
#define OFFSET_VIP OFFSET_VIP_32BIT
#else
#define OFFSET_VIP OFFSET_VIP_64BIT
#endif
#else
#if PROCESSOR_TYPE == 0
#define OFFSET_VIP OFFSET_VIP_32BIT
#else
#define OFFSET_VIP OFFSET_VIP_64BIT
#endif
#endif
#define CVAR_POINTERS_AMXX_INIT_VER_NUM 170
#if defined AMXX_VERSION_NUM && AMXX_VERSION_NUM >= CVAR_POINTERS_AMXX_INIT_VER_NUM
#define CVAR_POINTERS
new g_cvar_pointer
#endif
new ICON_NAME[] = "vipsafety"
#define BIT_CENTER_TEXT (1<<2)
new MESSAGE_TEXT[] = "#Cannot_Switch_From_VIP"
new g_msgid_icon
new g_msgid_text
new g_vip_id
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
#if defined CVAR_POINTERS
g_cvar_pointer = register_cvar(CVAR_NAME, CVAR_DEFAULT)
#else
register_cvar(CVAR_NAME, CVAR_DEFAULT)
#endif
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
register_event("ResetHUD", "event_hud_reset", "be")
register_event("StatusIcon", "event_vip_safety", "be", "1=1", "2=vipsafety")
#if defined BIT_ICON
register_event("DeathMsg", "event_death", "a", "2!0")
#endif
register_clcmd("fullupdate", "clcmd_fullupdate")
register_clcmd("chooseteam", "clcmd_role_switch")
register_clcmd("jointeam", "clcmd_role_switch")
g_msgid_icon = get_user_msgid("StatusIcon")
g_msgid_text = get_user_msgid("TextMsg")
}
public event_new_round() {
if (!g_vip_id || !is_user_connected(g_vip_id))
return
new tchar[2]
get_user_team(g_vip_id, tchar, 1)
if (tchar[0] != 'C') {
g_vip_id = 0
return
}
set_player_vip(g_vip_id)
if (get_cvar_value() < 0)
g_vip_id = 0
}
public event_hud_reset(id) {
set_task(0.1, "task_vip_alteration", id)
}
public task_vip_alteration(id) {
if (is_user_alive(id) && set_player_vip(id, false)) {
g_vip_id = id
set_user_health (id, 200)
#if defined BIT_ICON
msg_vip_icon(id)
#endif
}
}
public client_disconnect(id) {
if (id == g_vip_id && !is_player_vip(id)) {
set_player_vip(id)
g_vip_id = 0
}
}
public event_vip_safety(id) {
if (id == g_vip_id)
{
open_jail(id)
set_player_vip(id)
}
}
public open_jail(id) {
new ent2 =0
while((ent2 = engfunc(EngFunc_FindEntityByString, ent2, "targetname", "bombtargeta"))) {
dllfunc(DLLFunc_Use,ent2,id)
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public event_death() {
new id = read_data(2)
if (id == g_vip_id)
msg_vip_icon(id, false)
}
public clcmd_role_switch(id) {
if (id != g_vip_id)
return PLUGIN_CONTINUE
msg_cant_switch_roles(id)
return PLUGIN_HANDLED
}
public clcmd_fullupdate() {
return PLUGIN_HANDLED
}
stock get_cvar_value() {
#if defined CVAR_POINTERS
return get_pcvar_num(g_cvar_pointer)
#else
return get_cvar_num(CVAR_NAME)
#endif
}
stock is_player_vip(id) {
return (get_pdata_int(id, OFFSET_VIP, OFFSET_VIP_LINUXDIFF) & BIT_VIP)
}
stock bool:set_player_vip(id, bool:vip = true) {
new oldbits = get_pdata_int(id, OFFSET_VIP, OFFSET_VIP_LINUXDIFF)
if (!vip && !(oldbits & BIT_VIP))
return false
new newbits
switch (vip) {
case true : newbits = (oldbits | BIT_VIP)
case false: newbits = (oldbits & ~BIT_VIP)
}
set_pdata_int(id, OFFSET_VIP, newbits, OFFSET_VIP_LINUXDIFF)
return true
}
stock msg_vip_icon(id, bool:show = true) {
message_begin(MSG_ONE, g_msgid_icon, {0, 0, 0}, id)
write_byte((show ? BIT_ICON : 0))
write_string(ICON_NAME)
if (show) {
write_byte(ICON_R)
write_byte(ICON_G)
write_byte(ICON_B)
}
message_end()
}
stock msg_cant_switch_roles(id) {
message_begin(MSG_ONE, g_msgid_text, {0, 0, 0}, id)
write_byte(BIT_CENTER_TEXT)
write_string(MESSAGE_TEXT)
message_end()
}

It works but there is a bug


Code:
[AMXX] Displaying debug trace (plugin "vipvr200t.amxx")
[AMXX] Run time error 3: stack error 
[AMXX] Displaying debug trace (plugin "vipvr200t.amxx")
[AMXX] Run time error 3: stack error 
[AMXX]    [0] vipvr200t.sma::set_player_vip (line 142)
[AMXX]    [1] vipvr200t.sma::event_vip_safety (line98 )
please tell me how to fix it ?
thanks

Last edited by elle; 05-08-2012 at 03:38.
elle is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-08-2012 , 08:38   Re: how to trigger an entity which has defined targetname ?
Reply With Quote #6

PHP Code:
new ent2 0
while((ent2 engfunc(EngFunc_FindEntityByStringent2"targetname""bombtargeta"))) { 

It should be = -1, also don't return anything ever in a loop.
__________________
<VeCo> is offline
elle
Member
Join Date: Feb 2011
Old 05-08-2012 , 12:37   Re: how to trigger an entity which has defined targetname ?
Reply With Quote #7

Quote:
Originally Posted by <VeCo> View Post
PHP Code:
new ent2 0
while((ent2 engfunc(EngFunc_FindEntityByStringent2"targetname""bombtargeta"))) { 
It should be = -1, also don't return anything ever in a loop.
thank you for helping ,but :
i tried changing new ent2 = -1
but that bugs still happens (stack error)
if i dont return PLUGIN_HANDLED in while "loop", it will cause overflow error and crash the game
elle 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 18:23.


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