[Tutorial] Nuke Command
#1

Hey, today ill teach you how to make a nuke command (or something similar)

So first off i will be doing this in zcmd because its i prefer using it over dcmd and strcmp.

To start put this at the top
pawn Code:
#include <zcmd>
#include <sscanf2>


#define red 0xFF0000AA
Now to get the code started.
pawn Code:
CMD:nuke(playerid,params[])
{
Ok so, we need to add the 'new' under the {
pawn Code:
new pname[24], targetid, string[128],string2[128];
Breaking it down;
pname is the player's name you just nuked.
targetid is the player's ID you just nuked.
string[128] is used to send the client message for all and to the player.

Now making this for admins only:
pawn Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "SERVER: Unknown Command.");
!IsPlayerAdmin is saying, "If the player isnt logged into rcon then he will get the message "SERVER: Unknown Command."

Now lets say the admin only typed /nuke with no player id/name.
pawn Code:
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, red, "USAGE: /nuke [playerid/name]");
If the admin didnt type the id/name he will receive USAGE: /nuke [playerid/name]

Now if the admin typed an invalid id/name
pawn Code:
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, red, "ERROR: That player isn't online!");
This function checks if the player selected is online. If he is not the admin receives ERROR: That player isn't online!

Now we are going to get into the real command functions.
We have to make a new float for the players X Y Z location.

pawn Code:
new Float: x, Float: y, Float: z;
Okay, next we need to get the players name who is being nuked.
pawn Code:
GetPlayerName(targetid, pname, 24);
As mentioned, targetid = id, pname = nuked players name

Now we use the floats we created above.
pawn Code:
GetPlayerPos(targetid, x, y, z);
This will be used to locate the player to know where to create the explosion

Now to create the explosion; without an explosion its not a nuke!
pawn Code:
CreateExplosion(x, y, z, 7, 10);
The x y z is the players cords from the floats we made earlier

To make sure he dies
pawn Code:
SetPlayerHealth(targetid,0);
Now using the string, we make it send the message to all
pawn Code:
format(string, 128, "%s (%d) has died from a mysterious explosion...", pname, targetid);
the %s will be the players name, %d will be his id

Now to format the string to send it to the admin
pawn Code:
format(string2, 128, "You have nuked %s (%d)", pname, targetid);
So, sending the message to the correct people
To all players
pawn Code:
SendClientMessageToAll(0xFF00FFFF, string);
To the player nuked
pawn Code:
SendClientMessage(targetid, 0xFF00FFFF, "You have died from a mysterious explosion...");
To the admin
pawn Code:
SendClientMessage(playerid, 0xFF00FFFF, string2);
Now the code should successfully nuke the player!

Questions, problems? Post a comment
Reply


Messages In This Thread
Nuke Command - by SnG.Scot_MisCuDI - 11.04.2012, 02:03
Re: Nuke Command - by Sting. - 11.04.2012, 04:32
Re: Nuke Command - by Wickeed - 14.04.2012, 14:21
Re: Nuke Command - by SnG.Scot_MisCuDI - 15.04.2012, 18:23
Re: Nuke Command - by SnG.Scot_MisCuDI - 19.04.2012, 04:01
Re: Nuke Command - by newbienoob - 19.04.2012, 13:05
Re: Nuke Command - by SnG.Scot_MisCuDI - 21.04.2012, 19:37
Re: Nuke Command - by faisy8 - 22.04.2012, 07:50
Re: Nuke Command - by SnG.Scot_MisCuDI - 24.04.2012, 23:29
Re: Nuke Command - by RollTi - 25.04.2012, 09:04
Re: Nuke Command - by Wickeed - 25.04.2012, 14:38
Re: Nuke Command - by dannyk0ed - 25.04.2012, 14:48
Re: Nuke Command - by SnG.Scot_MisCuDI - 25.04.2012, 19:33
Re: Nuke Command - by Wickeed - 25.04.2012, 19:42
Re: Nuke Command - by SnG.Scot_MisCuDI - 28.04.2012, 18:47
Re: Nuke Command - by Wickeed - 28.04.2012, 22:47
Re: Nuke Command - by SnG.Scot_MisCuDI - 30.04.2012, 22:01
Re: Nuke Command - by SnG.Scot_MisCuDI - 12.05.2012, 21:01
Re: Nuke Command - by Djole1337 - 09.06.2012, 18:02
Re: Nuke Command - by Edin Black - 09.06.2012, 19:46
Re: Nuke Command - by qazwsx - 10.09.2013, 08:10

Forum Jump:


Users browsing this thread: 1 Guest(s)