Gamemode based in includes
#1

Is it possible to make a gamemode with includes? I mean, for example, put some command into an include and then include it in the gm?
Is it possible to put an include into another include? For example, I'm writing an include, can I include one? Or how do I make that?
Reply
#2

Yes it's possible, for example..

You have your main pawn file which is called "roleplay.pwn", you could then have, let's say a commands file called "roleplay_commands.pwn" which would be saved in the gamemodes folder and included in the "roleplay.pwn" file like this,

pawn Code:
#include "roleplay_commands.pwn"
Reply
#3

You should look at GrandLarceny, as it does some of this in its setup.
Reply
#4

Includes are not saved in the gamemodes folder, they are saved in the "pawno\includes" folder, where all the other samp includes are located.
You can create a directory there, in which you save your includes.

PHP Code:
#include <MyGamemode\Defines.inc> // Setup all #define statements and some other stuff
#include <MyGamemode\Declarations.inc> // Holds all enums and related arrays

#include <MyGamemode\PlayerFunctions.inc> // Holds all player functions
#include <MyGamemode\VehicleFunctions.inc> // Holds all vehicle functions
#include <MyGamemode\SupportFunctions.inc> // Holds all support function

#include <MyGamemode\Housing.inc> // Holds the entire housing system
#include <MyGamemode\Speedometer.inc> // Holds the Speedometer functions
#include <MyGamemode\OnGameModeInitExit.inc> // Holds OnGameModeInit and OnGameModeExit
#include <MyGamemode\Commands.inc> // Holds all commands
#include <MyGamemode\GlobalTimers.inc> // Holds all global timers

#include <MyGamemode\OnPlayerConnectDisconnect.inc> // Holds all functions related to logging in players and disconnecting them
#include <MyGamemode\OnDialogResponse.inc> // Holds the OnDialogResponse callback
#include <MyGamemode\TemporaryCommands.inc> // Holds all temporary commands 
These files are located inside "pawno\includes\MyGamemode".
Also, includes have the extension ".inc", not ".pwn".
Reply
#5

Yes, it's perfectly possible, and also it is a way of doing a modular setup for your gamemode.
However I do encourage you to read more on modular setups for gamemode in the forums (One of them is Scavenge And Survive by Southclaws) so you wouldn't do it like AmigaBlizzard thinks is right, because thats a terrible setup.

Quote:
Originally Posted by AmigaBlizzard
View Post
Includes are not saved in the gamemodes folder, they are saved in the "pawno\includes" folder, where all the other samp includes are located.
You can create a directory there, in which you save your includes.

PHP Code:
#include <MyGamemode\Defines.inc> // Setup all #define statements and some other stuff
#include <MyGamemode\Declarations.inc> // Holds all enums and related arrays
#include <MyGamemode\PlayerFunctions.inc> // Holds all player functions
#include <MyGamemode\VehicleFunctions.inc> // Holds all vehicle functions
#include <MyGamemode\SupportFunctions.inc> // Holds all support function
#include <MyGamemode\Housing.inc> // Holds the entire housing system
#include <MyGamemode\Speedometer.inc> // Holds the Speedometer functions
#include <MyGamemode\OnGameModeInitExit.inc> // Holds OnGameModeInit and OnGameModeExit
#include <MyGamemode\Commands.inc> // Holds all commands
#include <MyGamemode\GlobalTimers.inc> // Holds all global timers
#include <MyGamemode\OnPlayerConnectDisconnect.inc> // Holds all functions related to logging in players and disconnecting them
#include <MyGamemode\OnDialogResponse.inc> // Holds the OnDialogResponse callback
#include <MyGamemode\TemporaryCommands.inc> // Holds all temporary commands 
These files are located inside "pawno\includes\MyGamemode".
Also, includes have the extension ".inc", not ".pwn".
Thats absolutely wrong, you can have those includes in your gamemode folder, and also with .pwn extension, you just have to include them like:
PHP Code:
#include "something.pwn" 
Reply
#6

Why would my approach be terrible?
It works for me.

Btw, the default samp includes are managed in a similar way.
Defines and generic functions in one include (a_samp.inc), object functions in another (a_objects.inc), player functions in a third include (a_players.inc), vehicle functions in a 4th include (a_vehicles.inc), SQL functions in a 5th include (a_sampdb.inc) and so on.
Reply
#7

I wouldn't pollute the pawno/include folder either. I keep this folder exclusively for the default SA-MP API. I create a "source" folder in the server root and I store everything in there. Since the include directive accepts a path you can also go up in the directory tree. So if your main gamemode is in the gamemodes directory you can include like this:
PHP Code:
#include "..\source\libraries\third_party\a_mysql.inc" 
Reply
#8

GTO was a good gamemode that used includes to make the entire setup... Worked well until it was broken, then it was a nightmare to actually fix and debug.
Reply
#9

Quote:
Originally Posted by AmigaBlizzard
View Post
Why would my approach be terrible?
It works for me.

Btw, the default samp includes are managed in a similar way.
Defines and generic functions in one include (a_samp.inc), object functions in another (a_objects.inc), player functions in a third include (a_players.inc), vehicle functions in a 4th include (a_vehicles.inc), SQL functions in a 5th include (a_sampdb.inc) and so on.
Yes, it works for you, but is a terrible habit that you shouldn't promote, well you like it? great, you like using dini and main callback+strcmp for CMDs? great, and it works. doesn't mean it's the proper or best approach.
Say I was to change a variable in vehicle enum from Health to vHealth for more clarity, how many files should I change in your approach? 9.. 19... 900, how can I do that in a proper approach? a simple find and replace in one file, even more properly with a regex to find VehI[ - ][Health] if Health is used on other enums too.

No, sa-mp isn't managed in "the same way"
it's managed in the proper way, as in it's categorized their code based on their function, because sa-mp is only providing tools, you see it as "divided by functions" or whatsoever.

Apply the same to the logic, and you'd be having everything about the vehicle in one include, everything about houses in another and so on.
Reply
#10

Changing a variable-name in multiple files isn't a problem if you use Notepad++.
I have all the files open at the same time and you can simply search and replace in all open files at once.

I admit that I cannot have code for the housing system (for example) all in one file, because everything in my gamemode is mixed up.
Alot of code uses something from another system as well.
Effectively splitting code isn't really possible.

In the end, I might put all code into one huge file, but it's always easy to have several files open at once and switch between them instead of having everything in one file during coding and scrolling all the time.

Too bad we don't have true objects to code with, with constructors and destructors and class-functions etc.
You can still write small functions that can be used to set/get data from an array with enums, then you don't need to use variable-names everywhere.
Then the variable names inside enums are only used by the set/get functions and nowhere else.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)