PDA

View Full Version : [Tutorial] How to make a DM arena system!



SergiuOfficial
14-06-17, 11:18
Hello guys, I'm back with a new tutorial.
I haven't seen any of these tutorials on the SA-MP forums so I decided to make one myself!
You can add this to your TDM/Stunt/Freeroam/Trucking server or even RP!
(You can make it an event which can be created by admins, you know..)

Alright let's get started!
First, let's add this to the top of our script.
Code:
new InDM[MAX_PLAYERS];
new Dead[MAX_PLAYERS];
Let's define some colors:
Code:
#define COLOR_GREEN 0x33AA33AA
#define COLOR_WHITE 0xFFFFFFFF

Alright, we're done with that, let's get to the real work!

Now what we're gonna do, is show that OnPlayerConnect, the player doesn't spawn at this arena, we will do the following with this:
Code:
//OnPlayerConnect
InDM[playerid] = 0;

Great, let's move to our OnPlayerSpawn now, we will do the following:
Code:
if(Dead[playerid] == 1)
{
SetPlayerHealth(playerid, 100);
SetPlayerArmour(playerid, 100);
ResetPlayerWeapons(playerid);
GivePlayerWeapon(playerid, 26, cellmax);
GivePlayerWeapon(playerid, 28, cellmax);
GivePlayerWeapon(playerid, 24, cellmax);
GivePlayerWeapon(playerid, 34, cellmax);
SetPlayerInterior(playerid, 1);
SetPlayerPos(playerid, 1412.639892, -1.787510, 1000.924377);
SetPlayerVirtualWorld(playerid, 1);
SetPlayerSkin(playerid, 167);
Dead[playerid] = 0;
}

Let me explain what I did step by step:
Code:
SetPlayerHealth(playerid, 100); // we set the player's health and armour to 100 OnPlayerSpawn
SetPlayerArmour(playerid, 100);

Code:
ResetPlayerWeapons(playerid); // we resetted the player's weapons
GivePlayerWeapon(playerid, 26, cellmax); // we gave the player the following weapons:2 grenades, Desert eagle, sniper, UZI and sawn off.
GivePlayerWeapon(playerid, 28, cellmax); // you can change it to what you want of course.
GivePlayerWeapon(playerid, 24, cellmax); // cellmax is to give the player infinite ammo.
GivePlayerWeapon(playerid, 34, cellmax);
GivePlayerWeapon(playerid, 16, 2);

Code:
SetPlayerInterior(playerid, 1); // setting his interior to 1(Check Interiors list to see which one we have set to the DM arena
SetPlayerPos(playerid, 1412.639892, -1.787510, 1000.924377); // coordinates for his player spawn
SetPlayerVirtualWorld(playerid, 1); // Virtual world 1, doesn't matter anyway
SetPlayerSkin(playerid, 167); // chicken head skin, just for fun :D
Dead[playerid] = 0; // As we've declared before Dead == 1, now it sets it to 0.

Alright, I hope you're still following!
Now let's move to OnPlayerDeath, we will put the following: ((If you're adding this to your script, you better put this:
Code:
if(InDM[playerid] == 1)
Code:
// now the code
new msg[120], msg2[120];
format(msg, sizeof(msg), "You killed %s!", GetName(playerid));
format(msg2, sizeof(msg2),"You got killed by %s!", GetName(killerid));
SendClientMessage(playerid, COLOR_GREEN, msg2);
SendClientMessage(killerid, COLOR_GREEN, msg);
SetPlayerHealth(killerid, 100);
SetPlayerArmour(killerid, 100);
SetPlayerSkin(playerid, 167);
Dead[playerid] = 1;
SpawnPlayer(playerid);
SetPlayerInterior(playerid, 1);
SetPlayerPos(playerid, 1412.639892, -1.787510, 1000.924377);
SetPlayerVirtualWorld(playerid, 1);
SetPlayerTeam(playerid, playerid);
GivePlayerWeapon(playerid, 26, cellmax);
GivePlayerWeapon(playerid, 16, 2);
GivePlayerWeapon(playerid, 28, cellmax);
GivePlayerWeapon(playerid, 24, cellmax);
GivePlayerWeapon(playerid, 34, cellmax);
What we did here is send both players a message saying who they killed/got killed by.
We also healed the killer and set his armour to 100, you can remove this if you don't want it this way.
I added a SetPlayerSkin for the player who got killed(Just in case it bugs if you got many teams outside the DM arena).
We also set that the player is Dead(Dead[playerid] = 1; If you scroll up we checked the Dead[playerid] OnPlayerSpawn.
I added the same interior and virtual world to the player in case it bugs(It was bugging with me before, that's why I did it).
Now the SetPlayerTeam(playerid, playerid) will set every player in a different team, so everyone is in a different team, and they won't team up because they can kill each other.

Just to make sure, I added GivePlayerWeapon to the OnPlayerDeath too, well for some reasons before, when you were dying it wasn't giving any weapons, so it's okay to put it here as well as OnPlayerSpawn.

Now let's make the commands, shall we?

Let's start with the /exitdm command.
We have this:
Code:
CMD:exitdm(playerid, params[])
{
if(InDM[playerid] == 0)
{
SendClientMessage(playerid, -1, "You are not at the DM arena!");
return 1;
}
else if(InDM[playerid] == 1)
{
InDM[playerid] = 0;
SetPlayerVirtualWorld(playerid, 0);
SetPlayerHealth(playerid, 0.00);
ForceClassSelection(playerid);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, -1, "You have left the DM arena!");
return 1;
}
return 1;
}
Let's explain what we did here, if they do the command /exitdm and they're not in the arena, it will tell them they're not in the arena with a SendClientMessage.
If they really are in the arena, it will remove them from there, kill them and force them to class selection.
We also resetted their interior and virtual world.

Now let's make the command that will teleport us to the arena!
(PS: You can add it as a pickup, or in a dialog or anything, but I'm making it simple here.
Code:
CMD:enterdm(playerid, params[])
{
InDM[playerid] = 1; // we declared him in the DM arena.
GameTextForPlayer(playerid, "/exitdm to exit!", 3000, 4); // a little game text to tell him how to exit if he's bored from the arena.
SendClientMessage(playerid, -1, "{66FF66}Welcome to the deathmatch arena! {BABABA}"); // Welcoming him to the arena..
SetPlayerInterior(playerid, 1); // setting his interior to 1
SetPlayerPos(playerid, 1412.639892, -1.787510, 1000.924377); // aswell as his position
SetPlayerVirtualWorld(playerid, 1); // and virtual world :D
SetPlayerTeam(playerid, playerid); // setting every player in a team, since every one has a unique playerid
ResetPlayerWeapons(playerid); // removing his weapons from outside the arena
SetPlayerColor(playerid, COLOR_WHITE); // setting everyone's color to white, u can change it
SetPlayerSkin(playerid, 167); // setting his funny skin
SetPlayerHealth(playerid, 100); // 100 for the health
SetPlayerArmour(playerid, 100); // 100 armour
GivePlayerWeapon(playerid, 26, cellmax);
GivePlayerWeapon(playerid, 28, cellmax);
GivePlayerWeapon(playerid, 24, cellmax);
GivePlayerWeapon(playerid, 34, cellmax);
GivePlayerWeapon(playerid, 16, 2); // we gave him the weapons here.

new str[200], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(str, sizeof(str), "{FFFFFF}%s {BABABA}(ID: %d) has entered the DM arena! Join him using /enterdm !", name, playerid);
SendClientMessageToAll(-1, str);// we just announced to everyone that he entered the arena
return 1;
}

Oh, one more thing!
Let's create a stock for GetName:
Code:
stock GetName(playerid)
{
new pnameid[24];
GetPlayerName(playerid,pnameid,24);
return pnameid;
}

See? That wasn't so bad, it's actually easy!
Well we're done with this.
PS: If you wanna disable commands in the DM arena, use if(InDM[playerid] == 0) then the command codes.
I hope you like this, and find it useful.
Thanks for reading everyone!