Hello,
Is there any way to change the order of events or to make one event wait a little bit for another?
I need simple plugin - showing on the HUD name of player which user is currently spectating. I found the "SpecHealth2" event which looks like a thing that I need - code using the event (everything works):
PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Test"
#define VERSION "1.0"
#define AUTHOR "Test"
new SyncHudObj;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
SyncHudObj = CreateHudSyncObj();
register_event("SpecHealth2","event_showNick","bd");
}
public event_showNick(id) {
new target=read_data(2);
new targetName[32];
get_user_name(target, targetName, 31);
set_hudmessage(255, 255, 255, 0.02, 0.21, 0, 0.0, 10.0, 0.0, 0.0);
ShowSyncHudMsg(id, SyncHudObj, "You are watching: %s", targetName);
}
Now it's time for 'tricky' part - I would like to show that info
only if user/watcher/specator is in FirstPersonView. Google'd a little bit, found a code of Admin ESP plugin and:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Test"
#define VERSION "1.0"
#define AUTHOR "Test"
new SyncHudObj;
new first_person[33];
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
SyncHudObj = CreateHudSyncObj();
register_event("SpecHealth2","event_showNick","bd");
register_event("TextMsg","isFirstPersonSpec","bd","2&#Spec_Mode");
}
public event_showNick(id) {
if (!first_person[id]) {
ClearSyncHud(id, SyncHudObj);
return PLUGIN_CONTINUE;
}
new target=read_data(2);
new targetName[32];
get_user_name(target, targetName, 31);
set_hudmessage(255, 255, 255, 0.02, 0.21, 0, 0.0, 10.0, 0.0, 0.0);
ShowSyncHudMsg(id, SyncHudObj, "You are watching: %s", targetName);
return PLUGIN_CONTINUE;
}
public isFirstPersonSpec(id) {
new specMode[12];
read_data(2,specMode,11);
if(equal(specMode,"#Spec_Mode4")) {
first_person[id]=true;
} else {
first_person[id]=false;
}
return PLUGIN_CONTINUE;
}
If the first_person[id] value is not set to true we are clearing the HUD (sometimes we are not in the FirstPersonView anymore).
Looks good, sounds good, works almost good - it do not work for the first player which we switch to within FirstPersonView. Looks like the events are in 'wrong' order for me. First goes "SpecHealth2" which check value of first_person and finds there false - so it is not rendering anything on HUD. Then goes "TextMsg" setting the first_person[id] to true. I would like to change the order of events - first "TextMsg", then "SpecHealth2" - it is even possible? I've tried switching places with the register_event functions in plugin_init() and the public functions() but it do not help.
If it is not possible do you know any solution to my problem (like other event containing Spec_Mode, SpecatorID and SpectatedID/target)? I would
rather not use set_task - events are better :-)