[Tutorial] Making /vw (virtualworld) command using ZCMD and sscanf
#1

Hey guys i am creating a tutorial to make a command for virtual worlds using zcmd and sscanf.

First you will need zcmd and sscanf get them from here:
ZCMD: ZCMD
sscanf:sscanf

Now lets get started.

First we will use the includes

pawn Code:
#include <a_samp>
#include <sscanf>
#include <zcmd>
I dont think i will need to tell what it means.
Now lets start the main command

pawn Code:
CMD:vw(playerid,params[])
{
new virtualworld;
if(sscanf(params,"i",virtualworld)) return SendClientMessage(playerid,-1,"USAGE: /vw [id]");
else
{
new str[256];
SetPlayerVirtualWorld(playerid,virtualworld);
format(str,sizeof(str),"You are now in virtual world %d",virtualworld);
SendClientMessage(playerid,-1,str);
}
return 1;
}

Now lets see what have we done here.



pawn Code:
CMD:vw(playerid,params[])
{
here we are declaring/making and starting our command using ZCMD.

NOTE: commands starting like this are NOT in "OnPlayerCommandText" function.


pawn Code:
new virtualworld;
In this we have declared a new variable ie virtualworld.


pawn Code:
if(sscanf(params,"i",virtualworld)) return SendClientMessage(playerid,-1,"USAGE: /vw [id]");

In this part we are seeing for the virtualworld id the player is giving after /vw command. If the player doesnt type the parameter he will recieve this message that he has to type a parameter.


pawn Code:
else
{
new str[256];
SetPlayerVirtualWorld(playerid,virtualworld);
format(str,sizeof(str),"You are now in virtual world %d",virtualworld);
SendClientMessage(playerid,-1,str);
}


If the player has specified a parameter it will go to the next part of code ie after else part this part sets the virtualworld of player by using SetPlayerVirtualWorld function.
We have also made a new variable str.
Here we are using format function because SendClientMessage does not support use of %d, %s etc.The format function is using str variable.
Then we are using SendClientMessage to tell the player that he is now in the virtualworld he specified as a parameter.



pawn Code:
return 1;
}

This tells the work of the code is over.



Please dont be harsh as this is my first post..
Also sorry for my bad grammar
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)