Command help - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Command help (
/showthread.php?tid=657827)
Command help -
KinderClans - 15.08.2018
Can someone tell me why this command doesn't work?
Basically, i have 2 type of drugs: marijuana and cocaine. And i want the player choose which type of drugs (and its respective amount) to sell. Ex /selldrugs marijuana 50.
But doesn't work:
pawn Code:
CMD:selldrugs(playerid, params[])
{
if (Player[playerid][Job] != JOB_DRUG_DEALER) return SendClientMessage(playerid, COLOR_RED, "* You must be a drug dealer to sell drugs.");
if(gTeam[playerid] == TEAM_COP) return SendClientMessage(playerid, COLOR_RED, "* Law Enforcement officers can't sell drugs.");
new amount, string[156];
if(sscanf(params, "u", amount)) return SendClientMessage(playerid, COLOR_RED, "* [USAGE]: /selldrugs [drug type (marijuana, cocaine)] [grams amount] | Ex: /selldrugs marijuana 50");
if(amount < 1 || amount > 50) return SendClientMessage(playerid, COLOR_RED, "* Min amount: 1 gram | Max amount: 50 grams.");
if (!strcmp(params, "marijuana", true))
{
if (Player[playerid][MarijuanaGrams] < 0) return SendClientMessage(playerid, COLOR_RED, "* You dont have marijuana to sell.");
Player[playerid][MarijuanaGrams] -= amount;
GivePlayerMoney(playerid, MARIJUANA_COST_PER_GRAM*amount);
SetPVarInt(playerid,"CmdTime",GetTickCount()+5000);
}
else if (!strcmp(params, "cocaine", true))
{
if (Player[playerid][CocaineGrams] < 0) return SendClientMessage(playerid, COLOR_RED, "* You dont have cocaine to sell.");
Player[playerid][CocaineGrams] -= amount;
GivePlayerMoney(playerid, COCAINE_COST_PER_GRAM*amount);
SetPVarInt(playerid,"CmdTime",GetTickCount()+5000);
}
return 1;
}
Re: Command help -
GRiMMREAPER - 15.08.2018
I have my sincere doubts you've read
sscanf's documentation, therefore do it before you post your doubts here.
Regardless, try this code. You had a variable named "string" for no reason and you were using
strcmp wrong. Give this a try and let me hear back from you.
pawn Code:
CMD:selldrugs(playerid, params[]) {
if (Player[playerid][Job] != JOB_DRUG_DEALER) return SendClientMessage(playerid, COLOR_RED, "* You must be a drug dealer to sell drugs.");
if(gTeam[playerid] == TEAM_COP) return SendClientMessage(playerid, COLOR_RED, "* Law Enforcement officers can't sell drugs.");
new amount,
type[30];
if(sscanf(params, "s[30]i", type, amount)) return SendClientMessage(playerid, COLOR_RED, "* [USAGE]: /selldrugs [drug type (marijuana, cocaine)] [grams amount] | Ex: /selldrugs marijuana 50");
if(amount < 1 || amount > 50) return SendClientMessage(playerid, COLOR_RED, "* Min amount: 1 gram | Max amount: 50 grams.");
if(!strcmp(type, "marijuana", true)) {
if (Player[playerid][MarijuanaGrams] < 0) return SendClientMessage(playerid, COLOR_RED, "* You dont have marijuana to sell.");
Player[playerid][MarijuanaGrams] -= amount;
GivePlayerMoney(playerid, MARIJUANA_COST_PER_GRAM*amount);
SetPVarInt(playerid,"CmdTime",GetTickCount()+5000);
}
else if(!strcmp(type, "cocaine", true)) {
if (Player[playerid][CocaineGrams] < 0) return SendClientMessage(playerid, COLOR_RED, "* You dont have cocaine to sell.");
Player[playerid][CocaineGrams] -= amount;
GivePlayerMoney(playerid, COCAINE_COST_PER_GRAM*amount);
SetPVarInt(playerid,"CmdTime",GetTickCount()+5000);
}
return 1;
}