[Tutorial] How to correct create commands with ZCMD + Sscanf 2.X
#1

Tutorial by JM_Millers

P.S: I'm Russian, sorry for my bad english

Introduction

Many users of American forum use ZCMD + Sscanf wrong.
I try to show the correct version.

Incorrect use of:

PHP код:
CMD:givemoney(playeridparams[])
{
    new 
playamoney;
    if(!
IsPlayerAdmin(playerid)) return 1;
    if(
sscanf(params"ui"playamoney))
    return 
SendCientMessage(playerid, -1"USE: /givemoney [playerid] [amount]");
    
GivePlayerMoney(playerid, -money);
    
GivePlayerMoney(playamoney);
    return 
1;

100 commands = over 100 variables = stack Overflow

Correct usage:

PHP код:
CMD:givemoney(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 1;
    if(
sscanf(params"ui"params[0], params[1]))
    return 
SendCientMessage(playerid, -1"USE: /givemoney [playerid] [amount]");
    
GivePlayerMoney(playerid, -params[1]);
    
GivePlayerMoney(params[0], params[1]);
    return 
1;

Thank you for your attention and sorry for the grammatical errors.
Reply
#2

Simple but clear tutorial. By the way, why just admins can givemoney?
Reply
#3

Quote:
Originally Posted by Fabio11
Посмотреть сообщение
Simple but clear tutorial. By the way, why just admins can givemoney?
Thanks, this is just example.
Reply
#4

Lol I didn`t saw something like this before.Is that working perfect without problem?
Reply
#5

A mistake here:

Quote:
Originally Posted by JM_Millers
Посмотреть сообщение
PHP код:
    return SendCientMessage(playerid, -1"USE: /givemoney [playerid] [amount]"); 
It's
PHP код:
SendClientMessage(playerid,-1"USE: /givemoney [playerid] [amount]"); 
You should remove
PHP код:
GivePlayerMoney(playerid, -params[1]); 
Otherwise the command won't work.
Reply
#6

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
A mistake here:



It's
PHP код:
SendClientMessage(playerid,-1"USE: /givemoney [playerid] [amount]"); 
You should remove
PHP код:
GivePlayerMoney(playerid, -params[1]); 
Otherwise the command won't work.
No, in my lesson all right
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
No, the first version is correct, I don't think you understand how a stack works. Two commands will never be called at the same time, so there will never be 100 variables active at once.

In fact, your method has serious security problems when using optional specifiers and an empty "params".

Edit: Also, nothing like this is ever mentioned in the sscanf topic, so I'm not sure why you thought this was the correct way to do it.
PHP код:
CMD:veh(playeridparams[])
{
new 
heap heapspace();
if(
GetPVarInt(playerid"Admin") < 3) return SendClientMessage(playeridwhite"["#Red"»"#White"] Вы не администратор 3 LVL");
new Float:Pos[3];
if(
sscanf(params,"i"params[0])) return SendClientMessage(playeridwhite"Использовать: /veh [id автомобиля]");
if(
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]))
{
CreateVehicle(params[0], Pos[0], Pos[1], Pos[2], 90.0random(128), random(128), 30000);
}
printf("VEH PARAMS STK %d (%d LOSS)"heapspace(), (heap heapspace()));
return 
1;
}
CMD:car(playeridparams[])
{
new 
heap heapspace();
new 
vehicleid;
if(
GetPVarInt(playerid"Admin") < 3) return SendClientMessage(playeridwhite"["#Red"»"#White"] Вы не администратор 3 LVL");
new Float:Pos[3];
if(
sscanf(params,"i"vehicleid)) return SendClientMessage(playeridwhite"Использовать: /veh [id автомобиля]");
if(
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]))
{
CreateVehicle(vehicleidPos[0], Pos[1], Pos[2], 90.0random(128), random(128), 30000);
}
printf("CAR VERIABLE STK %d (%d LOSS)"heapspace(), (heap heapspace()));
return 
1;

Код:
[09/01/13 - 17:23:35] VEH PARAMS STK 16076 (16 LOSS)
[09/01/13 - 17:23:42] CAR VERIABLE STK 16104 (20 LOSS)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)