15.08.2018, 22:33
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.
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;
}

