[Tutorial] How to make a TDM (Team DeathMatch GameMode from scratch
#1

How to make a TDM (Team DeathMatch GameMode from scratch)
Well, hello guys, this is my first tutorial and I hope you like it, all this is about how to make a TDM GameMode from scratch, i'll be adding some commands also and some other features..

Starting

Well, what you need first is to open a pwn file and remove all you have inside, after that put this..

pawn Code:
#include <a_samp> // The most important include
This are the includes, which you need to start your gamemode..

Lets do the define work now, like colors and teams. ..

pawn Code:
// COLORS
#define RED 0xFF0000FF
#define BLUE 0x0000BBAA
#define LIGHTBLUE 0x33CCFFAA
#define GREEN 0x008000FF

// TEAMS
#define TEAM_ASSASINS
#define TEAM_POLICE

// OTHER
#define GameMode "Tutorial GameMode" // GameMode Name that will display on "Mode" place on samp.exeз

new gTeam[MAX_PLAYERS];
Under all of this you can add the main, this will be printed when u open samp-server.exe

pawn Code:
main()
{
    print("Tutorial GameMode by MiGu3X has succesfully loaded!");
}

GameMode Starting

This is when u start doing the public functions, like OnGameModeInit...

pawn Code:
public OnGameModeInit( )
{
    UsePlayerPedAnims(); // Uses GTA:SA normal anims for player not to run in a rare way.

    SetGameModeText (GameMode); // Gives the GameMode a name .. If u didnt do #define GameMode "Text" pawno will send u error messages

    LoadVehicles();
    AddPlayerClass( 0, 2195.4729, 1688.1770, 12.3672, 266.4879, -1, 10000, -1, 10000, -1, 10000 ); // Spawn Assasins 1
    AddPlayerClass( 78, 2195.8218, 1685.8918, 12.3672, 266.4879, -1, 10000, -1, 10000, -1, 10000 ); // Spawn Assasins 2
   
    AddPlayerClass( 23  -1, 10000, -1, 10000, -1, 10000 ); // Spawn Police 1
    AddPlayerClass( 285, 2281.4963, 2467.0193, 3.5313, 182.1925, -1, 10000, -1, 10000, -1, 10000 ); // Spawn Police 2
AddPlayerClass is for player, when he spawns he will spawn on that location with thos skins, but with random weapons ( -1 ) , u can change it.. with the weapons in Weapons Wiki

Dont worry if LoadVehicles(); will give u a message, we will stock it later on..

Lets add a public of OnGameModeExit

pawn Code:
public OnGameModeExit()
{
    print( ">> Tutorial GameMode by MiGu3X has succesfully ended / closed!" );
    return 1;
}
Also u can add a welocme message in OnPlayerConnect, like:

pawn Code:
public OnPlayerConnect(playerid)
{
 SendClientMessage(playerid, RED,"====================[Welcome]==================");
 SendClientMessage(playerid, BLUE,"Welcome to the Team DeathcMatch Server by MiGu3X.");
 SendClientMessage(playerid, BLUE,"Use you command for help and your command to see the rules.");
 SendClientMessage(playerid, RED,"================================================");
So when player connects he will get a message saying that ..

Lets make now a public that will show the player skin, and will tell which play is which team.. then you have to put

pawn Code:
public OnPlayerRequestClass( playerid, classid )
{
    SetPlayerTeamFromClass(playerid, classid);
    return 1;
}
After that add

pawn Code:
SetPlayerTeamFromClass(playerid, classid)
{
    switch(classid)
    {
        case 0, 1:
        {
            gTeam[playerid] = TEAM_ASSASINS;
            GameTextForPlayer(playerid, "~r~ASSASINS", 3000, 4);
            SetPlayerPos(playerid, 2180.4934, 1676.8185, 11.1197); // Assasins Spawn Pos
            SetPlayerInterior(playerid, 0);
            SetPlayerCameraPos(playerid, 2189.2839, 1677.0737, 11.1197); // Assasins Spawn CameraPos
            SetPlayerCameraLookAt(playerid, 2180.4934, 1676.8185, 11.1197); // Assasins Spawn CameraLookAt
            SetPlayerColor(playerid, RED);
            return 1;
        }
        case 2, 3:
        {
            gTeam[playerid] = TEAM_POLICE;
            GameTextForPlayer(playerid, "~b~POLICE", 3000, 4);
            SetPlayerPos(playerid, 2353.5962, 2405.6279, 10.8203); // Police Spawn Pos
            SetPlayerInterior(playerid, 0);
            SetPlayerCameraPos(playerid, 2361.3018, 2405.6365, 10.8203); // Police Spawn CameraPos
            SetPlayerCameraLookAt(playerid, 2353.5962, 2405.6279, 10.8203); // Police Spawn CameraLookAt
            SetPlayerColor(playerid, BLUE);
            return 1;
        }
The
Code:
~r~ will show u the color in red and the ~b~ will show it on blue
So if playerid is on TEAM_POLICE in class selection he will see a gametext saying "POLICE" on blue and will appear for 3 seconds
Code:
 3000, 4 = 3000 milliseconds and 4 the style of the gametext
Now we have to set the team colors, so lets add:

pawn Code:
SetPlayerToTeamColor(playerid)
{
    if(gTeam[playerid] == TEAM_ASSASINS)
    {
        SetPlayerColor(playerid, RED);
    }
    else if(gTeam[playerid] == TEAM_POLICE)
    {
        SetPlayerColor(playerid, BLUE);
    }
}
This will put TEAM_ASSASINS as red color for all the players which are spawned as them and for the TEAM_POLICE members as blue..

Also we need to add that in OnPlayerUpdate, so..

pawn Code:
public OnPlayerUpdate(playerid)
{
    SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
   
    if(gTeam[playerid] == TEAM_ASSASINS)
    {
        SetPlayerColor(playerid, RED);
    }
    else if(gTeam[playerid] == TEAM_POLICE)
    {
        SetPlayerColor(playerid, BLUE);
    }  
    else
    {
        SetPlayerColor(playerid, WHITE);
    }
    return 1;
}
So that will set team players to colors..

DO NOT FORGET TO ADD in OnPlayerSpawn like this:

pawn Code:
public OnPlayerSpawn(playerid)
{
    SetPlayerToTeamColor(playerid);
    SetPlayerTeam(playerid, gTeam[playerid]);
}
So that teams are set and you can play..

GameMode Ending

But do you remember the LoadVehicles??

we need to add a stock... here it is

pawn Code:
stock LoadVehicles()
{
    // Police Vehicles
    AddStaticVehicle(598,2314.5166,2455.2322,3.0175,270.4656,0,1);  // Police Car 1 | ( LVPD )
    AddStaticVehicle(598,2314.4871,2460.4189,3.0199,269.2951,0,1);  // Police Car 2 | ( LVPD )
    AddStaticVehicle(598,2314.2512,2465.3118,3.0218,270.5271,0,1);  // Police Car 3 | ( LVPD )
    AddStaticVehicle(598,2313.8899,2470.3916,3.0209,269.2904,0,1);  // Police Car 4 | ( LVPD )
    AddStaticVehicle(598,2313.7957,2475.1494,3.0183,271.1079,0,1);  // Police Car 5 | ( LVPD )
    AddStaticVehicle(598,2314.4668,2480.2031,3.0177,269.7416,0,1);  // Police Car 6 | ( LVPD )
    AddStaticVehicle(598,2314.4568,2485.1697,3.0170,271.3759,0,1);  // Police Car 7 | ( LVPD )
    AddStaticVehicle(598,2285.6282,2475.5735,3.0162,180.2829,0,1);  // Police Car 8 | ( LVPD )
    AddStaticVehicle(598,2281.4402,2474.9036,3.0181,180.5781,0,1);  // Police Car 9 | ( LVPD )
   
    // Assasins Vehicles
    AddStaticVehicle(411,2176.8386,1664.8558,10.5474,178.3957,116,1);   // Assasins Car 1 | ( Infernus )
    AddStaticVehicle(411,2176.9980,1670.5874,10.5474,178.3957,116,1);   // Assasins Car 2 | ( Infernus )
    AddStaticVehicle(411,2177.1799,1680.6041,10.6552,178.4888,116,1);   // Assasins Car 3 | ( Infernus )
    AddStaticVehicle(411,2176.8721,1687.7756,10.5474,179.4075,116,1);   // Assasins Car 4 | ( Infernus )
    AddStaticVehicle(411,2176.9075,1695.3198,10.5991,179.3561,116,1);   // Assasins Car 5 | ( Infernus )
    AddStaticVehicle(415,2147.8801,1672.4912,10.5929,150.7361,40,1);    // Assasins Car 6 | ( Cheetah )
    AddStaticVehicle(415,2149.8684,1678.3390,10.5924,172.3202,40,1);    // Assasins Car 7 | ( Cheetah )
    AddStaticVehicle(415,2149.7190,1685.4001,10.5909,193.4975,40,1);    // Assasins Car 8 | ( Cheetah )
    AddStaticVehicle(415,2147.1289,1692.9467,10.5906,201.8330,40,1);    // Assasins Car 9 | ( Cheetah )
    AddStaticVehicle(415,2139.9570,1701.5696,10.5896,226.5212,40,1);    // Assasins Car 10 | ( Cheetah )
So thats all the Tutorial , if you need some other help or get errors post them as reply, i hope u liked it

If i did something wrong please correct me.

You can add register and login system with dini, y_ini or whatever you want,

Best Regards
Reply
#2

gTeam instead of SetPlayerTeam
AddPlayerClass instead of AddPlayerClassEx.

People need to learn more efficient methods to make a TDM, use the better and new ways, tutorials like this have been posted on SA-MP forums a 100 times yet none has cared to use innovative functions.

I'll soon post a tutorial on how you can use the existing functions to make a much simpler and much more efficient base of TDM
Reply
#3

I did my best, didn't though over about AddPlayerClassEx, cauz when i tested it, didn't worked for me... It's just simple tutorial...
Reply
#4

not bad, nice
Reply
#5

This is what i call old school TDM add something better like login&register saving system etc.
Reply
#6

Nice tutorial.

Good Job.
Reply
#7

Thank you all for the replies
Reply
#8

nice tut, Thanks!
Reply
#9

Guys can you help me ?
i have error...
i did everything correct but i have the fatal error 100: cannot read from file: "a_samp"
i added the a_samp in the includes but it's still not work help me please PM me if you know how to do this please and thank you!...
Reply
#10

Please upload to pastebin all codes.
Thank You!
Reply
#11

That's not worth being called a gamemode ... you should add stuff like a kill feed, point system and whatever such a mode could need. Anyways this might be too specific to make a tutorial about.

Quote:
Originally Posted by AlonGlenn
View Post
Please upload to pastebin all codes.
Thank You!
its supposed to be a tutorial not a gm download ...
Reply
#12

You guys do realise that this is thread from 2013?? Right?
Reply
#13

Quote:
Originally Posted by Micko123
View Post
You guys do realise that this is thread from 2013?? Right?
Totally didn't :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)