Liberty Unleashed
Scripting => Script Help => Topic started by: John_Michael on September 14, 2011, 10:38:34 pm
-
Hey all, I was wondering if it's possible to disable the normal join/quit messages of the server and replace them with my own. Also, I have a script ready for this, but it give me an error that I don't quite understand:
//This function is executed when a player leaves.
function onPlayerPart(thePlayer, reason)
{
local reasonString = "Unknown";
if(reason == PARTREASON_DISCONNECTED) { reasonString = "Quit"; }
if(reason == PARTREASON_TIMEOUT) { reasonString = "Timeout"; }
if(reason == PARTREASON_BAN) { reasonString = "Banned"; }
if(reason == PARTREASON_KICKED) { reasonString = "Kicked"; }
MessageAllExcept("* "+thePlayer.Name+" has left the game ("+reasonString+").", thePlayer, 0, 255, 0);
}
CONNECTION: Closed [192.168.1.45] | Index [0]
AN ERROR HAS OCCURED [getVarInfo: Could not retrieve UserData]
CALLSTACK
*FUNCTION [onPlayerPart()] Scripts/Main/sJohnMode.nut line [57]
LOCALS
[reasonString] "Quit"
[reason] 0
[thePlayer] INSTANCE
[this] TABLE
CONNECTION: Incoming [192.168.1.45] | Index [0]
Thanks in advance.
-
To disable them you can just return 1; on the events in the client scripts.
You don't need to use MessageAllExcept, just use Message, since that player will have left the server anyway.
Which line is line 57?
-
So to disable join/quit messages, I need to return 1 client-side? Sounds weird, but I'll go for it.
Here is what I have now - same error. Line 57 is where the comment is.
//This function is executed when a player leaves.
function onPlayerPart(thePlayer, reason)
{
local reasonString = "Unknown";
if(reason == PARTREASON_DISCONNECTED) { reasonString = "Quit"; }
if(reason == PARTREASON_TIMEOUT) { reasonString = "Timeout"; }
if(reason == PARTREASON_BAN) { reasonString = "Banned"; } //This is line 57
if(reason == PARTREASON_KICKED) { reasonString = "Kicked"; }
MessageExcept("* "+thePlayer.Name+" has left the game ("+reasonString+").", 0, 255, 0);
}
-
Just a little correction you need to return 0 not 1 - the reason for this being that the built in messages are client-side and returning 0 will stop processing the join/part events any further.
-
Gotcha, but what about the error I'm having? It seems a bit random.
-
Ah yeh sorry, dunno what I was thinking when I said 1 :P.
As for your code I don't see anything immediately wrong, try this instead:
local szPartReason = "Disconnected";
switch ( reason )
{
case PARTREASON_DISCONNECTED: szPartReason = "Quit";
break;
case PARTREASON_TIMEOUT: szPartReason = "Timeout";
break;
case PARTREASON_BAN: szPartReason = "Banned";
break;
case PARTREASON_KICKED: szPartReason = "Kicked";
break;
}
-
Ok, so there were 2 issues:
1- Message() causes an error (and in some cases, a server crash) if no players are on the server when the message is output. I made a small workaround for this:
function _Message(theString, r, g, b)
{
if(GetPlayers())
{
return Message(theString, r, g, b);
}
else
{
return 1;
}
}
2 - I probably should have used a switch statement in the first place.
Thanks for the help.