[Tutorial] How to make a gamemode from scratch
#1

Hi. Again, an usefull tutorial by me
I'll explain you how to make a gamemode from scratch - Probably only for the beginners :')
Before starting I have a little tip. If you never made a gamemode yourself, or if you're a beginner, I recommend you to make a freeroam gamemode - That's the easiest gamemode type (I think).
Let's start!

The most people would ask: "Where should/must I begin" or "What do I have to make when?".
I won't answer them . Actually, if you make a gamemode, you need to ask yourself questions!
1) What for a gamemode do I want?
2) What do I want included in the gamemode?
That are the most basic questions. You need to know that before you're gonna make anything! If you're making a gamemode, but if you don't know what you want, you won't come far :/
I'll give an example of the questions (+answers).

Question 1:
Let's say I want a freeroam gamemode. For this you only need to place vehicles and some important stuff (basic stuff, scroll down)
Now I know that I need to place vehicles (random). It's also usefull to add random spawns, handy teleports and a house system

Question 2:
For a basic gamemode, a player system is handy
Know I the following things:
* Add vehicles
* Add random spawns
* Add 'usefull' teleports
* Add an (easy) house system
* Add an player system

That's a begin! The most basic things are: VEHICLES, USER SYSTEM, (random) SPAWNS, USER CLASSES

When you're gonna start making a gamemode, open pawno and press CTRL + N. You'll get a page with alot of callbacks.
You can remove all this callbacks! (unless if you don't know all of them. Leave them if you wanna use it later, but I always remove them 'cuz I don't use the most of them!)
Start including includes This's how it's being used:
pawn Код:
#include <FILENAME>
The "FILENAME" is included in your {pawno}/includes folder. It needs to have the extension .inc. When including, you won't need to add '.inc'.
So, #include <file> instead of #include <file.inc>. This'll work, but it costs A BIT diskspace (without .inc is looks better). You can also use #include "file" instead of the <> for the parent directory.
So you can also add an includes map in your SAMP map... Example:
[map "SAMP"]
--[map "PAWNO"]
----[map "includes"]
----[/map]
--[/map]
--[map "includes"]
--[/map]
[/map]
With #include "../includes/{file}" you'll use an include from the "SAMP/includes" folder instead of "SAMP/pawno/includes"!
NOTE: Always include a_samp! That includes all the standard functions!
pawn Код:
#include <a_samp>
After this, you can add colours. These are more clearer when you use SendClientMessage (e.d)... Example!!!
SendClientMessageToAll(0xFFFFFFFF, "Hello world!"); looks less clearer then SendClientMessageToAll(COLOR_WHITE, "Hello world!");. Also, if you used some color codes in client messages instead of the defines, you need to change it all (or use CTRL+H ^^). But with defined, you only have to change one thing, fast! I recommend you using #define.
It works like this:
pawn Код:
#define {DEFINE} {INFO}
You can define coulors, texts and more. For texts you need to use parentheses! (").
BAD EXAMPLE:
pawn Код:
#define HELLO_WORLD Hello World!
GOOD EXAMPLE:
pawn Код:
#define HELLO_WORLD "Hello World!"
About the colours; It's almost the same as HEX format. You need to put 0x in front of it, and ALPHA behind it!.
The color white in HTML (HEX) is this: FFFFFF. So, in SA:MP it would be 0xFFFFFFFF. How lower the ALPHA is, how less visible it'll be!
The most nice alpha is "AA". It's also the very best for the color gray (my opinion). I'll give you some standard colors!
pawn Код:
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_RED 0xFF0000AA
#define COLOR_GREEN 0x00FF00AA
#define COLOR_BLUE 0x0000FFAA
#define COLOR_GRAY 0xAFAFAFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_LIGHTBLUE 0x0AFFFFAA
#define COLOR_PURPLE 0xFF00FFAA
#define COLOR_ORANGE 0xFFBB00AA
And I also have a tip: Use TABS after defines (#define {DEFINE}_TAB_{INFO}). Putt them all on one line. That makes it also clearer. Another example :')
pawn Код:
#define COLOR_WHITE             0xFFFFFFAA
#define COLOR_RED               0xFF0000AA
#define COLOR_GREEN             0x00FF00AA
#define COLOR_BLUE              0x0000FFAA
#define COLOR_GRAY              0xAFAFAFAA
#define COLOR_YELLOW            0xFFFF00AA
#define COLOR_LIGHTBLUE         0x0AFFFFAA
#define COLOR_PURPLE            0xFF00FFAA
#define COLOR_ORANGE            0xFFBB00AA
You see? This is more clearer and easier to find something (again my opinion).
You can find more about it on ****** his tutorial: https://sampforum.blast.hk/showthread.php?tid=166680

Now we only have includes, defines. That's no gamemode! We can't do ANYTHING with this. And actually, it's possible that you'll crash when you connect and when you won't spawn.
But we'll handle that later. First, we need an important function. If you don't use it, you'll get this error in your console (and server_log.txt)
Код:
[hh:mm:ss] Script[gamemodes/script.amx]: Run time error 20: "Invalid index parameter (bad entry point)"
You need the function main() for this. The most people only use it for a message, so you can see that the gamemode is loaded. So this is what we gonna have, for example:
pawn Код:
main()
{
    print("My gamemode from scratch is loaded! :D");
    return 1;
}
So, when it's done with the callback OnGameModeInit(), it'll show My gamemode from scratch is loaded! .
We also have OnGameModeInit. That'll be called when the gamemode starts. You can (re)set strings here, create textdraws e.d. Just add in your script (not in main or another callback): OnGameModeInit()
Then, open it with brackets( { & } ). In the brackets you have to fill in the information you want. For example, the AddPlayerClass. That one is important too!
If you won't add that, and when you spawn after connecting, you'll 'crash'. I mean with that, that you get a screen with the text Stay within the world boundries! and some weird colors.
When you say something in the chat, it'll be showed really strange. AddPlayerClass has the following params:
Код:
AddPlayerClass(skin, Float:x, Float:y, Float:z, Float:Angle, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);

skin = the skin id
x = The X spawn position
y = The Y spawn position
z = The Z spawn position (height)
Angle = The angle, where the player looks at when spawning
weapon1-3 = Weapon 1-3 ([url=http://weedarr.wikidot.com/gunlist]ID)
weapon1-3_ammu = Ammu in weapon 1-3
If you're gonna make the spawn positions in the script and if you're gonna use commands to get weapons (RP) I recommend you to only use this:
pawn Код:
AddPlayerClass(SKINID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Replace the SKINID with the skin id you want.
There's by the way also an OnGameModeExit. This one'll be called when the gamemode exists, so when you use rcon command 'exit' or 'gmx'. Just clicking [X] on your console won't work!

Adding vehicle's is also VERY usefull. This can you do with three different functions:
pawn Код:
CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2);
AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay);
I recommend you using CreateVehicle, because AddStaticVehicle(Ex) will only work in OnFilterScriptInit or OnGameModeInit! Trains can only be added with AddStaticVehicle.

How to find positions?
Well, I ever made a filterscript named Ultimate Ingame Editor.
With this you can:
* Add vehicles and save them into a file
* Add positions and save them into a file (with or without function names)
* Make teleport commands and them them into a file
* Add a pickup with info and save it into a file (health, armour, info pickup, custom: Edit it yourself)
Here's the topic: https://sampforum.blast.hk/showthread.php?tid=184733

After all the important includes, defines and functions, you are more on your own! Now, the two questions'll come (back).
What do you want? What do you need? If you're gonna include your own usersystem, I recommend you to make that one first
I'll make a good tutorial soon for making user systems! The most are using MySql, and alot of people don't know that or don't want that. I found two other tutorials, but they're using the slow dini! I'll make one that's using DJSON and ZCMD!

You're now on you're own. 'cuz there probably over million different script ways, ideas etc, I won't give more information
Well, I'll put some usefull standard functions below this, but you need to make systems your own! Off course you can ask questions in this topic .

Usefull STANDARD functions e.d.
SetTimer - Will start a timer. You're gonna need (custom) callbacks for this! Just adding 'public callback()' won't work! Use forward:
pawn Код:
forward MyFunction();
public MyFunction()
{
    return 1;
}
SetTimerEx - Will start a timer. With this one, you can use params in a custom callback! With the normal SetTimer you can't!!!
It works like this:
SetTimerEx(callbackname, interval, repeat, param_type_code, param_string);
If you don't understand this, I'll give an example of this callback:
pawn Код:
forward KickPlayer(playerid);
public KickPlayer(playerid)
    return Kick(playerid);
This timer'll kick the player after 5 seconds after using the function.
SetTimerEx("KickPlayer", 5000, false, "i", playerid);
The '5000' is the time in milli seconds when the function'll be called. (1 second = 1000 milli seconds. 1 minute = 60000 milli seconds).
The 'false' means, that the function won't be repeated. When you use 'true', the function'll be called every 5 seconds
The "i" stands for "integer". The playeris is just a single integer, that's why you're gonna need "i", "d". I'll give the most used 'tags'.
"i" = integer
"d" = omg forgotten... same effect as "i"
"s" = string (text string)
"f" = float (0.00000000).

This is the most usefull stuff
If you're really don't know alot yet, I recommend you reading the next tutorials:
* How to find bugs (learn more about debugging)
* Script cleanup (how to make a script looking more 'professional')
* Tutorial for script beginners (more important stuff)

And as last, but not least at all!
Don't forget to add credits if you're using someone's include, function, script etc!!!
Put this above in the gamemode or make a new file! Here's an example of my 'CREDITS.txt'
Код:
The SA:MP Team: [www.sa-mp.com]
	* Server scripting functions

Kwarde: [www.rl-rp.com]
	* The gamemode/script
	* The idea
	* Outside prison
	* Bank interior
	
Dracoblue: [www.dracoblue.net]
	* Djson include
	* Dini include

Incognito:
	* Incognito's streamer [https://sampforum.blast.hk/showthread.ph...9.97136256	
Zeex:
	* ZCMD [https://sampforum.blast.hk/showthread.ph...9.97136256	
Alex_Valde:
	* The Prison INTERIOR. (OZ Prison). [https://sampforum.blast.hk/showthread.ph...9.97136256	
******: [www.y-less.com]
	* sscanf
	* Some tutorials
	
Slice:
	* Hold studio - For the weapon holdster script
	* Some tutorials
	* Mailer include
	
Wups:
	* OnPlayerShootPlayer include [https://sampforum.blast.hk/showthread.ph...9.97136256	
Admantis:
	* After dead, laying on ground IDEA (made by myself) [Afterlife/accept dead : https://sampforum.blast.hk/showthread.php?tid=205223]
Please add credits! People won't like it if you don't add credits, and you can be banned for it if you release a script!

I think I gave enough now. Say it again if I miss something
I'll add it then, probably.

Good luck

- Kevin
Reply
#2

REALLY NICE! Good work man!
I will make a freeroam... But with more stuff offcourse and not to use on our server!
Reply
#3

You need to tell people that using..
Quote:

#include "file"

looks in the script's parent folder, not the include folder.
Reply
#4

Awesome tutorial, !!

@ricardo: Freedoom? xD Whaha, sounds like hell ^^
Reply
#5

Very nice tutorial man!
Reply
#6

I mean FreeRoam
Reply
#7

Quote:
Originally Posted by Gabe
Посмотреть сообщение
You need to tell people that using..

looks in the script's parent folder, not the include folder.
Ah thank you. Forgot to add *facepalm*
Reply
#8


When you make the basic player system one please pm me
Reply
#9

I'll do.
Like I said I'll use djson. There are more tutorials, but that're using mysql or dini :')
Reply
#10

I'm sorry to say I'm rather disappointed. When someone starts scripting, he will more focus on basic things like AddPlayerClass, finding coordinates, adding vehicles and teleport commands. A new scripter should not straightaway start with methods like SetTimer(-Ex) or flooded with pre-processor information. Sure, it's easy if you know it, but IMO new scripters should get to know how methods work first, how to find coordinates and get around with the editor a bit.
Reply
#11

Quote:
Originally Posted by Hiddos
View Post
I'm sorry to say I'm rather disappointed. When someone starts scripting, he will more focus on basic things like AddPlayerClass, finding coordinates, adding vehicles and teleport commands. A new scripter should not straightaway start with methods like SetTimer(-Ex) or flooded with pre-processor information. Sure, it's easy if you know it, but IMO new scripters should get to know how methods work first, how to find coordinates and get around with the editor a bit.
I have to agree on that, still I think you did a great job on the tutorial. And I hope alot of people may find it usefull!
Reply
#12

good tut, keep it up
Reply
#13

@Hiddos & @playboyx12:
I'll add more soon :') (probably Sunday)

- Kevin
Reply
#14

You are the best
Reply
#15

You've helped many people
Reply
#16

That's my intention
However it's #EDITTED:

main()
OnGameModeInit()
OnGameModeExit()
AddPlayerClass
CreateVehicle / AddStaticVehicle(Ex)
How to find positions etc (just a link to a filterscript)
Reply
#17

Wow, if it was good before now is very good
Reply
#18

thanks
Reply
#19

You're welcome.
Reply
#20

what are callbacks?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)