25.10.2009, 21:36
This tutorial was created to prevent stupid noobs from creating threads like "Hao duz I putted mai 0.2x script to runz on teh new serber?"
Although it seems I'm already too late. I'm going to explain this in the easiest way possible.
For this tutorial I'm going to convert the curse that all professional scripters hate, Public Enemy Number 1 A.K.A. The Godfather, originally authored by Astro (Denver).
Please note that the images are for placing references only, the actual code shown on them is incorrect
STEP 1:
First thing's first, download the new server package from the SA-MP main website on this page
http://www.SA-MP.com/Download.php
Choose either Linux or Windows, for this tutorial I'll be using Windows.
You open it with a RAR extractor, a good one is at www.RarLabs.com
Copy all files into a new folder or into your existing server folder.
Assure that your ".pwn" file A.K.A. your script, is in the gamemodes folder
Go to your "pawno" folder and open "pawno.exe" to insure that the 0.3a include files are being used instead of any old server includes.
Open your ".pwn" script
Now if you try to compile you'll get atleast 1 error
This error is caused by the removal of the native callback "OnPlayerPrivmsg"
It was removed because you could just as easily script it in yourself, which I will show you how to do now
First you have to create the callback with a "forward" command line, the most common spot for forwards is at the top of the script underneath the "define" lines.
The call back should have these parameters
OnPlayerPrivmsg(playerid,receiverid,text[]);
"playerid" is the player sending the PM, "receiverid" is the player receiving the PM, and "text[]" is what is being sent from playerid to receiverid
After that we have to create the command portion.
STEP 2:
This command will be placed under the "OnPlayerCommandText" callback with the rest of the commands (assuming you have any)
I'll explain it line by line.
if(!strcmp(cmdtext[1],"pm",true,2))
This compares what the player typed in to see if it matches up with "/pm"
"cmdtext" is the command the player typed in, I have added "[1]" because "[ 0 ]" is the first character, which is of course the back-slash "/", It wouldn't call the OnPlayerCommandText callback unless that was the first character
if(!cmdtext[3]||!cmdtext[4])return SendClientMessage(playerid,0xF8DA07FF,"USAGE: /pm [playerid] [text]");
The if statement is seeing if the 3rd and 4th characters in "cmdtext" exists, these would be the space immediately after "/pm " and the ID number the player puts in. "/pm 3"
If they don't exist that means the player didn't type one or the other, and for the command to work the player has to type both.
new receiverid = strval(cmdtext[4]);
This line is creating a standard integer variable to save the value of the spot immediately after "/pm ", it should be the ID that the player wants to send a PM to
if(!IsPlayerConnected(receiverid))return SendClientMessage(playerid,0xF8DA07FF,"Invalid Player ID!");
this line checks to see if the receiverid is connected to the server, and if it isn't returns a message
new begintext = strfind(cmdtext[4]," ")+1+4;
This is creating a new standard integer variable and is finding the exact character spot that the player's message begins on, located after the ID the player is wanting to send it to.
the +1 is there because the number returned is before the character strfind is looking for
the +4 is there because the search started on character 4 and needs to make up for that absence.
if(!strlen(cmdtext[begintext]))return SendClientMessage(playerid,0xF8DA07FF,"USAGE: /pm [playerid] [text]");
This line is determing if the player typed anything in for the message, if they don't it returns a message
OnPlayerPrivmsg(playerid, receiverid, cmdtext[begintext]);
Now we call the callback that we're re-creating giving the playerid, the receiverid, and the message
return 1;
this line ends the command with a positive note, if it's 0 then it gives a "SERVER: unrecognized command" message
STEP 3:
Remove the callback "OnPlayerInfoChange"
Not sure what it does, but if it's on your script, just do a "CTRL+F" search and delete it's entirety
STEP 4:
Since as of right now "/pm" does nothing, we're gonna have to fix it!
Inside the OnPlayerPrivmsg callback add the following code below any existing code, but above the return 1;:
Like so:
Please note that the filterscript labeled as 'base.amx' also has it's own "/pm" command and will run along-side this one.
STEP 5:
Now we have to remove the SetDisabledWeapons function because it is no longer supported in SA-MP 0.3
Do a CTRL+F search for it in your pawn editor and in every instance of it, place to '/' in front of it.
This creates a 'comment' line which means it's only seeable in the '.pwn' file and it won't compile in the final product.
Example:
Should now look like this:
Commenting it out like this allows us to easily place it back in if the function is ever returned in a later version of SA-MP.
FINISHED!
If you're still having troubles, it might be your script. Remember, 0.3 comes with it's own vehicle streamer so there's no need for another one!
Although it seems I'm already too late. I'm going to explain this in the easiest way possible.
For this tutorial I'm going to convert the curse that all professional scripters hate, Public Enemy Number 1 A.K.A. The Godfather, originally authored by Astro (Denver).
Please note that the images are for placing references only, the actual code shown on them is incorrect
STEP 1:
First thing's first, download the new server package from the SA-MP main website on this page
http://www.SA-MP.com/Download.php
Choose either Linux or Windows, for this tutorial I'll be using Windows.
You open it with a RAR extractor, a good one is at www.RarLabs.com
Copy all files into a new folder or into your existing server folder.
Assure that your ".pwn" file A.K.A. your script, is in the gamemodes folder
Go to your "pawno" folder and open "pawno.exe" to insure that the 0.3a include files are being used instead of any old server includes.
Open your ".pwn" script
Now if you try to compile you'll get atleast 1 error
This error is caused by the removal of the native callback "OnPlayerPrivmsg"
It was removed because you could just as easily script it in yourself, which I will show you how to do now
First you have to create the callback with a "forward" command line, the most common spot for forwards is at the top of the script underneath the "define" lines.
The call back should have these parameters
OnPlayerPrivmsg(playerid,receiverid,text[]);
"playerid" is the player sending the PM, "receiverid" is the player receiving the PM, and "text[]" is what is being sent from playerid to receiverid
After that we have to create the command portion.
STEP 2:
pawn Code:
if(!strcmp(cmdtext[1],"pm",true,2))
{
if(!cmdtext[3]||!cmdtext[4])return SendClientMessage(playerid,0xF8DA07FF,"USAGE: /pm [playerid] [text]");
new receiverid = strval(cmdtext[4]);
if(!IsPlayerConnected(receiverid))return SendClientMessage(playerid,0xF8DA07FF,"Invalid Player ID!");
new begintext = strfind(cmdtext[4]," ")+1+4;
if(!strlen(cmdtext[begintext]))return SendClientMessage(playerid,0xF8DA07FF,"USAGE: /pm [playerid] [text]");
OnPlayerPrivmsg(playerid, receiverid, cmdtext[begintext]);
return 1;
}
This command will be placed under the "OnPlayerCommandText" callback with the rest of the commands (assuming you have any)
I'll explain it line by line.
if(!strcmp(cmdtext[1],"pm",true,2))
This compares what the player typed in to see if it matches up with "/pm"
"cmdtext" is the command the player typed in, I have added "[1]" because "[ 0 ]" is the first character, which is of course the back-slash "/", It wouldn't call the OnPlayerCommandText callback unless that was the first character
if(!cmdtext[3]||!cmdtext[4])return SendClientMessage(playerid,0xF8DA07FF,"USAGE: /pm [playerid] [text]");
The if statement is seeing if the 3rd and 4th characters in "cmdtext" exists, these would be the space immediately after "/pm " and the ID number the player puts in. "/pm 3"
If they don't exist that means the player didn't type one or the other, and for the command to work the player has to type both.
new receiverid = strval(cmdtext[4]);
This line is creating a standard integer variable to save the value of the spot immediately after "/pm ", it should be the ID that the player wants to send a PM to
if(!IsPlayerConnected(receiverid))return SendClientMessage(playerid,0xF8DA07FF,"Invalid Player ID!");
this line checks to see if the receiverid is connected to the server, and if it isn't returns a message
new begintext = strfind(cmdtext[4]," ")+1+4;
This is creating a new standard integer variable and is finding the exact character spot that the player's message begins on, located after the ID the player is wanting to send it to.
the +1 is there because the number returned is before the character strfind is looking for
the +4 is there because the search started on character 4 and needs to make up for that absence.
if(!strlen(cmdtext[begintext]))return SendClientMessage(playerid,0xF8DA07FF,"USAGE: /pm [playerid] [text]");
This line is determing if the player typed anything in for the message, if they don't it returns a message
OnPlayerPrivmsg(playerid, receiverid, cmdtext[begintext]);
Now we call the callback that we're re-creating giving the playerid, the receiverid, and the message
return 1;
this line ends the command with a positive note, if it's 0 then it gives a "SERVER: unrecognized command" message
STEP 3:
Remove the callback "OnPlayerInfoChange"
Not sure what it does, but if it's on your script, just do a "CTRL+F" search and delete it's entirety
STEP 4:
Since as of right now "/pm" does nothing, we're gonna have to fix it!
Inside the OnPlayerPrivmsg callback add the following code below any existing code, but above the return 1;:
pawn Code:
new pname[MAX_PLAYER_NAME];
new rname[MAX_PLAYER_NAME];
new tmpstring[256];
GetPlayerName(receiverid,rname,sizeof(rname));
GetPlayerName(playerid,pname,sizeof(pname));
format(tmpstring,sizeof(tmpstring),"to %s(%d): %s",rname,receiverid,text);
SendClientMessage(playerid,0xFFCC22FF,tmpstring);
format(tmpstring,sizeof(tmpstring),"from %s(%d): %s",pname,playerid,text);
SendClientMessage(receiverid,0xFFFF22FF,tmpstring);
Please note that the filterscript labeled as 'base.amx' also has it's own "/pm" command and will run along-side this one.
STEP 5:
Now we have to remove the SetDisabledWeapons function because it is no longer supported in SA-MP 0.3
Do a CTRL+F search for it in your pawn editor and in every instance of it, place to '/' in front of it.
This creates a 'comment' line which means it's only seeable in the '.pwn' file and it won't compile in the final product.
Example:
pawn Code:
public OnGameModeInit()
{
SetDisabledWeapons(38,46,45,44);
return 1;
}
pawn Code:
public OnGameModeInit()
{
//SetDisabledWeapons(38,46,45,44);
return 1;
}
FINISHED!
If you're still having troubles, it might be your script. Remember, 0.3 comes with it's own vehicle streamer so there's no need for another one!