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

[Solved] Timer Target Variable Problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-13-2015 , 01:11   [Solved] Timer Target Variable Problem
Reply With Quote #1

Solved!

Do not blank your post; read rules; -RedSword

Hi ,

i have problem with the timers and target..

I Want It Like When Someone Write :

/test <target>

Its Create Timer And Do Server Command On The Target.



Example Code :

Code:
Timer :

CreateTimer(5.0, Test, _, TIMER_REPEAT);


Public :

public Action:Test(Handle:timer, any:target)
{
PrintToChatAll("%N Gives %N Test Command!" client, target);
ServerCommand("sm_test2 %N", target);

}
And The Server Log :
Code:
Target Not Found.
the target code i using :

Code:
char arg1[32], target;
GetCmdArg(1, arg1, sizeof(arg1));
target = FindTarget(client, arg1);
How Do I Send The Target Variable With The Timer ?

For Full Code Contact Me

Thx For Helpers
__________________

Last edited by RedSword; 08-13-2015 at 04:22. Reason: do not blank your post, read rules
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Icon315
Junior Member
Join Date: Dec 2014
Old 08-13-2015 , 01:58   Re: Timer Target Variable Problem
Reply With Quote #2

Well since you are trying to send both the client and the target, you might try using a DataPacks.
https://wiki.alliedmods.net/Timers_(...ng)#Data_Packs

Here's an example:
Code:
public Action Test(int client, int args)
{
    char arg1[32], target;
    GetCmdArg(1, arg1, sizeof(arg1));
    target = FindTarget(client, arg1);
    if(IsClientInGame(target))
    {
        Handle data = CreateDataPack();
        WritePackCell(data, client);
        WritePackCell(data, target);
        CreateTimer(5.0, TestTimer, data, TIMER_REPEAT);
    }
}

public Action TestTimer(Handle timer, any:data)
{
    ResetPack(data);
    int client = ReadPackCell(data);
    int target = ReadPackCell(data);
    PrintToChatAll("%N Gives %N Test Command!", client, target);
    ServerCommand("sm_test2 #%d", GetClientUserId(target));
}

Last edited by Icon315; 08-15-2015 at 04:47.
Icon315 is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-13-2015 , 02:08   Re: Timer Target Variable Problem
Reply With Quote #3

Quote:
Originally Posted by Icon315 View Post
Well since you are trying to send both the client and the target, you might try using a DataPacks.
https://wiki.alliedmods.net/Timers_(...ng)#Data_Packs

Here's an example:
Code:
public Action Test(int client, int args)
{
    char arg1[32], target;
    GetCmdArg(1, arg1, sizeof(arg1));
    target = FindTarget(client, arg1);
    if(IsClientInGame(target))
    {
        Handle data = CreateDataPack();
        WritePackCell(data, client);
        WritePackCell(data, target);
        CreateTimer(5.0, TestTimer, data, TIMER_REPEAT);
    }
}

public Action TestTimer(Handle timer, any:data)
{
    ResetPack(data);
    int client = ReadPackCell(data);
    int target = ReadPackCell(data);
    PrintToChatAll("%N Gives %N Test Command!", client, target);
    ServerCommand("sm_test2 %N", target);
}
Thx For Your Reply !
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-13-2015 , 02:44   Re: Timer Target Variable Problem
Reply With Quote #4

Solved !
__________________

Last edited by nhnkl159; 08-13-2015 at 03:56.
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 08-13-2015 , 04:24   Re: [Solved] Timer Target Variable Problem
Reply With Quote #5

Re-added your question to the first post, as per the forum rules you should not blank your post. This is intended to help people in the future to find possibly similar problems.

Red
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 08-13-2015 at 04:25.
RedSword is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-13-2015 , 04:29   Re: [Solved] Timer Target Variable Problem
Reply With Quote #6

Quote:
Originally Posted by RedSword View Post
Re-added your question to the first post, as per the forum rules you should not blank your post. This is intended to help people in the future to find possibly similar problems.

Red

OK thanks you
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 08-13-2015 , 10:03   Re: [Solved] Timer Target Variable Problem
Reply With Quote #7

I should also say, NEVER PASS A CLIENT NAME TO ServerCommand NATIVE, it's just begging to be exploited.
__________________
WildCard65 is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 08-14-2015 , 18:02   Re: [Solved] Timer Target Variable Problem
Reply With Quote #8

Quote:
Originally Posted by WildCard65 View Post
I should also say, NEVER PASS A CLIENT NAME TO ServerCommand NATIVE, it's just begging to be exploited.
^This. Use user IDs instead. e.g.
PHP Code:
new iUserID GetClientUserId(client);
ServerCommand("sm_slay #%i"iUserID); 
To explain what kind of exploits wildcard is referring to, imagine the name "haha;quit".

The server command becomes: sm_test2 haha;quit

Now your server is shut down. GG.
__________________

Last edited by ThatOneGuy; 08-14-2015 at 18:05.
ThatOneGuy is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-15-2015 , 02:18   Re: [Solved] Timer Target Variable Problem
Reply With Quote #9

Quote:
Originally Posted by ThatOneGuy View Post
^This. Use user IDs instead. e.g.
PHP Code:
new iUserID GetClientUserId(client);
ServerCommand("sm_slay #%i"iUserID); 
To explain what kind of exploits wildcard is referring to, imagine the name "haha;quit".

The server command becomes: sm_test2 haha;quit

Now your server is shut down. GG.
So to remove the exploit i need to use like :

Servercommand("sm_test2 #%N", target);

And its remove the exploit?
__________________

Last edited by nhnkl159; 08-15-2015 at 02:19.
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-15-2015 , 04:01   Re: [Solved] Timer Target Variable Problem
Reply With Quote #10

i, not N, and userID, not target
__________________
ddhoward 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 16:49.


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