Author Topic: Disabling default join/quit messages  (Read 2924 times)

xIBKn6

  • Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Disabling default join/quit messages
« on: September 14, 2011, 11: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:

Code: [Select]
//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);
}
Code: [Select]
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.

Force

  • Developer
  • Full Member
  • *****
  • Posts: 204
  • Karma: +6/-2
    • View Profile
Re: Disabling default join/quit messages
« Reply #1 on: September 14, 2011, 11:43:50 pm »
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?
Quote
[Tue - 20:09:35] <&VRocker> CRAP!
[Tue - 20:09:43] <&VRocker> i think i just followed through...
Quote
[Sat - 22:11:56] <~Smapy> [R3V]breSt12 killed [R3V]Jack_Bauer. (Splat)

xIBKn6

  • Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Disabling default join/quit messages
« Reply #2 on: September 15, 2011, 12:08:39 am »
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.

Code: [Select]
//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);
}

Juppi

  • Developer
  • Jr. Member
  • *****
  • Posts: 86
  • Karma: +3/-1
    • View Profile
    • Kuslahden alaste GTA:MP clan
Re: Disabling default join/quit messages
« Reply #3 on: September 15, 2011, 12:45:40 am »
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.

xIBKn6

  • Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Disabling default join/quit messages
« Reply #4 on: September 15, 2011, 12:54:21 am »
Gotcha, but what about the error I'm having? It seems a bit random.

Force

  • Developer
  • Full Member
  • *****
  • Posts: 204
  • Karma: +6/-2
    • View Profile
Re: Disabling default join/quit messages
« Reply #5 on: September 15, 2011, 01:19:54 am »
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:

Code: [Select]
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;
}
Quote
[Tue - 20:09:35] <&VRocker> CRAP!
[Tue - 20:09:43] <&VRocker> i think i just followed through...
Quote
[Sat - 22:11:56] <~Smapy> [R3V]breSt12 killed [R3V]Jack_Bauer. (Splat)

xIBKn6

  • Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Disabling default join/quit messages
« Reply #6 on: September 15, 2011, 03:22:41 am »
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:
Code: [Select]
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.

 

© Liberty Unleashed Team.