Raised This Month: $32 Target: $400
 8% 

datatimer | :any parameter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 03-17-2014 , 10:16   datatimer | :any parameter
Reply With Quote #1

I'm using a datatimer but something is done wrong, can you see it?

Where the timer gets callend:
PHP Code:
new Handle:hJoinTeamInfo;
 
Timer_ClientJoinedTeam[client] = CreateDataTimer(1.0OnClientChangedTeamhJoinTeamInfo);
 
WritePackCell(hJoinTeamInfoclient);
 
WritePackCell(hJoinTeamInfoiTeam);
 
WritePackCell(hJoinTeamInfoiFirstTeamJoin);
 
WritePackCell(hJoinTeamInfoGetClientTeam(client));
  
 return 
Plugin_Continue
In the callback:
PHP Code:
public Action:OnClientChangedTeam(Handle:timerHandle:hDatapack)
{
 
ResetPack(hDatapack);
 new 
client ReadPackCell(hDatapack);
 new 
iTeam ReadPackCell(hDatapack);
 new 
iFirstTeamJoin ReadPackCell(hDatapack);
 new 
prevteam ReadPackCell(hDatapack);
 
CloseHandle(hDatapack);
...
...

This gives me a strange error, i think it was a memery error not sure.


Second question: How can i add in the any parameter in my native so that the string is formatable in the native itself.
(fe; i have this now and i want to add in the :any parameter for formatting rules, how can i do this?)
PHP Code:
// native Mmorpg_PrintToChat(client, const String:szMessage[]="");
public Native_Mmorpg_PrintToChat(Handle:pluginNumParams)
{
 new 
client GetNativeCell(1);
 new 
String:szMessage[255];
 
GetNativeString(2szMessagesizeof(szMessage));
 
 if(
strlen(szMessage) > 0)
 {
  if(
_IsValidClient(client))
  {
   
CPrintToChat(client"%s {default}%s"CPrefixszMessage);
  }
 }

__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 03-17-2014 , 13:03   Re: datatimer | :any parameter
Reply With Quote #2

1) Try removing the CloseHandle line inside of the timer callback. If that's not it, post the error you're getting.
2) Use the VFormat function.
bl4nk is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 03-17-2014 , 16:11   Re: datatimer | :any parameter
Reply With Quote #3

Ok thanks, that was my first idea aswell but i still need to test it to be 100% sure

I'll get back to you here incase i need further assistance.
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 03-18-2014 , 05:17   Re: datatimer | :any parameter
Reply With Quote #4

PHP Code:
Timer_ClientJoinedTeam[client] = CreateDataTimer(1.0OnClientChangedTeamhJoinTeamInfo);
WritePackCell(hJoinTeamInfoclient); 
nuuuuu

You should use client serials/user ids in timers instead of client indexes. Even if you're keeping track using a global array like Timer_ClientJoinedTeam (which I didn't see, heh) it's still not a very good habit.
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)

Last edited by MasterOfTheXP; 03-18-2014 at 05:18.
MasterOfTheXP is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-18-2014 , 05:44   Re: datatimer | :any parameter
Reply With Quote #5

Yep. Like @Master... said.

Do you really need global Handle array for store timers ??
And you don't need CloseHhandle datataimer datapack, it will do itself.

anyway...
Code:

Timer_ClientJoinedTeam[MAXPLAYERS+1];

Daa(client)
{

	if(Timer_ClientJoinedTeam[client] != INVALID_HANDLE)
	{
		KillTimer(Timer_ClientJoinedTeam[client]);
		Timer_ClientJoinedTeam[client] = INVALID_HANDLE;
	}

	new Handle:hJoinTeamInfo;
	Timer_ClientJoinedTeam[client] = CreateDataTimer(1.0, OnClientChangedTeam, hJoinTeamInfo);
	WritePackCell(hJoinTeamInfo, client);
	WritePackCell(hJoinTeamInfo, GetClientUserId(client));
	...
	...
	...
	...
	ResetPack(hDatapack);

}

public Action:OnClientChangedTeam(Handle:timer, Handle:hDatapack)
{
	new array_index = ReadPackCell(hDatapack);
	Timer_ClientJoinedTeam[array_index] = INVALID_HANDLE; // Clear handle when timer make (last) action.

	new client = GetClientOfUserId(ReadPackCell(hDatapack));

	if(client == 0)
	{
		return Plugin_Stop;
	}
	...
	...
	...
	...


	return Plugin_Continue;
}
Bacardi is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 03-27-2014 , 06:47   Re: datatimer | :any parameter
Reply With Quote #6

Quote:
Originally Posted by MasterOfTheXP View Post
PHP Code:
Timer_ClientJoinedTeam[client] = CreateDataTimer(1.0OnClientChangedTeamhJoinTeamInfo);
 
WritePackCell(hJoinTeamInfoclient); 
nuuuuu

You should use client serials/user ids in timers instead of client indexes. Even if you're keeping track using a global array like Timer_ClientJoinedTeam (which I didn't see, heh) it's still not a very good habit.
omg you are right, i oversee this quite a lot :s.

Quote:
Originally Posted by Bacardi View Post
Yep. Like @Master... said.

Do you really need global Handle array for store timers ??
And you don't need CloseHhandle datataimer datapack, it will do itself.
- i do need a global handle for this because when you join a team it can fail, for example because team is full, i need to catch this event and stop the datatimer callback from executing its actions.
- yeah i edited this and the memory error was gone
Quote:
Originally Posted by Bacardi View Post
Spoiler
I know its not nescesary to close the handle in the datatimer callback but i am using return plugin_stop instead of plugin_continue and before this i already set the global timerhandle to invalid and this works without errors. does it matter here what i return at the end of the datatimer callback?

How I have it now:
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 03-27-2014 , 07:11   Re: datatimer | :any parameter
Reply With Quote #7

Quote:
Originally Posted by bl4nk View Post
1)
2) Use the VFormat function.
is this correct?:
PHP Code:
public Native_Mmorpg_PrintToChat(Handle:pluginNumParams)
{
    new 
client GetNativeCell(1);
    new 
String:szMessage[256];
    
GetNativeString(2szMessagesizeof(szMessage));
    
VFormat(szMessage256szMessage3);
 
    if(
strlen(szMessage) > 0)
    {
         if(
_IsValidClient(client))
        {
             
CPrintToChat(client"%s {default}%s"CPrefixszMessage);
        }
    }

edit.
tested this but it does not work, the the %.. are not formatted and displayed as %.
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 03-27-2014 at 14:05.
striker07 is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-27-2014 , 08:03   Re: datatimer | :any parameter
Reply With Quote #8

Your mechanism of action is bad. Just add command listener for jointeam, or just use getclientteam. Try storing their previous team in an array?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 03-27-2014 , 08:25   Re: datatimer | :any parameter
Reply With Quote #9

Quote:
Originally Posted by friagram View Post
Your mechanism of action is bad. Just add command listener for jointeam, or just use getclientteam. Try storing their previous team in an array?
that is how its done

HookEvent("jointeam_failed", Event_JoinTeamFailed, EventHookMode_Pre); // here i simply close timerhandle before it fires and set handle to invalid if not invalid
AddCommandListener(OnClientJoinTeam, "jointeam");


it works perfectly, no problems with that anymore
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 03-29-2014 , 10:42   Re: datatimer | :any parameter
Reply With Quote #10

For the vformat issue, i am getting this in my server console:
L 03/29/2014 - 156:48: [SM] Plugin encountered error 4: Invalid parameter or parameter type
L 03/29/2014 - 156:48: [SM] Native "VFormat" reported: String formatted incorrectly - parameter 3 (total 2)

using this native:
PHP Code:
public Native_Mmorpg_PrintToChat(Handle:pluginNumParams)
{
    new 
client GetNativeCell(1);
    new 
String:szMessage[256];
    
GetNativeString(2szMessagesizeof(szMessage));
    new 
String:szFinalMsg[256];
    
VFormat(szFinalMsg256szMessage3);
 
    if(
strlen(szMessage) > 0)
    {
         if(
_IsValidClient(client))
         {
              
CPrintToChat(client"%s {default}%s"CPrefixszFinalMsg);
         }
    }

The problem is that Vformat does not see the third parameter in this native(also not retrieving the any:... parameter, how can i fix this/return the any parameter?

I was thinking getnativecellref but this does not seem logical.
Can vformat even be used in natives?
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 03-29-2014 at 10:44.
striker07 is offline
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 00:05.


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