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

Ehm sir , Wrong section
And please next time use
Reply
#3

Uhm sir.
You are in wrong section and please use [ pawn ] [ /pawn ] tags
Reply
#4

Indeed.

3/10, considering you didn't use pawn tags, you barely explain the things (judging from me reading it for only a few seconds) and it just doesn't look neat.
Reply
#5

sorry people i didnt know the section i am new to samp forums i will now remember to use pawn and / pawn tags. also i am using mobile to write so please sorry
Reply
#6

It should be here : Tutorial's
Reply
#7

ok i will remember next time thanks for the advice though
Reply
#8

hey should i make this thread in tutorials??
Reply
#9

Quote:
Originally Posted by electrux
View Post
hey should i make this thread in tutorials??
NO AND DONT SPAMM EVERY 3 MIN GO READ THE RULES OR YOU WILL BE BANNED
Reply
#10

ok ok sorryy wont do again
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)