Hello There, Guest! Login or Register


Useful Functions/Snippets/Commands
#5
shouldn't this
Code:
public OnPlayerDisconnect(playerid,reason)
{
   new str[256],gConnectname[255];
   GetPlayerName(playerid,gConnectname,255);
   switch(reason)
   {
        case 0: format(str,256,"%s has Timed Out!");
        case 1: format(str,256,"%s has left the server.");
        case 2: format(str,256,"%s has been kicked out the server.");

   }
   SendClientMessageToAll(0xAFAFAFAA,str);
   return true;
}
be
Code:
public OnPlayerDisconnect(playerid,reason)
{
   new str[40],gConnectname[24];
   GetPlayerName(playerid,gConnectname,24);
   switch(reason)
   {
        case 0: format(str,sizeof(str),"%s has Timed Out!",gConnectname);
        case 1: format(str,sizeof(str),"%s has left the server.",gConnectname);
        case 2: format(str,sizeof(str),"%s has been kicked out the server."gConnectname);

   }
   SendClientMessageToAll(0xAFAFAFAA,str);
   return true;
}

you forgot to add gConnectname to the format thing :)

now some of my stuff:

Random Messages:

Up the top:
Code:
forward msgtimer();
new Help[][] =
{
    "Try \"/Commands\" for help.",
    "Spotted a hacker? read \"/help 2\".",
    "Don't use any hacks/cheats, you will be banned instantly!",
    "Don't ask to be an admin!",
    "English in mainchat, Use \"/pm\" to use Non-English",
    "Please don't use CAPS, you will be muted!",
    "Remember to obey the \"/rules\"!!",
    "Don't spawn-kill, you will be kicked!",
    "Spotted a cheater/hacker? use /report [ID] [Report].",
    "Don't door-camp (Shooting at doors) you will be kicked.",
    "Try \"/admins to see the online admins.",
    "Never ever report cheaters in main-chat.",
    "Remember to read the /rules!"

};

Under OnGameModeInit:

Code:
SetTimer("msgtimer",180000,1);

Somewhere except in another callback:

Code:
public msgtimer()
{
    SendClientMessageToAll(COLOR_YELLOW, Help[random(sizeof(Help))]);
}
You may want to change the messages to some of your own   ;)

/grove [playerid]
Code:
if(strcmp(cmd, "/grove", true) == 0)
{
new tmp[256];
tmp = strtok(cmdtext, idx);
new otherplayer = strval(tmp);
if(!strlen(tmp))
{
    SendClientMessage(playerid,0x33AA33AA,"USAGE: /grove [playerid]");
    return 1;
}
if(IsPlayerConnected(otherplayer))
{
    SetPlayerPos(otherplayer,2500.9519,-1668.9618,13.3554);
}
else
{
    SendClientMessage(playerid,0x33AA33AA,"Invalid ID");
}
return 1;
}
with this you need to define strtok into your script

Repair your vehicle with /repair
Code:
if (strcmp("/Repair", cmdtext, true) == 0)
{

if(!IsPlayerInAnyVehicle(playerid))
{
    SendClientMessage(playerid,COLOR_WHITE,"You're not in a vehicle!");
    return 1;
}
if(GetPlayerMoney(playerid) <= 9999)
{
    SendClientMessage(playerid,COLOR_GREEN,"You don't have $10,000 dollars to repair your vehicle");
    return 1;
}

new string[128];
new name[24];
GetPlayerName(playerid,name,24);
SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
format(string,sizeof(string),"%s (ID: %d) Has repaired his vehicle for $10,000 dollars!",name,playerid);
SendClientMessageToAll(COLOR_WHITE,string);

return 1;
}
"/rapair" costs 10 grand :)

EDIT:
Guide on good string sizes:

instead of having all your sizes 256 you can count up how many bytes each "SendClientMessage" is and add names if there included so for example:

Code:
new string[];
new name[24];
GetPlayerName(playerid,name, 24);
format(string,sizeof(string),"Hello %s your my friend",name);
SendClientMessage(playerid,0xAFAFAFAA,string);
i left the new string[]; empty.
now where gonna count the bytes to see what it should be: okay so lets count
Hello  your my friend = 21 bytes,we leave the %s alone, Note in every sentance there is an invisible NUL byte so instead of 21 it would be 22 so now we have counted 22
since we have a name, the size of the name is 24 so what is 22 + 24? it is 46 :) so now we change the
new string[]; to new string[46];
:)
also remember that the max string size for SendClientMessage is 128
Reply


Messages In This Thread
Useful Functions/Snippets/Commands - by Jay - 04-21-2008, 03:19 PM
Re: Useful Functions/Snippets/Commands - by Jay - 04-21-2008, 07:42 PM
Re: Useful Functions/Snippets/Commands - by Smoke - 04-23-2008, 06:50 AM
Re: Useful Functions/Snippets/Commands - by Jay - 04-23-2008, 04:54 PM
Re: Useful Functions/Snippets/Commands - by Smoke - 04-24-2008, 10:18 AM
Re: Useful Functions/Snippets/Commands - by Jay - 04-29-2008, 01:03 PM
Re: Useful Functions/Snippets/Commands - by Jay - 05-08-2008, 11:54 AM
Re: Useful Functions/Snippets/Commands - by Jay - 02-02-2009, 10:17 PM