Tutorial -> Convert 0.2x script to 0.3a
#1

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:


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);
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:
pawn Code:
public OnGameModeInit()
{
  SetDisabledWeapons(38,46,45,44);
  return 1;
}
Should now look like this:
pawn Code:
public OnGameModeInit()
{
  //SetDisabledWeapons(38,46,45,44);
  return 1;
}
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!
Reply
#2

nice, now we have a link to send the the noobs :]
Reply
#3

Updated and corrected.

I'm still thinking of other ways that 0.3a could disrupt a 0.2x server. I think with the 2nd rlease of 0.3a available, the CreatePickup virtual world issue is resolved.
Reply
#4

Good work, congratz.
Reply
#5

Good Job Joe.
Reply
#6

This tutorial is pointless, anyone retarded enough to need this has no business scripting.
Reply
#7

Quote:
Originally Posted by Raekwon
This tutorial is pointless, anyone retarded enough to need this has no business scripting.
Precisely why I put it here.

More tutorials = Less Stupid Question

and we all know how I feel about stupid questions.
Reply
#8

nice tutorial and very useful for newbies like me
Reply
#9

I did everything as it said but i get errors of undefined symbol recieverid for every one of them?
Reply
#10

Good work!
Reply
#11

Quote:
Originally Posted by 0ne
I did everything as it said but i get errors of undefined symbol recieverid for every one of them?
>.< Receiver is spelled wrong in some places.

Do CTRL+H then replace all 'recieverid' with 'receiverid'. That should fix your problem.

Fixed the tutorial.
Reply
#12

Worked, but now i get a warning which says The arguments of definition doesn't match

Code:
if(!strcmp(cmdtext[1],"pm",true,2))
	{
	  new receiverid = strval(cmdtext[4]);
  	new begintext = strval(cmdtext[4]," ");
		if(!cmdtext[3]||!cmdtext[4])return SendClientMessage(playerid,COLOR_WHITE,"Naudojimas: /pm [zaidejoid] [tekstas]");
		if(!IsPlayerConnected(receiverid))return SendClientMessage(playerid,COLOR_RED,"Neteisingas zaidejo ID!");
		if(!strlen(cmdtext[begintext]))return SendClientMessage(playerid,COLOR_WHITE,"Naudojimas: /pm [zaidejoid] [tekstas]");
		OnPlayerPrivmsg(playerid, receiverid, cmdtext[begintext]);
		return 1;
	}
the pm command's
Code:
new begintext = strval(cmdtext[4]," ");
points to it<<
Reply
#13

should have been 'strfind()+1' not 'strval()' I thought I fixed that earlier.


Fixed.
Reply
#14

Code:
C:\Documents and Settings\Administrator\Desktop\fr4_360-21_10_2009\gamemodes\IRP1.97.pwn(34) : warning 201: redefinition of constant/macro (symbol "MAX_PICKUPS")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:      7788 bytes
Code size:      766424 bytes
Data size:     2849628 bytes
Stack/heap size:   16384 bytes; estimated max. usage=5220 cells (20880 bytes)
Total requirements: 3640224 bytes

1 Warning.
Reply
#15

Add #undef MAX_PICKUPS above #define MAX_PICKUPS
Reply
#16

Quote:
Originally Posted by Raekwon
anyone retarded enough to need this has no business scripting.
To be fair, that's a LITTLE harsh, i'm sure you were a compleat noob at one point, as were we all. So to say that kind of thing, is a little silly IMO.

Nice tutorial though. It will definatly help people...
Reply
#17

Can you help me?
Have four error:

Code:
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26939) : warning 235: public function lacks forward declaration (symbol "OnPlayerPrivmsg")
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 017: undefined symbol "Mute"
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : warning 215: expression has no effect
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 001: expected token: ";", but found "]"
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 029: invalid expression, assumed zero
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#18

Quote:
Originally Posted by HsY
Can you help me?
Have four error:

Code:
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26939) : warning 235: public function lacks forward declaration (symbol "OnPlayerPrivmsg")
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 017: undefined symbol "Mute"
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : warning 215: expression has no effect
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 001: expected token: ";", but found "]"
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 029: invalid expression, assumed zero
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
place the lines of errors and the lines previous and the lines successors of the errors, please put in , to get better observation
Reply
#19

Is there simply a list of 0.2x -> 0.3a incompatibilities?
Reply
#20

Quote:
Originally Posted by TheNooB
Quote:
Originally Posted by HsY
Can you help me?
Have four error:

Code:
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26939) : warning 235: public function lacks forward declaration (symbol "OnPlayerPrivmsg")
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 017: undefined symbol "Mute"
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : warning 215: expression has no effect
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 001: expected token: ";", but found "]"
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : error 029: invalid expression, assumed zero
C:\Documents and Settings\DoDy\Desktop\scripturi\samp\gamemodes\LcS.pwn(26941) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
place the lines of errors and the lines previous and the lines successors of the errors, please put in , to get better observation
Code:
public OnPlayerPrivmsg(playerid, recieverid, text[])
{
  if(Mute[playerid] == 1)return 0;
  PlayerRespond[recieverid] = playerid;

  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);
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)