[Tutorial] How to make a Simple /pu cmd
#1

Hi guyz this is my first tutorial on samp forums .
Today I will show all how to make a simple /pu Or /pullover Command Using Zcmd and sscanf2
https://sampforum.blast.hk/showthread.php?tid=91354 -ZCMD

I am gonna make a series of commands tutorial using zcmd so feel free to post/pm me any cmd tutorial

So first You will have to include zcmd at the top of your script like this
Код:
#include <zcmd>
Also include sscanf under zcmd like this
Код:
#include <sscanf2>
So we are done with the includes part

Then go to the end of script or anywhere you want but outside a call back
and then put like this I am giving the whole cmd first then ill explain it
Код:
CMD:pullover(playerid, params[])
{
new targetid;
if(sscanf(params, "u",targetid)) return SendClientMessage(playerid,COLOR_LIGHTBLUE,"[USAGE]/pullover [playerid]");
if(GetPlayerTeam(playerid) != TEAM_COPS) return SendClientMessage(playerid, COLOR_RED, "You cannot use this as you are not a cop!!");
if(GetPlayerTeam(targetid) == TEAM_COPS) return SendClientMessage(playerid, COLOR_RED, "You cannot ask a cop to pull over and stop");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"You cannot ask this player to pullover as he is not connected");
new Float:X;
new Float:Y;
new Float:Z;
GetPlayerPos(playerid, X, Y, Z);
new Float:TX;
new Float:TY;
new Float:TZ;
GetPlayerPos(targetid, TX, TY, TZ);
if(!IsPlayerInRangeOfPoint(playerid, 7.0, TX, TY, TZ)) return SendClientMessage(playerid, COLOR_RED,"The Player is Too Far");
if(IsPlayerInRangeOfPoint(playerid, 7.0, TX, TY, TZ))
{
new string [128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),"%d has asked you to Stop and Surrender yourself!",name);
SendClientMessage(targetid, COLOR_RED, string);
}

return 1;
}
So first we will define a targetid So that it will get affected on the target


if(sscanf(params, "u",targetid)) return SendClientMessage(playerid,COLOR_LIGHTBLUE,"[USAGE]/pullover [playerid]");
So this means that if the player types /pullover then the player will get a usage error like this [USAGE]/pullover [playerid]

if(GetPlayerTeam(playerid) != TEAM_COPS) return SendClientMessage(playerid, COLOR_RED, "You cannot use this as you are not a cop!!");

This will check if the player is in team Cops You can edit it with your own team name

if(GetPlayerTeam(targetid) == TEAM_COPS) return SendClientMessage(playerid, COLOR_RED, "You cannot ask a cop to pull over and stop");

This is also related to team but here this will check that if the target id is a cop and return a error message

if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"You cannot ask this player to pullover as he is not connected");

This is a main thing it will check if the player i:e target id is connected to the server or not

I have not used and stock of my own so you need to get the player's distance and target's distance so
new Float:X;
new Float:Y;
new Float:Z;
GetPlayerPos(playerid, X, Y, Z);

Here i get the player's pos

new Float:TX;
new Float:TY;
new Float:TZ;
GetPlayerPos(targetid, TX, TY, TZ);

and here the target's pos

So now we have to check that are both player's in range of each other so

if(!IsPlayerInRangeOfPoint(playerid, 7.0, TX, TY, TZ)) return SendClientMessage(playerid, COLOR_RED,"The Player is Too Far");

You can change 7.0 to what range you want

Then time for the real cmd

if(IsPlayerInRangeOfPoint(playerid, 7.0, TX, TY, TZ))
{
new string [128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),"%d has asked you to Stop and Surrender yourself!",name);
SendClientMessage(targetid, COLOR_RED, string);
}

Here if the player's range is 7.0 frm target's range then
we have to make a string using new string[128]; and also name[MAX_PLAYER_NAME];

Then we will get the player's name and using string we will send message to the target

End:-

Thanks for reading my tutorial. POst other cmds you want !
Reply


Messages In This Thread
How to make a Simple /pu cmd - by rockhopper - 21.05.2014, 09:24
Re: How to make a Simple /pu cmd - by Luis- - 21.05.2014, 12:06
Re: How to make a Simple /pu cmd - by Sojo12 - 21.05.2014, 12:06
Re: How to make a Simple /pu cmd - by rockhopper - 21.05.2014, 14:03
Re: How to make a Simple /pu cmd - by Luis- - 21.05.2014, 19:45
Re: How to make a Simple /pu cmd - by rockhopper - 22.05.2014, 08:19

Forum Jump:


Users browsing this thread: 3 Guest(s)