Help with making /command [text] -
Karol56 - 05.07.2012
Hi,
For the past week I've been trying to figure out how to make a simple command with text at the end..
So for example.
/givemoney [money] [player] //Gives some amount of money to a specified player.
Please help..
And, I've used the search function around 20 times, looking for a topic which explains this but couldn't find any.
Respuesta: Help with making /command [text] -
Chris1337 - 05.07.2012
pawn Код:
if(strcmp(cmd, "/givecash", true) == 0)
{
new tmp[256];
new string[128];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new giveplayerid, moneys;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_5, "USAGE: /givecash [playerid] [amount]");
return 1;
}
giveplayerid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_5, "USAGE: /givecash [playerid] [amount]");
return 1;
}
moneys = strval(tmp);
//printf("givecash_command: %d %d",giveplayerid,moneys);
if (IsPlayerConnected(giveplayerid))
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
playermoney = GetPlayerMoney(playerid);
if (moneys > 0 && playermoney >= moneys)
{
GivePlayerMoney(playerid, (0 - moneys));
GivePlayerMoney(giveplayerid, moneys);
format(string, sizeof(string), "You gave %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
SendClientMessage(playerid, COLOR_GREEN, string);
format(string, sizeof(string), "You got $%d from %s(player: %d).", moneys, sendername, playerid);
SendClientMessage(giveplayerid, COLOR_GREEN, string);
PlayerPlaySound(playerid,1084,0.0,0.0,0.0);
printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Jou dont have so much ;)");
}
}
else
{
format(string, sizeof(string), "%d not found.", giveplayerid);
SendClientMessage(playerid, COLOR_RED, string);
}
return 1;
}
I SEARCHED , DONT TESTED
Re: Help with making /command [text] -
[KHK]Khalid - 05.07.2012
Open up lvdm that gamemode which comes with the server package, it has a command like what you're trying to make.
Edit:
The code by axxelac would work too but you'll have to add the strtok defination to your script (
Strtok), otherwise it will give you errors undefined symbol "strtok".
Re: Help with making /command [text] -
Roko_foko - 05.07.2012
https://sampwiki.blast.hk/wiki/Fast_Commands, here you can find nice things which are made to work with that kind of commands. I prefer sscanf, as it's not hard to understad for beginers, but all of them are good.
Re: Help with making /command [text] -
Karol56 - 05.07.2012
Thanks but 2 errors:
D:\GTA SA\SAMP Development\Server files\gamemodes\Karol.pwn(220) : error 017: undefined symbol "idx"
D:\GTA SA\SAMP Development\Server files\gamemodes\Karol.pwn(229) : error 017: undefined symbol "idx"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
2 Errors.
EDIT:
Never mind.. fixed.