Executing function calls in order

Started by Murdock, May 17, 2015, 02:53 PM

Previous topic - Next topic

Murdock

While working on an anti-spam script I stumbled on two problems.
I am trying to send a message before kicking the player, so the player knows why he was kicked.
But the function KickPlayer seems to execute faster than the Message function, resulting in the player being kicked first, and the message being sent afterwards which will not be received by the player.

I used the following code to test this:
function onPlayerChat( player, message )
{
  Message( format( "*** %s has been kicked for spamming", player.Name ) );
  KickPlayer( player );
  return false;
}

I am also experiencing a similar problem when I want to disconnect my IRC bots when reloading all scripts.
Executing "IRC.Disconnect(); ReloadScripts();" works fine, however the following code does not:
function onScriptUnload()
{
  if ( IRC )
    IRC.Disconnect();
}

Both problems are solved when I add a timer of 100ms to the last function that needs to execute.
However, I don't think it's good practise to bloat the script with timers.
Is there any other way to have these functions execute in order properly?

.

#1
I remember back in the days when I was scripting for CS 1.6 and you'd have to specify a kick/ban message/reason automatically. I think the devs should add this as well. Allow us to kick/ban someone with a reason included. A simple string after the player instance that is sent to the client after the kick/ban. So, when the player is disconnected from the server the message remains there.

EDIT: Actually, I think it's not about executing functions in order. AFAIK, the server is multi-threaded. At least the networking part is and the plugins could be too (or at least the way they send commands to the server, I think).  Probably this plays an important role as to which message reaches first from the plugins. Not sure though because I'm missing further information about how the server is implemented.
.