SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 01/09/2010, 01:57 PM   #1
gamer931215
High-roller
 
gamer931215's Avatar
 
Join Date: Feb 2010
Location: That box in front of your house stealing your wifi.
Posts: 1,090
Reputation: 322
Default Help making an include

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 Code:
#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!
__________________

Thanks to Zh3r0 for this awesome signature!
gamer931215 is offline  
Old 01/09/2010, 02:05 PM   #2
DaneAMattie
Huge Clucker
 
DaneAMattie's Avatar
 
Join Date: Jan 2010
Location: Netherlands
Posts: 284
Reputation: 0
Default Re: Help making an include

Quote:
Originally Posted by gamer931215 View Post
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 Code:
#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
__________________
Releases:
DaneAMattie is offline  
Old 01/09/2010, 02:06 PM   #3
gamer931215
High-roller
 
gamer931215's Avatar
 
Join Date: Feb 2010
Location: That box in front of your house stealing your wifi.
Posts: 1,090
Reputation: 322
Default Re: Help making an include

Quote:
Originally Posted by DaneAMattie View Post
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...
__________________

Thanks to Zh3r0 for this awesome signature!

Last edited by gamer931215; 01/09/2010 at 02:25 PM.
gamer931215 is offline  
Old 01/09/2010, 02:24 PM   #4
gamer931215
High-roller
 
gamer931215's Avatar
 
Join Date: Feb 2010
Location: That box in front of your house stealing your wifi.
Posts: 1,090
Reputation: 322
Default Re: Help making an include

Anyone ?
__________________

Thanks to Zh3r0 for this awesome signature!
gamer931215 is offline  
Old 01/09/2010, 02:27 PM   #5
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,960
Reputation: 94
Default Re: Help making an include

You've put ; in the end of the public callback,which may cause crashes.
pawn Code:
public CreatePrivateVehicle(pName,id,x,y,z,r,c1,c2);
Should be
pawn Code:
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 Code:
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 Code:
new pVehicle[MAX_VEHICLES][38];

And,another error I found,you should format pVehicle,not define it with '='.
Like this:
pawn Code:
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.

Last edited by [XST]O_x; 01/09/2010 at 02:40 PM.
[XST]O_x is offline  
Old 01/09/2010, 02:39 PM   #6
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,068
Reputation: 2655
Default Re: Help making an include

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.
__________________
Vince is offline  
Old 01/09/2010, 05:09 PM   #7
gamer931215
High-roller
 
gamer931215's Avatar
 
Join Date: Feb 2010
Location: That box in front of your house stealing your wifi.
Posts: 1,090
Reputation: 322
Default Re: Help making an include

Thanks for the help guys, working on it now.

Anyways i knew it was strcmp, but forgot :P hehe worked more with strings.
__________________

Thanks to Zh3r0 for this awesome signature!
gamer931215 is offline  
Old 01/09/2010, 06:10 PM   #8
gamer931215
High-roller
 
gamer931215's Avatar
 
Join Date: Feb 2010
Location: That box in front of your house stealing your wifi.
Posts: 1,090
Reputation: 322
Default Re: Help making an include

Quote:
Originally Posted by [XST]O_x View Post
You've put (..)
Quote:
Originally Posted by Vince View Post
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)
__________________

Thanks to Zh3r0 for this awesome signature!
gamer931215 is offline  
Old 01/09/2010, 06:16 PM   #9
LarzI
High-roller
 
LarzI's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 2,628
Reputation: 136
Default Re: Help making an include

It is very simple, indeed. But for noobs, that could be pretty useful.
I'd say release it, you have nothing to lose, really.
LarzI is offline  
Old 01/09/2010, 06:26 PM   #10
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,960
Reputation: 94
Default Re: Help making an include

I didn't get the point of Pcar_OnPlayerStateChange.
As newstate,is yet an unknown variable to Pawno,and then you're checking if the variable 'newstate' (Which Pawno defines only as a variable with a previously used name,not the real 'newstate') is equal to PLAYER_STATE_DRIVER which is defined in 'a_samp.inc' as 2. So basically,you're checking if the variable(which is stocked) 'newstate' 's value equals to 2,while it's value is yet no defined anywhere.
And when are those functions called?
[XST]O_x is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FS+ Include]YossI's Health include GiP_YossI Filterscripts 10 17/04/2011 05:15 PM
Help me a include! mYzCorleone Help Archive 4 21/07/2010 06:06 AM
[HELP] About #include boynumber5 Help Archive 1 28/03/2010 03:04 PM
Need an Include Mark k Help Archive 4 20/12/2009 11:03 AM
making your script to upload files wich include vehicles, objects etc. boelie Help Archive 4 15/09/2009 09:50 AM


All times are GMT. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.