23.02.2013, 16:04
(
Last edited by MiGu3X; 28/02/2013 at 09:09 PM.
)
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
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];
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
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;
}
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,"================================================");
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;
}
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;
}
Code:
~r~ will show u the color in red and the ~b~ will show it on blue
Code:
3000, 4 = 3000 milliseconds and 4 the style of the gametext
pawn Code:
SetPlayerToTeamColor(playerid)
{
if(gTeam[playerid] == TEAM_ASSASINS)
{
SetPlayerColor(playerid, RED);
}
else if(gTeam[playerid] == TEAM_POLICE)
{
SetPlayerColor(playerid, 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;
}
DO NOT FORGET TO ADD in OnPlayerSpawn like this:
pawn Code:
public OnPlayerSpawn(playerid)
{
SetPlayerToTeamColor(playerid);
SetPlayerTeam(playerid, gTeam[playerid]);
}
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 )
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