Code which can let choose whatever integer player wants to insert into command -
karakana7 - 01.11.2010
Ok, so simple explanation.I want to do command, which should be wrote like this /penalty [playername] [amount of penalty] .Half of the code I done myself, but the main question, what to do, that policeman can choose what amount penalty he wants to give to the player.Maybe I need to create variable and write something like variable = strval(SetInt(playerid));

But isn't SetInt function is only used in dini?And one more question, so how I understand strtok is searching what value will be writed after the /command HERE, but if I want that strtok search what is writed /command here
HERE, than how to do it?Thanks everyone who will might help me!!!
Re: Code which can let choose whatever integer player wants to insert into command -
ViruZZzZ_ChiLLL - 01.11.2010
Use sscanf + zcmd
pawn Код:
new playerid2, penalty;
CMD:penalty(playerid, params[])
{
if(sscanf(params, "ui", playerid2, penalty)) SendClientMessage(playerid, Orange, "USAGE : .....");
else if(playerid2 == INVALID_PLAYER_ID) SendClientMessage(playerid, Orange, "ERROR : That user is not online.....");
else if(playerid2 == playerid) SendClientMessage(playerid, Color, "ERROR : You cant give yourself a pentaly....");
else
{
GivePenalty(playerid2);
.....
// Some codes here
}
return 1;
}
Re: Code which can let choose whatever integer player wants to insert into command -
Cameltoe - 01.11.2010
zcmd & sscanf.
pawn Код:
command(penalty, playerid, params[])
{
new Amount, pID;
if(sscanf(params, "ui", pID, Amount)) return SendClientMessage(playerid, COLOR, "Usage /penalty ( playername / id ) ( amount )");
SetPlayerPenalty(pID, Amount);
new string[80];
format(string, 80, "Changed id: %d's Penalty points to: %d.",pID, Amount);
SendClientMessage(playerid, COLOR, string);
return 1;
}
Should get you going.
EDIT: K, looks like ViruZZzZ wrote a bit faster x)
Quote:
Originally Posted by ViruZZzZ_ChiLLL
Use sscanf + zcmd
pawn Код:
new playerid2, penalty;
CMD:penalty(playerid, params[]) { if(sscanf(params, "ui", playerid2, penalty)) SendClientMessage(playerid, Orange, "USAGE : ....."); else if(playerid2 == INVALID_PLAYER_ID) SendClientMessage(playerid, Orange, "ERROR : That user is not online....."); else if(playerid2 == playerid) SendClientMessage(playerid, Color, "ERROR : You cant give yourself a pentaly...."); else { GivePenalty(playerid2); ..... // Some codes here } return 1; }
|
Re: Code which can let choose whatever integer player wants to insert into command -
karakana7 - 01.11.2010
No, i don't created it like that.So what I created until now is this:
pawn Код:
new tmp, name, Float:x, Float:y, Float:z, policeman, string, money;
if(strcmp(cmdtext, "/penalty", true) == 0)
{
tmp = strval(GetPlayerName(playerid, name, sizeof(name));
money = strval(SetInt(playerid));
tmp = strtok(cmdtex, idx);
if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "Usage: /penalty [Player_Nick]");
if(!IsPlayerInRangeOfPoint(playerid, 7.0, x, y, z))
{
SendClientMessage(playerid, 0xAFAFAFAA, "He's running!")
}
else
{
GetPlayerName(playerid, policeman, sizeof(policeman));
format(string, sizeof(string), "You was stopped by %s.He requiring to you to pay %d for penalty ", policeman, money));
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSBOX, "PENALTY", "string", "Accept", "Disagree");
But the problem is that I want to know how to write code, which will let policeman to write amount of money in the /command [playername]
[HERE]...So for this I used function SetInt, but is it right?That's my question.And still no one didn't tell me how to do, that strtok function search what policeman writed /command here
HERE?
Re: Code which can let choose whatever integer player wants to insert into command -
karakana7 - 01.11.2010
So now i edited my code, but there's some errors and some uncertainty.So I have code under OnPlayerCommandText and OnDialogResponse callbacks.Codes:
pawn Код:
if(strcmp(cmd, "/penalty", true) == 0)
{
new tmp[256];
new money[128];
tmp = strtok(cmdtext, idx);
if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /penalty [Player_nick] [amount of penalty]");
if(strlen(money) == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /penalty [Player_nick] [amount of penalty]");
if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "This player is not online!");
new Float:x,Float:y,Float:z;
if(!IsPlayerInRangeOfPoint(playerid, 7.0, x, y, z))
{
SendClientMessage(playerid, 0xAFAFAFAA, "He's running!!!");
}
else
{
new policeman;
new string[128];
GetPlayerName(playerid, policeman, sizeof(policeman));
format(string, sizeof(string), "Yo was stopped by %s.He wants that you pay %d $ for the penalty, if you don't pay, you will be jailed!", policeman, money);
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "penalty", string, "agree", "disagree");
}
}
And second:
pawn Код:
{
if(dialogid == 0)
if(!response)
{
TogglePlayerControllable(playerid, 0);
return 1;
}
else
{
SetPlayerMoney(playerid, [b]here[/b]);
return 1;
}
return 0;
}
Questions
1.Ok so how you see, i'm using strtok to search what is writed after the command (/command HERE), but how exactly I can set what player needs to write here, that command can work?
2.How to deal with these errors:
Код:
C:\Documents and Settings\Justas\Desktop\samp\gamemodes\gyvenimas.pwn(230) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Justas\Desktop\samp\gamemodes\gyvenimas.pwn(230) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Justas\Desktop\samp\gamemodes\gyvenimas.pwn(490) : error 017: undefined symbol "pinigai"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
3 Errors.
3.And how to remove money from the player, who was punished in this command: SetPlayerMoney(playerid,
here);?
Re: Code which can let choose whatever integer player wants to insert into command -
karakana7 - 01.11.2010
Quote:
Originally Posted by ******
People already gave you all the code for this using sscanf. What you are asking is exactly what sscanf was designed for and greatly simplifies the operation.
|
Thank you for the answer ******.But please can you show me how to do it with dcmd+strtok, I want to know it, I want to know how to do it hardway and with dialog, so what i need to add, edit in my code, that i can achieve my goal?
Re: Code which can let choose whatever integer player wants to insert into command -
Zh3r0 - 01.11.2010
Why using strtok? Welcome in 2010 when it's almost 1 year maybe more since sscanf got released.
Like ****** said, it simplifies your code very much, it becomes easier to work with.
Learn how to use SSCANF + ZCMD then you are the king in this.
@Why learning how to make it harder? It's easier, and you want to learn the hardest, weirdo...
Re: Code which can let choose whatever integer player wants to insert into command -
DarkPower - 01.11.2010
https://sampwiki.blast.hk/wiki/Fast_Commands
Re: Code which can let choose whatever integer player wants to insert into command -
karakana7 - 01.11.2010
Thank you for comments, but is it impposible to do it with strcmp and strok, that all of you are telling to use zcmd and sscanf?Look, I want to learn more posibilities how to do this thing than only to know how to do it in one way.So i'm pleasing you to help me, i know that there is newer ways, but I want to learn old ways.
Re: Code which can let choose whatever integer player wants to insert into command -
karakana7 - 01.11.2010
REFRESH!