02.08.2011, 06:15
Hi peoples, in this tutorial I will teach you how to make your own Team deathmatch ( TDM ) gamemode.
1. Introduction
- What is Team Deathmatch?
It is some kind of a deathmatch, but with teams!
2. Requirements
1. A basic PAWN knowledge.
3. Creating the gamemode
Open your pawno program, click CTRL+A on your keyboard ( Select all ) and delete it.
Add the following code :
We are including a_samp, the include itself also includes some other files, which will help us ( Some includes got an useful functions ).
Next, we will define team ID's
Below it add :
- What is that thing?
As far as I know, it's a callback which starts after OnGameModeInit, and AFAIK it won't be called on a filterscript ( #define FILTERSCRIPT )
print is a function which will sends a message on the server console.
And add this :
3.1. Adding classes
Quoted from SA-MP wiki.
Let's continue!
Add the classes ( from savedpositions.txt ) below OnGameModeInit
AddPlayerClass will add a class, this is the arguments :
.
Let's continue again.
Now we will add a callback which will calls when a player is on class selection.
We will add gametexts!
Let's continue.
We will add an anti-teamkill! ( With SetPlayerTeam they can still be killed with knifes. )
The whole gamemode should looks like :
That's all I can bring, because I had a homework ATM.
Hope it can be useful for newbies!
p.s. This is my first tutorial I have ever made.
1. Introduction
- What is Team Deathmatch?
It is some kind of a deathmatch, but with teams!
2. Requirements
1. A basic PAWN knowledge.
3. Creating the gamemode
Open your pawno program, click CTRL+A on your keyboard ( Select all ) and delete it.
Add the following code :
pawn Код:
#include < a_samp >
Next, we will define team ID's
pawn Код:
#define TEAM_BALLAS ( 0 ) // Defines TEAM_BALLAS as team ID 0
#define TEAM_CJ ( 1 ) // Defines TEAM_CJ as team ID 1
pawn Код:
main( )
As far as I know, it's a callback which starts after OnGameModeInit, and AFAIK it won't be called on a filterscript ( #define FILTERSCRIPT )
pawn Код:
main( )
{ // Opening bracket
print( ">> Team deathmatch by < yourname > has been loaded!" );
} // Closing bracket
And add this :
pawn Код:
public OnGameModeInit( ) // This callback is called when the gamemode is started.
{
return 1; // This means, the gamemode is processed succesfully AFAIK.
}
Quote:
You will probably want to move some of your spawn points about so everyone doesn't spawn in the same place, which would make a rather boring deathmatch and camping amazingly easy. This is where the debug mode comes in. Run "samp_debug.exe" in your San Andreas root directory and whenever you want to save a co-ordinate type "/save" in the game (press "t" or the key under escape to bring up the text/chat prompt). This will save your current position, angle and playerid to a file called "savedpositions.txt" in your Documents/GTA SA Userfiles/savedpositions.txt |
Let's continue!
Add the classes ( from savedpositions.txt ) below OnGameModeInit
pawn Код:
public OnGameModeInit( )
{
AddPlayerClass( 102, 1958.3783, 1343.1572, 15.3746, 269.1425, 5, 0, 22, 100, 32, 50 ); // Ballas
// The class above is classid 0.
AddPlayerClass( 0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // CJ
// Multiply the classid + 1, so this class is classid 1.
AddPlayerClass( 1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // The truth
// Multiply the classid + 1 again, so this is classid 2.
return 1;
}
pawn Код:
AddPlayerClass( skinID, Float: X, Float: Y, Float: Z, Float: A, Weapon 0, Ammo 0, Weapon 1, Ammo 1, Weapon 2, Ammo 2 );
Let's continue again.
Now we will add a callback which will calls when a player is on class selection.
pawn Код:
public OnPlayerRequestClass( playerid, classid ) // This is called when a player is on class selection
{
return 1; // This means the callback is executed succesfully AFAIK.
}
pawn Код:
public OnPlayerRequestClass( playerid, classid ) // This is called when a player is on class selection
{
switch ( classid ) // This is like a if/elseif statement.
{
case 0: // If the classid is 0
{ // Then
GameTextForPlayer( playerid, "~r~TEAM Ballas", 300, 3 );
// Sends a gametext for player
// ~r~ is a red color in gametext.
// Arguments : Player ID, const string[ ], time ( milliseconds ), style
// Wiki for more info
SetPlayerTeam( playerid, TEAM_BALLAS ); // Sets the player's team to TEAM_BALLAS
}
case 1: // If the classid is 1
{ // Then
GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
// Sends a gametext for player
// ~g~ is a green color in gametext.
// Arguments : Player ID, const string[ ], time ( milliseconds ), style
// Wiki for more info
SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
}
case 2: // If the classid is 2
{ // Then
GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
// Sends a gametext for player
// ~g~ is a green color in gametext.
// Arguments : Player ID, const string[ ], time ( milliseconds ), style
// Wiki for more info
SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
}
}
return 1; // This means the callback is executed succesfully AFAIK.
}
We will add an anti-teamkill! ( With SetPlayerTeam they can still be killed with knifes. )
pawn Код:
public OnPlayerDeath( playerid, killerid, reason ) // This is called when a player deaths.
{
if ( killerid != INVALID_PLAYER_ID ) // If the killerid are NOT an invalid player
{ // Then
if ( GetPlayerTeam( killerid ) == GetPlayerTeam( playerid ) ) // If killerid's team == playerid's team ( who has been killed )
{ // Then
SetPlayerHealth( killerid, -1 ); // Kills the killer ( Setting the health to -1 ).
SendClientMessage( killerid, -1, "No teamkilling." ); // Sends a message to the killer with a white colour ( -1 ), with the message " No teamkilling. ".
GivePlayerMoney( killerid, - 5000 ); // Take $5000 from the killerid, because teamkilling,
}
else // Another team killed the player
{
SendClientMessage( killerid, -1, "Nice shot!" ); // Sends a message to the killer with a white colour ( -1 ) with the message "Nice Shot! ".
GivePlayerMoney( killerid, 5000 ); // Gives the killerid $5000.
}
}
SendDeathMessage( killerid, playerid, reason ); // Sends a death message about the killerid is killing the player, with the reason ( At the middle right of your game, can be toggled by pressing F9 ).
return 1; // This means the callback is executed succesfully AFAIK.
}
pawn Код:
#include < a_samp >
#define TEAM_BALLAS ( 0 ) // Defines TEAM_BALLAS as team ID 0
#define TEAM_CJ ( 1 ) // Defines TEAM_CJ as team ID 1
main( )
{ // Opening bracket
print( ">> Team deathmatch by < yourname > has been loaded!" );
} // Closing bracket
public OnGameModeInit( )
{
AddPlayerClass( 102, 1958.3783, 1343.1572, 15.3746, 269.1425, 5, 0, 22, 100, 32, 50 ); // Ballas
// The class above is classid 0.
AddPlayerClass( 0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // CJ
// Multiply the classid + 1, so this class is classid 1.
AddPlayerClass( 1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0 ); // The truth
// Multiply the classid + 1 again, so this is classid 2.
return 1;
}
public OnPlayerRequestClass( playerid, classid ) // This is called when a player is on class selection
{
switch ( classid ) // This is like a if/elseif statement.
{
case 0: // If the classid is 0
{ // Then
GameTextForPlayer( playerid, "~r~TEAM Ballas", 300, 3 );
// Sends a gametext for player
// ~r~ is a red color in gametext.
// Arguments : Player ID, const string[ ], time ( milliseconds ), style
// Wiki for more info
SetPlayerTeam( playerid, TEAM_BALLAS ); // Sets the player's team to TEAM_BALLAS
}
case 1: // If the classid is 1
{ // Then
GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
// Sends a gametext for player
// ~g~ is a green color in gametext.
// Arguments : Player ID, const string[ ], time ( milliseconds ), style
// Wiki for more info
SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
}
case 2: // If the classid is 2
{ // Then
GameTextForPlayer( playerid, "~g~TEAM CJ", 300, 3 );
// Sends a gametext for player
// ~g~ is a green color in gametext.
// Arguments : Player ID, const string[ ], time ( milliseconds ), style
// Wiki for more info
SetPlayerTeam( playerid, TEAM_CJ ); // Sets the player's team to TEAM_CJ
}
}
return 1; // This means the callback is executed succesfully AFAIK.
}
public OnPlayerDeath( playerid, killerid, reason ) // This is called when a player deaths.
{
if ( killerid != INVALID_PLAYER_ID ) // If the killerid are NOT an invalid player
{ // Then
if ( GetPlayerTeam( killerid ) == GetPlayerTeam( playerid ) ) // If killerid's team == playerid's team ( who has been killed )
{ // Then
SetPlayerHealth( killerid, -1 ); // Kills the killer ( Setting the health to -1 ).
SendClientMessage( killerid, -1, "No teamkilling." ); // Sends a message to the killer with a white colour ( -1 ), with the message " No teamkilling. ".
GivePlayerMoney( killerid, - 5000 ); // Take $5000 from the killerid, because teamkilling,
}
else // Another team killed the player
{
SendClientMessage( killerid, -1, "Nice shot!" ); // Sends a message to the killer with a white colour ( -1 ) with the message "Nice Shot! ".
GivePlayerMoney( killerid, 5000 ); // Gives the killerid $5000.
}
}
SendDeathMessage( killerid, playerid, reason ); // Sends a death message about the killerid is killing the player, with the reason ( At the middle right of your game, can be toggled by pressing F9 ).
return 1; // This means the callback is executed succesfully AFAIK.
}
Hope it can be useful for newbies!
p.s. This is my first tutorial I have ever made.