[Tutorial] How to make DeathMach? Learn here!
#1

Hi!
Today I am going to show you how to make DeathMach that will respawn player after death
I am going to make a rocket death mach
Here we go


First includes
We will need ZCMD for commands.Thanks to Zeex

pawn Code:
#include <a_samp>
// Thanks to SA-MP Team
#include <zcmd>
// Thanks to Zeex
pawn Code:
#define VIRTUAL_WORLD 10 //Virtual world whitch players will play in!
#define ROCKET_HEALTH 50 //Health that player will spawn with when join!
Now some colors:
pawn Code:
#define COLOR_GREEN 0x33AA33AA
#define COL_RED   "{E01B4C}"
BEWARE! This is very important
pawn Code:
new str[256];
new InDM[MAX_PLAYERS];
new InROCKET[MAX_PLAYERS];
forward OnDeath(playerid);// forward for the timer that it will respawn player after death.
Now put this under new's
You can change positions but at the end there musn't be "," as you can see here
That will make that who will join DM here will be spawned randomly.

pawn Code:
new Float:DMSpawns[][4] =
{
{247.5956,1458.5726,43.0946,185.8330},
{199.6086,1394.2821,43.0946,350.1746},
{247.5956,1458.5726,43.0946,185.8330},
{167.4688,1426.9861,26.2922,244.9503},
{186.0784,1456.1190,60.1355,184.6759},
{246.0688,1410.4255,23.3703,94.1182},
{287.6833,1411.3716,10.3918,82.7555}
};
Put that under the positions
That will make that it won't put player in DM when he will connect.

pawn Code:
public OnPlayerConnect(playerid)
{
InDM[playerid] = 0;
InROCKET[playerid] = 0;
return 1;
}
First line here will make that it will give killerid 1+ score when he will kill player in DM
Second line is the timer that it will respawn player when he dye in DM.
It will respawn him in 2 sec. You can change this will changeing "2000" to "----"what ever you want

pawn Code:
public OnPlayerDeath(playerid, killerid)
{
if(InDM[playerid] == 1)
{
if(killerid == INVALID_PLAYER_ID) return 1;
new str1[126];
new str[126];
format(str1,sizeof(str1), "~r~You ~r~killed:~n~~g~%s", PlayerName(playerid));
GameTextForPlayer(killerid,str1,2000,5);
format(str,sizeof(str), "~r~You ~g~were ~r~killed ~g~by:~n~~g~%s", PlayerName(killerid));
GameTextForPlayer(playerid,str,2000,5);
}
return 1;
}
pawn Code:
public OnPlayerSpawn(playerid)
{
if(InDM[playerid] == 1)
{
OnDeath(playerid);
}
return 1;
}

Here is the timer.
This will make that player will respawn after death.It will set player health to 50. You can change player health

pawn Code:
public OnDeath(playerid)
{
if(InROCKET == 1)
{
SetPlayerHealth(playerid, 50);//Set Player Health to 50
SetPlayerInterior(playerid, 0);//Set Player Interior to 0
SetPlayerVirtualWorld(playerid, 10); //Set Player Virtual World to 10.
new rand = random(sizeof(DMSpawns));
SetPlayerPos(playerid, DMSpawns[rand][0], DMSpawns[rand][1], DMSpawns[rand][2]); //Set Player random pos X Y and Z
SetPlayerFacingAngle(playerid, DMSpawns[rand][3]);  //Set Player random fancing angle
GivePlayerWeapon(playerid, 35, 1500); //Give Player Rocket Launcher
}
}
That will make that when player disconnect it will automaticly put him out of DM.
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
InDM[playerid] = 0;// Automaticly put player out of DM when player disconnect
InROCKET[playerid] = 0; // Automaticly put player out of ROCKET DM when player disconnect
return 1;
}
Now here is the command. You can change it to what ever you want.
Function::When will player type "/rocketdm" it will spawn him randomly. It will send message to all who play DM that "----" has joined the DM. It will put him to the wirtual world and give him the Rocket Launcher and set player health to 50. You can change player health!
When Player type "/rocketdm" he will leave the DM and it will put him to the world number "0".It will also reset him weapons.

pawn Code:
CMD:rocket(playerid,params[])
{
if(InDM[playerid] == 1) return GameTextForPlayer(playerid, "~g~Type /kill first",2000,5); //If player want to join and is already in DM
if(InDM[playerid] == 0) //If player joined
{
InDM[playerid] = 1;  // Sets variale to 1
}
if(InROCKET[playerid] == 0) //If player joined
{
InROCKET[playerid] = 1; // Sets variale to 1
}
ResetPlayerWeapons(playerid); //Resets player weapons
GameTextForPlayer(playerid,"~g~You ~r~have joined ~g~/rocket, ~n~~p~to ~r~leave ~y~type ~g~/kill",2000,5); //Shows message to player
format(String, sizeof(String), "Server:{FFFFFF}%s(%d) has joined "COL_GREEN"RocketDM(/rocket)", PlayerName(playerid), playerid);
SendClientMessageToAll(COLOR_LIGHTBLUE, String); //Sends message to all players
SetPlayerVirtualWorld(playerid, VIRTUAL_WORLD); //Sets Player virtual world
new rand = random(sizeof(DMSpawns));
SetPlayerPos(playerid, DMSpawns[rand][0], DMSpawns[rand][1], DMSpawns[rand][2]); //Set Player random pos X Y and Z
SetPlayerFacingAngle(playerid, DMSpawns[rand][3]); //Set Player random facing angle
GivePlayerWeapon(playerid, 35, 99999); //Give Player Rocket Launcher
SetPlayerHealth(playerid, ROCKET_HEALTH);//Sets player health to 50
return 1;
}
pawn Code:
CMD:kill(playerid, params[])
{
InDM[playerid] = 0; //This will put player out of DM
InROCKET[playerid] = 0;  //This will put player out of ROCKET DM
SetPlayerHealth(playerid,0);   //Player will die...
SetPlayerVirtualWorld(playerid,0); //Player virtual world will be set to 0
return 1;
}

Example of a command if player is in DM
PHP Code:
CMD:w(playerid,params[])
{
if(
InDM[playerid]) return GameTextForPlayer(playerid,"~g~You are in ~r~DM~n~~g~To leave type ~r~(/kill)",2000,5);
ShowPlayerDialog(playerid999DIALOG_STYLE_LIST""COL_GREEN"Weapons","Melee Weapons\nPistols""OK""Esc");
return 
1;

Reply
#2

Sorry. You have several grammatical mistakes in your tutorial please fix these. Also what on earth does:
pawn Code:
forward OnDeath(playerid);[MAX_PLAYERS];
actually do?

Also, you didn't really explain anything.
Reply
#3

Thanks I didn't see that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)