Raised This Month: $ Target: $400
 0% 

Multiple Triggers on pTouched


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blood2k
Senior Member
Join Date: Mar 2014
Old 03-28-2017 , 01:45   Multiple Triggers on pTouched
Reply With Quote #1

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

}
blood2k is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-28-2017 , 07:22   Re: Multiple Triggers on pTouched
Reply With Quote #2

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

__________________

Last edited by PRoSToTeM@; 03-28-2017 at 11:13.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
blood2k
Senior Member
Join Date: Mar 2014
Old 03-28-2017 , 11:26   Re: Multiple Triggers on pTouched
Reply With Quote #3

Quote:
Originally Posted by PRoSToTeM@ View Post
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!
blood2k 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 17:59.


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