Raised This Month: $12 Target: $400
 3% 

Ham_Touch spam issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
heroicpower7613
Member
Join Date: Nov 2016
Old 01-06-2017 , 14:20   Ham_Touch spam issue
Reply With Quote #1

im new to scripting
i have a simple code that prints a message when you're touching player.
problem is its spamming the message like crazy when touching.
how can i get it to print only one message and not lag the server?

code:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Touch"player""PlayerTouch");
    
// Add your code here...
}

public 
PlayerTouch(idplayer) {
    
    if( 
is_user_aliveid ) && is_user_aliveplayer ) && cs_get_user_teamid ) ==CS_TEAM_T && cs_get_user_teamplayer ) == CS_TEAM_CT ) { //if you are CT and touch T
        
        
new touch_target[32]
        
get_user_name(idtouch_target31);
        
client_printplayerprint_chat"touching: %s [terrorist]"touch_target );
    }
    return 
PLUGIN_CONTINUE;

heroicpower7613 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-06-2017 , 14:44   Re: Ham_Touch spam issue
Reply With Quote #2

Of course it will be spaming. You are touching the player all the time. Add a simple timer and send the message only if X seconds have passed since the last message.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
heroicpower7613
Member
Join Date: Nov 2016
Old 01-06-2017 , 15:14   Re: Ham_Touch spam issue
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
Add a simple timer and send the message only if X seconds have passed since the last message.
idk how to do it
heroicpower7613 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-06-2017 , 16:41   Re: Ham_Touch spam issue
Reply With Quote #4

Then search. There are approximately 644628 examples of how to do it out there.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 01-06-2017 , 16:57   Re: Ham_Touch spam issue
Reply With Quote #5

like that:
PHP Code:
// Here we insert the current times + the necesary time to wait
new g_Time[33];


public 
touchid )
{
    
// here we get the exact current seconds passed from map/server start.
    
new iCurrentTime floatroundget_gametime() );

    
// We check if 'now' is bigger or equal with the g_Time, wich means if he past 10 seconds.
    
if( iCurrentTIme >= g_Timeid ] )
    {
        
// Times passed, you can use now!
        // your code here ...


        // Also we update the time:
        // +10 , how many seconds he need to wait until he can use again the command.
        
g_Timeid ] = iCurrentTime 10;
    }

    else
    {
        
client_printid print_chat"wait %i seconds before use again this command!"g_Timeid ] - iCurrentTIme );    
    }


__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
heroicpower7613
Member
Join Date: Nov 2016
Old 01-06-2017 , 17:21   Re: Ham_Touch spam issue
Reply With Quote #6

Quote:
Originally Posted by Craxor View Post
like that:
thanks my man, it works

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new g_Time[33];

public 
plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Touch"player""PlayerTouch");
    
// Add your code here...
}

public 
PlayerTouch(idplayer) {
    
    if( 
is_user_aliveid ) && is_user_aliveplayer ) && cs_get_user_teamid ) ==CS_TEAM_T && cs_get_user_teamplayer ) == CS_TEAM_CT ) { //you are CT and touch T
        
        
new iCurrentTime floatroundget_gametime() );
        if( 
iCurrentTime >= g_Time[player] ) 
        {
        
            new 
touch_target[32]
            
get_user_name(idtouch_target31);
            
client_print(playerprint_chat"touching: %s [t]"touch_target);
            
g_Time[player] = iCurrentTime 10;

        } else {

            return 
PLUGIN_HANDLED;
        }
        
    }
    return 
PLUGIN_HANDLED;


Last edited by heroicpower7613; 04-18-2017 at 06:59.
heroicpower7613 is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-06-2017 , 19:37   Re: Ham_Touch spam issue
Reply With Quote #7

@Craxor what is the purpose of using rounded time? Rounded time in your code gives not 10 secs, but from 9.5 to 10.5 secs.
So:
PHP Code:
#define GetCurrentGameTime get_gametime

new Float:g_nextNotificationTime[MAX_PLAYERS 1];

public 
PlayerTouch(touchedPlayertoucher)
{
    if (
GetCurrentGameTime() >= g_nextNotificationTime[touchedPlayer])
    {
        
// Notify touched player
        
        
const delaySeconds 10;
        
g_nextNotificationTime[touchedPlayer] = GetCurrentGameTime() + delaySeconds;
    }
    
    
// if you need to count remain seconds you can use this:
    // floatround(g_nextNotificationTime[touchedPlayer] - GetCurrentGameTime(), floatround_ceil)

__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-06-2017 , 23:14   Re: Ham_Touch spam issue
Reply With Quote #8

Instead of putting a timer on the touch, you can track the last player that was touched and not register a touch again until a different player is touched.

1 touches 2 [touch fires]
1 touches 2 [nothing happens]
1 touches 2 [nothing happens]
1 touches 4 [touch fires]
1 touches 4 [nothing happens]
1 touches 2 [touch fires]

PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define MAX_PLAYERS 32

#define IsPlayer(%1)    (1<=%1<=MAX_PLAYERS)

new g_LastTouchedMAX_PLAYERS ];

public 
plugin_init() 
{
    
RegisterHamHam_Touch "player" "PlayerTouch" );
}

public 
client_connectid 
{
    
g_LastTouchedid ] = 0;
}

public 
PlayerTouchid player 
{
    if ( 
IsPlayerid ) && IsPlayerplayer ) )
    {
        if ( 
g_LastTouchedid ] != player )
        {
            
//Touched player
            
client_printid print_chat "Touched %d" player );
        }
        
        
g_LastTouchedid ] = player;
    }

__________________
Bugsy is online now
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-07-2017 , 05:22   Re: Ham_Touch spam issue
Reply With Quote #9

@Bugsy:
1 touch 2
1 stop touching 2
1 touch 2 again
__________________

Last edited by HamletEagle; 01-07-2017 at 05:23.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 01-07-2017 , 10:20   Re: Ham_Touch spam issue
Reply With Quote #10

Prostet. i don't understand what are you saying, is working as is supposed to work..
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
Reply


Thread Tools
Display Modes

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 06:24.


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