Threaded timers???
#3

hmmm... crazy... I can't reproduce the problem in a simple test script.

Maybe the plugins I use work in threads and cause the server to crash if I call a function at the wrong time?

I'm using the following plugins: Are some of them known as buggy in this way?

SA-MP Server version: 0.3e RC7 (I also had this problem in RC6)


//EDIT: I found the problem.

I have an filterscript to process RCON commands in the gamemode. In my filterscript (rcon proxy) I just call rcmd_<command> with CallRemoteFunction().


RCON Proxy Filterscript:
Код:
#include <a_samp>

public OnFilterScriptInit()
{
	print("RCON Proxy Filterscript loaded");
	return true;
}

public OnFilterScriptExit()
{
	print("RCON Proxy Filterscript unloaded");
	return true;
}

public OnRconCommand(cmd[])
{
	new pos;
	new functionName[32];
	while (cmd[pos] > ' ')
	{
		functionName[pos] = tolower(cmd[pos]);
		pos++;
	}
	format(functionName, sizeof(functionName), "rcmd_%s", functionName);
	while (cmd[pos] == ' ')
	{
		pos++;
	}
	if (!cmd[pos])
	{
		return CallRemoteFunction(functionName, "s", "\1");
	}
	return CallRemoteFunction(functionName, "s", cmd[pos]);
}
Test gamemode:
Код:
#include <a_samp>

public OnGameModeInit()
{
	SetTimer("Timer", 250, true);
}

SlowFunction()
{
	print("SlowFunction:Start");
	// Simulate slow function
	new oldTime = gettime();
	new difference;
	while (difference < 5)
	{
		difference = gettime() - oldTime;
	}
	print("SlowFunction:End");
}

forward rcmd_testcmd(command[]);
public rcmd_testcmd(command[])
{
	SlowFunction();
	return true;
}

forward Timer();
public Timer()
{
	print("Timer");
}

main(){}
Just type "testcmd" in the server console or send it via RCON.


The result will look like that:
Код:
[00:44:22] Timer
[00:44:23] Timer
[00:44:23] Timer
[00:44:23] Timer
Console input: testcmd
[00:44:23] SlowFunction:Start
[00:44:23] Timer
[00:44:24] Timer
[00:44:24] Timer
[00:44:24] Timer
[00:44:25] Timer
[00:44:25] Timer
[00:44:25] Timer
[00:44:25] Timer
[00:44:26] Timer
[00:44:26] Timer
[00:44:26] Timer
[00:44:27] Timer
[00:44:27] Timer
[00:44:27] Timer
[00:44:27] Timer
[00:44:28] SlowFunction:End
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:29] Timer
[00:44:29] Timer
But I want that:
Код:
[00:44:22] Timer
[00:44:23] Timer
[00:44:23] Timer
[00:44:23] Timer
Console input: testcmd
[00:44:23] SlowFunction:Start
[00:44:28] SlowFunction:End
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:28] Timer
[00:44:29] Timer
[00:44:29] Timer
//EDIT2: I moved the SlowFunction() code directly to OnRconCommand() in the filterscript. Same problem...

Filterscripts don't run in the main loop? But I thought SA-MP is using a single thread?
Reply


Messages In This Thread
Threaded timers??? - by Programie - 23.04.2012, 19:22
Re: Threaded timers??? - by Hiddos - 23.04.2012, 21:33
Re: Threaded timers??? - by Programie - 23.04.2012, 22:26

Forum Jump:


Users browsing this thread: 1 Guest(s)