[Tutorial] Rbj's how to script (2) *Commands*
#1

Hey guys , this is my 2nd Tutorial and in this tutorial we'll talk about cmds

for those who searched for cmds i bet the most 3 cmds u found alot r /heal /kill and /help , i think its useless to explain them cause they're already in alot of posts but i'll show it for those who dont know
pawn Code:
public OnPlayerCommandText(playerid,cmdtext[])
{
       if(strcmp("/heal",cmdtext,true)==0)
       {
             SetPlayerHealth(playerid,100.0);
             SendClientMessage(playerid,COLOR_YELLOW,"Your Player has been Healed");
             return 1;
       }
       if(strcmp("/kill",cmdtext,true)==0)
       {
             SetPlayerHealth(playerid,0);
             SendClientMessage(playerid,COLOR_RED,"You have commited suicide");
             return 1;
       }
       if(strcmp("/help",cmdtext,true)==0)
       {
           SendClientMessage(playerid,COLOR_YELLOW,"Welcome to my server");
           return 1;
       }
     return 1;
}
so now we made the already known cmds , lets get to the cmds which cant be found alot when searching

let start with ......... /dive for example ? alright , first u need to include the library <ocmd> .inc file

pawn Code:
CMD:dive(playerid,params[])
{
    new highness;
    if(sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
    if (highness < 100 || highness > 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
    SendClientMessage(playerid,COLOR_AQUA,"You dive. Enjoy.");
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    SetPlayerPos(playerid,x,y,z+highness);
    GivePlayerWeapon(playerid, 46, 1);
    return 1;
}
so now you probably just coppied and pasted , without even knowing what is written , so lets explain this cmd
pawn Code:
new highness;
in this line u create a new subject called (highness) which we'll use in our cmd , u can name it anything but we name it highness as what it'll be used for

pawn Code:
if(sscanf(params,"i",highness))return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");
u maybe wondering what this line is , in other servers , when u type /dive without typing highness , doesnt it show USAGE:/dive [100-800] ? well that line do just like that , if(sscanf(params,"i",highness)) is when player doesnt type all cmd requirements to work

pawn Code:
if (highness < 100 || highness > 800) return SendClientMessage(playerid,COLOR_GREEN,"/dive [high 100-800]");//COLOR_BROWN
this line is trying to show the (highness) is only from 100-800 , and if a player types a number below 100 or above 800 a Client Message comes out telling him the available heights

pawn Code:
new Float:x,Float:y,Float:z;
this right here creates 3 new Float subjects which r X,Y,Z , and we're gonna know why we need them now

pawn Code:
GetPlayerPos(playerid,x,y,z);
    SetPlayerPos(playerid,x,y,z+highness);
    GivePlayerWeapon(playerid, 46, 1);
GetPlayerPos is used to get/detect players current position
SetPlayerPos(playerid,x,y,z+highness) this is used after u get player's current pos , then add the highness to the Float:Z , z+highness just add any height u write to the Float:Z

GivePlayerWeapon(playerid,46,1); this line gives the player a weapon depending on the Weapon ID , Parachute's ID is 46 and the 1 is 1 ammo from the weap , for example Combat Shotgun's ID is 27 and u want to add 500 ammo so u make GivePlayerWeapon(playerid,27,500);

now from only this command u can learn how to make teleporting commands , do /save [file name] inside the game then go to MyDocuments>GTA San Andreas User Files>SAMP>savedpositions and you'll find it there , dont forget to only copy the FloatX,Y,Z axis , you dont need Float:Angle in the teleporting , for example

AddPlayerClass(0,136.4344,-73.7790,1.4297,194.2452,0,0,0,0,0,0); // Saving Tutorial

only copy the 136.4344,-73.7790,1.4297 , then do SetPlayerPos(playerid,savedpos)

also u can do now a /weaps command which give u a weapon or weapons , by using GivePlayerWeapon(playerid,weaponid,weapon_ammo)

hope you enjoyed this tutorial , i'll post new tutorials that come in mind immediatly , if u have a problem , just send me a msg , i'll reply :3
Reply
#2

Good tutorial, but May I ask you what is ocmd?
Reply
#3

good tutorial..

PD: fix this

pawn Code:
ocmd:dive(playerid,params[])
{
to

pawn Code:
CMD:dive(playerid,params[])
{
:P :P
Reply
#4

Quote:
Originally Posted by !R1Ch@rD!
View Post
good tutorial..

PD: fix this

pawn Code:
ocmd:dive(playerid,params[])
{
to

pawn Code:
CMD:dive(playerid,params[])
{
:P :P
my bad xd , i have <ocmd> included thats why i always do the commands ocmd , Edited.
Reply
#5

Quote:
Originally Posted by Eth
View Post
Good tutorial, but May I ask you what is ocmd?
there's actually no difference bet. it and CMD: , im just used to ocmd more xD
Reply
#6

Really nice tut
Reply
#7

Nice TUT
Reply
#8

thx
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)