AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Multiple Triggers on pTouched (https://forums.alliedmods.net/showthread.php?t=295515)

blood2k 03-28-2017 01:45

Multiple Triggers on pTouched
 
Alright, I'm in no way a coder.. but I've been reading around and putting together snippets of codes that are relevant to what I needed to do: Create a entity sprite that when players step on will show them a message/motd/or whatever... i'll figure this out eventually.

Now I have it all put together.. and I was testing it showing a message to the player that touches the entity. It shows "Test test test".. my problem is it keeps spamming it as long as the player stands near the entity.. could somebody help me make it only execute the message once.. until player walks away and comes back to it again. :)

Code:

/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <engine>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

 public plugin_precache()
{
precache_model("sprites/marker.spr")
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_touch("info_ammustore", "player", "Message")
static ent
ent  = create_entity("info_target")
if(ent)
{
entity_set_string(ent,EV_SZ_classname,"info_ammustore") // entity classname
entity_set_model(ent,"sprites/marker.spr") // path to the sprite
 
entity_set_int(ent, EV_INT_solid, SOLID_TRIGGER) // Solid Passable
entity_set_int(ent,EV_INT_movetype,MOVETYPE_NONE) // don't move
 
set_rendering(ent, kRenderFxNoDissipation, 0,0,0, kRenderGlow, 255)
 
entity_set_origin(ent,Float:{-530.0,-2663.0,161.0}) // origin
}

}
public Message(pToucher, pTouched)
{
    client_print(pTouched, print_chat, "TEst test test"); // testing

}


PRoSToTeM@ 03-28-2017 07:22

Re: Multiple Triggers on pTouched
 
Try to check oldorigin of the player for touching with this trigger, if it doesn't touch the trigger then you can print this message.
Or you can check if player touched this trigger in previous frame:
PHP Code:

new bool:g_touchedPrevFrame[MAX_PLAYERS 1];
new 
bool:g_touchedThisFrame;

public 
client_putinserver(player) {
    
g_touchedPrevFrame[player] = false;
}

public 
client_PreThink(player) {
    
g_touchedThisFrame false;
}

public 
client_PostThink(player) {
    
g_touchedPrevFrame[player] = g_touchedThisFrame;
}

public 
Message(touchedtoucher
{
    
g_touchedThisFrame true;
    if (
g_touchedPrevFrame[toucher])
        return;
    
client_print(toucherprint_chat"TEst test test"); // testing



blood2k 03-28-2017 11:26

Re: Multiple Triggers on pTouched
 
Quote:

Originally Posted by PRoSToTeM@ (Post 2507333)
Try to check oldorigin of the player for touching with this trigger, if it doesn't touch the trigger then you can print this message.
Or you can check if player touched this trigger in previous frame:
PHP Code:

new bool:g_touchedPrevFrame[MAX_PLAYERS 1];
new 
bool:g_touchedThisFrame;

public 
client_putinserver(player) {
    
g_touchedPrevFrame[player] = false;
}

public 
client_PreThink(player) {
    
g_touchedThisFrame false;
}

public 
client_PostThink(player) {
    
g_touchedPrevFrame[player] = g_touchedThisFrame;
}

public 
Message(touchedtoucher
{
    
g_touchedThisFrame true;
    if (
g_touchedPrevFrame[toucher])
        return;
    
client_print(toucherprint_chat"TEst test test"); // testing





Thank you very much sir!:)


All times are GMT -4. The time now is 17:59.

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