[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
#2

Nice one. Good one. But for war server's, a high rank player would want to blow up the player, not an admin. But anyway, good tutorial!
Reply
#3

Good Tutorial 4,5/5
And useful D
Reply
#4

Quote:
Originally Posted by RTR12
View Post
Nice one. Good one. But for war server's, a high rank player would want to blow up the player, not an admin. But anyway, good tutorial!
Well yeah, you can tweak it any way, i just gave the basic command to start them off
Quote:
Originally Posted by Wickeed
View Post
Good Tutorial 4,5/5
And useful D
Thanks!
Reply
#5

bump for people who need it
Reply
#6

Thanks. That was easy.
Reply
#7

Quote:
Originally Posted by newbienoob
View Post
Thanks. That was easy.
No problem
Reply
#8

What is the effection of the nuke? Can it blast the whole map on sanandreas and are all the other players dead? And can you also tell me how you can make a nuclear bomb for yourself? or have you to download it?
Reply
#9

Quote:
Originally Posted by faisy8
View Post
What is the effection of the nuke? Can it blast the whole map on sanandreas and are all the other players dead? And can you also tell me how you can make a nuclear bomb for yourself? or have you to download it?
The nuke just explodes a player. It can also hurt the people around him. I dont think its possible to nuke the whole map unless you put a bunch of coords
Reply
#10

Why creating sendclientmessage(playerid, -1, "UNKNOWN COMMAND");

if you could just return 0; instead of sending a client message
Reply
#11

i got same problems when i "installed" sscanf2
pawn Код:
\pawno\include\sscanf2.inc(218) : warning 219: local variable "string" shadows a variable at a preceding level
\pawno\include\sscanf2.inc(218) : warning 219: local variable "string" shadows a variable at a preceding level
\pawno\include\sscanf2.inc(278) : warning 219: local variable "string" shadows a variable at a preceding level
\include\sscanf2.inc(278) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(79) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(100) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(123) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(138) : warning 219: local variable "string" shadows a variable at a preceding level
: warning 219: local variable "string" shadows a variable at a preceding level
: warning 219: local variable "string" shadows a variable at a preceding level
Reply
#12

or /kill
Reply
#13

Quote:
Originally Posted by Wickeed
Посмотреть сообщение
i got same problems when i "installed" sscanf2
pawn Код:
\pawno\include\sscanf2.inc(218) : warning 219: local variable "string" shadows a variable at a preceding level
\pawno\include\sscanf2.inc(218) : warning 219: local variable "string" shadows a variable at a preceding level
\pawno\include\sscanf2.inc(278) : warning 219: local variable "string" shadows a variable at a preceding level
\include\sscanf2.inc(278) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(79) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(100) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(123) : warning 219: local variable "string" shadows a variable at a preceding level
../include/gl_common.inc(138) : warning 219: local variable "string" shadows a variable at a preceding level
: warning 219: local variable "string" shadows a variable at a preceding level
: warning 219: local variable "string" shadows a variable at a preceding level
That means "string" is already defined
Reply
#14

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
That means "string" is already defined
Ok..How i can fix it (i am newbie scripter..)
Reply
#15

It shouldnt affect the code but if you want to get rid of it... Look at the top of the script and if u see new String[128]; or something like that delete it.
Reply
#16

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
It shouldnt affect the code but if you want to get rid of it... Look at the top of the script and if u see new String[128]; or something like that delete it.
Thanks This helped
Reply
#17

Quote:
Originally Posted by Wickeed
Посмотреть сообщение
Thanks This helped
No problem
Reply
#18

bump so if people need it
Reply
#19

Too much sacnr... but still nice.
Reply
#20

5/5

Nice
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)