Help making an include -
gamer931215 - 01.09.2010
Hi guys, i want to make my first include, its nothing special and could be integrated in the gamemode too. But i also want to learn to make includes so thats why i started something pretty simple (i thaight).
Well the problem is, i have just a few line of codes and pawno is now already
crashing !
Is there anything that i should know about an include that is wrong in the following code ?
pawn Код:
#include <a_samp>
new pVehicle[MAX_VEHICLES];
new Warned[MAX_PLAYERS];
native CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2);
public CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2);
{
new v = AddStaticVehicle(id,x,y,z,r,c1,c2);
pVehicle[v] = pName;
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER)
{
new pName[32];
GetPlayerName(playerid,pName,sizeof pName);
if (pName != pVehicle[GetPlayerVehicleID(playerid)]) {
RemovePlayerFromVehicle(playerid);
//warn player, and on 2nd time kill etc
}
}
return 1;
}
Remember its not finished! only if its now already crashing, im sure im already doing
something wrong so thats why i ask for help.
And also
does OnPlayerStateChange work in an include ?, or must i made it an function that needs to be called at OnPlayerStateChange in the gamemode/filterscript ?
Anyways i couldnt find an tutorial or wiki thing for this, maybe if you can find it, you can help me with posting that link too!
Re: Help making an include -
DaneAMattie - 01.09.2010
Quote:
Originally Posted by gamer931215
Hi guys, i want to make my first include, its nothing special and could be integrated in the gamemode too. But i also want to learn to make includes so thats why i started something pretty simple (i thaight).
Well the problem is, i have just a few line of codes and pawno is now already crashing !
Is there anything that i should know about an include that is wrong in the following code ?
pawn Код:
#include <a_samp> new pVehicle[MAX_VEHICLES]; new Warned[MAX_PLAYERS];
native CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2);
public CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2); { new v = AddStaticVehicle(id,x,y,z,r,c1,c2); pVehicle[v] = pName; return 1; }
public OnPlayerStateChange(playerid, newstate, oldstate) { if (newstate == PLAYER_STATE_DRIVER) { new pName[32]; GetPlayerName(playerid,pName,sizeof pName); if (pName != pVehicle[GetPlayerVehicleID(playerid)]) { RemovePlayerFromVehicle(playerid); //warn player, and on 2nd time kill etc } } return 1; }
Remember its not finished! only if its now already crashing, im sure im already doing something wrong so thats why i ask for help.
And also does OnPlayerStateChange work in an include, or must i made it an function that needs to be called at OnPlayerStateChange in the gamemode/filterscript ?
Anyways i couldnt find an tutorial or wiki thing for this, maybe if you can find it, you can help me with posting that link too!
|
Includes are just pawn code in notepad, save it as .inc
Re: Help making an include -
gamer931215 - 01.09.2010
Quote:
Originally Posted by DaneAMattie
Includes are just pawn code in notepad, save it as .inc
|
They work a little bit different i guess, with natives etc, else my pawno (compiler) wont crash :S
Edit: i mean the gamemode that crashes using the include, i know i dont have to compile includes...
Re: Help making an include -
gamer931215 - 01.09.2010
Anyone ?
Re: Help making an include -
[XST]O_x - 01.09.2010
You've put ; in the end of the public callback,which may cause crashes.
pawn Код:
public CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2);
Should be
pawn Код:
public CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2)
And,pName is a string,so it must contain square brackets at the very least.
pawn Код:
public CreatePrivateVehicle(pName[],id,x,y,z,r,c1,c2)
And,I don't believe you can compare strings within only equal signs,use
strcmp for that.
Also,pVehicle is a string,so the variable should contain cells.
pawn Код:
new pVehicle[MAX_VEHICLES][38];
And,another error I found,you should format pVehicle,not define it with '='.
Like this:
pawn Код:
public CreatePrivateVehicle(pName[],id,x,y,z,r,c1,c2)
{
new v = AddStaticVehicle(id,x,y,z,r,c1,c2);
format(pVehicle[v],38,"%s",pName);
return 1;
}
And,you can't create natives just like that,they must be commented.
Therefore you will also need to forward your function.
Re: Help making an include -
Vince - 01.09.2010
You cannot create natives in simple includes (if you write a plugin you can, though), but you can comment them and they'll still show in the right hand side of Pawno.
Re: Help making an include -
gamer931215 - 01.09.2010
Thanks for the help guys, working on it now.
Anyways i knew it was strcmp, but forgot :P hehe worked more with strings.
Re: Help making an include -
gamer931215 - 01.09.2010
Quote:
Originally Posted by [XST]O_x
You've put (..)
|
Quote:
Originally Posted by Vince
You cannot create (...)
|
Thanks for the help guys ! i got 4 warnings so i asked also someone on msn (forgot the goddamn
Float :P could know it...)
Anyways it works !
http://pastebin.com/KtRRRRKU
Any optimalisation or tips/ideas ?
Im not gonna release it for real i think, since its my first include and VERY simple xD however i am planning to create an DestroyPcar function, etc (to reset it for the vehicleID and those standard functions which the normal one has too)
Re: Help making an include -
LarzI - 01.09.2010
It is very simple, indeed. But for noobs, that could be pretty useful.
I'd say release it, you have nothing to lose, really.
Re: Help making an include -
gamer931215 - 02.09.2010
Quote:
Originally Posted by LarzI
It is very simple, indeed. But for noobs, that could be pretty useful.
I'd say release it, you have nothing to lose, really.
|
Your right
I posted the full release here:
https://sampforum.blast.hk/showthread.php?tid=173359
Anyways since nobody was online anymore i couldnt test the lend & return system (only at myself), but i think everything is working correctly