11.04.2012, 02:03
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
Now to get the code started.
Ok so, we need to add the 'new' under the {
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:
!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.
If the admin didnt type the id/name he will receive USAGE: /nuke [playerid/name]
Now if the admin typed an invalid id/name
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.
Okay, next we need to get the players name who is being nuked.
As mentioned, targetid = id, pname = nuked players name
Now we use the floats we created above.
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!
The x y z is the players cords from the floats we made earlier
To make sure he dies
Now using the string, we make it send the message to all
the %s will be the players name, %d will be his id
Now to format the string to send it to the admin
So, sending the message to the correct people
To all players
To the player nuked
To the admin
Now the code should successfully nuke the player!
Questions, problems? Post a comment
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
pawn Code:
CMD:nuke(playerid,params[])
{
pawn Code:
new pname[24], targetid, string[128],string2[128];
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.");
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]");
Now if the admin typed an invalid id/name
pawn Code:
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, red, "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;
pawn Code:
GetPlayerName(targetid, pname, 24);
Now we use the floats we created above.
pawn Code:
GetPlayerPos(targetid, x, y, z);
Now to create the explosion; without an explosion its not a nuke!
pawn Code:
CreateExplosion(x, y, z, 7, 10);
To make sure he dies
pawn Code:
SetPlayerHealth(targetid,0);
pawn Code:
format(string, 128, "%s (%d) has died from a mysterious explosion...", pname, targetid);
Now to format the string to send it to the admin
pawn Code:
format(string2, 128, "You have nuked %s (%d)", pname, targetid);
To all players
pawn Code:
SendClientMessageToAll(0xFF00FFFF, string);
pawn Code:
SendClientMessage(targetid, 0xFF00FFFF, "You have died from a mysterious explosion...");
pawn Code:
SendClientMessage(playerid, 0xFF00FFFF, string2);
Questions, problems? Post a comment