SA-MP Forums Archive
include issue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: include issue (/showthread.php?tid=659597)



include issue - YenTy - 08.10.2018

Hi,

My problem is that I cannot #include "whatevername.pwn" different files (cmds in folder) to main gamemode because one that is under first is not working. I've shifted them and only code of one on the top is runnig. I'm ussing y_hook if it helps to answer what can cause the issue. Any suggestions?


Re: include issue - YenTy - 13.10.2018

Bump. Anyone have meet with this? I can add that if I put all comands to main gamamode then they're fine but any includes is not working further than one. Only for commands - wth? Any others includes containing scripts works without issues.


Re: include issue - v1k1nG - 13.10.2018

Let me suggest you, if you are new to this, start from 0, not from difficult scenarios.


Re: include issue - YenTy - 13.10.2018

I am not a new to this. Maybe my english is not fluent, yea it's not my native language. Anyway.. Idk, maybe Pawn.CMD isn't working properly because I cannot include more than one file.pwn with commands. One more line "#include <Pawn.CMD>" in every file is not helping.


Re: include issue - YenTy - 13.10.2018

In gamemode:

PHP код:
#include <a_samp>                        
#include <sscanf2>
#include <strlib>                        
#include <YSI\y_hooks>                
#include <a_mysql>                        
#include <Pawn.RakNet>                                    
#include <Pawn.CMD>                        
#include <SHA256>                        
#include <DialogCenter>    
#include <geolocation>                    
#include <YSI\y_iterate>                
#include "includes/main/definitions.pwn"
#include "includes/main/globalVars.pwn"
#include "includes/main/enums.pwn"
#include "includes/main/timers.pwn"
#include "includes/main/customFuncs.pwn"
#include "includes/main/dbConnection.pwn"
#include "includes/users/--.pwn"
#include "includes/users/--.pwn"
#include "includes/users/--.pwn"
#include "includes/users/--.pwn"
#include "includes/users/--.pwn"
#include "includes/characters/--.pwn"
#include "includes/characters/--.pwn"
#include "includes/characters/--.pwn"
#include "cmdHandler.pwn" // <-- there are cmds that are includes 
cmdHandler.pwn
PHP код:
forward OnPlayerCommandReceived(playeridcmd[], params[], flags);
public 
OnPlayerCommandReceived(playeridcmd[], params[], flags)
{
    if(
users[playerid][uStatus] == || characters[playerid][cStatus] == 0)
    {
        return 
0;
    }
    if(
lastCommandTime[playerid] > gettime())
    {
        return 
0;
    }
    else
    {
        
lastCommandTime[playerid] = gettime()+1;
        return 
1;
    }
}
// characters
#include "includes/characters/cmds/sv.pwn"
#include "includes/characters/cmds/s.pwn" 
s.pwn
PHP код:
CMD:s(playeridparams[])
{
    new 
text[128];
    if(
sscanf(params"s[128]"text))
    {
        return 
SendClientMessage(playerid, -1"{d9d9d9}[{00cc66}Use{d9d9d9}]: /s message");
    }
    else
    {
        
_sendLocalScream(playeridtext);
        return 
1;
    }

PHP код:
CMD:sv(playeridparams[])
{
    if(
characters[playerid][cLastSave] > gettime())
    {
        new 
message[256];
        new 
minutes = (characters[playerid][cLastSave]-gettime())/MINUTE;
        new 
seconds = (characters[playerid][cLastSave]-gettime())%MINUTE;
        
// some calculations, format
        
return SendClientMessage(playerid, -1message);
    }
    else
    {
        
characters[playerid][cLastSave] = gettime()+(MINUTE*10);
        
saveCharacterData(playerid);
        return 
SendClientMessage(playerid, -1"DEBUG EXIT");
    }




Re: include issue - YenTy - 13.10.2018

Whatever will happen there it seems that it does not relevant. These includes are responsible for managing login, checking ban, characters, blocks, spawn etc. I say not relevant because I can put this two command files on the top, right under dbConnection or even YSI\y_iterate if not defined variables and there, still - only one (first) included cmd is working. Here are examples I've tried to solve the problem with:

1 - https://pastebin.com/8Br81qGQ
2 - https://pastebin.com/WTwzBcjg


Re: include issue - KinderClans - 13.10.2018

Even tho i don't like modular scripting, when you reach almost 1000+ dynamic objects in your map, you can't put them all in a single gamemode.

Would be confusing and stupid. So i work in this way:

Main gamemode:

pawn Код:
#include "/Objects/bank.pwn"
In bank.pwn:

pawn Код:
stock CreateBankObjects()
{
//Code objects
}
Then, on the main gamemode, at OnGameModeInit:

pawn Код:
CreateBankObjects();
To call them.

That's how i do. Another example, random spawns:

This is LEO's random spawn coordinates:

pawn Код:
new Float:RandomCopSpawns[][4]=
{
//Coordinates
}
And again on main gamemode, to call them:

pawn Код:
new randi = random(sizeof(RandomCopSpawns));
SetPlayerPos(playerid, RandomCopSpawns[randi][0],RandomCopSpawns[randi][1],RandomCopSpawns[randi][2]);
Hope you got the idea.

I just noticed a thing (tho i don't need to do it), if in a separate .pwn you put any default callback (such as OnPlayerConnect, OnPlayerDeath and so on.) and meantime you have that callback in your main gamemode, script won't compile because callback X is already defined.

However don't need this. I use external .pwn files just to store stocks, custom callbacks, objects and everything NOT related to default Sa-Mp callbacks. Then i call them in my gamemode whenever i want.


Re: include issue - YenTy - 13.10.2018

Quote:

when you reach almost 1000+ dynamic objects in your map, you can't put them all in a single gamemode.
.. #include "/Objects/bank.pwn" ..

If I'm not wrong, it will compile as one file where all objects that are created will contained in main gamemode, and just included to be more readable for human. Anyway, I'm not used any object so far. I got the idea, but I don't know how it could help solve my problem, which is: commands doesn't include themselves because it's shows that there can exist only one file filled with cmds, at least it seems to me.

Quote:

However don't need this. I use external .pwn files just to store stocks, custom callbacks, objects and everything NOT related to default Sa-Mp callbacks. Then i call them in my gamemode whenever i want.

I did it too, moreover I'm using y_hook to avoid "callback X is already defined" error.


Re: include issue - YenTy - 15.10.2018

Also doesn't working:
pawn Код:
#include <a_samp>                      
#include <sscanf2>                 
#include <Pawn.CMD>                 // Seems to not working properly

#include "includes/characters/cmds/k.pwn"
#include "includes/characters/cmds/k2.pwn"