06.10.2017, 03:25
PHP код:
new OfferedDrugs[MAX_PLAYERS], bool:OfferingDrugs[MAX_PLAYERS], OfferingPrice[MAX_PLAYERS], DrugAmount[MAX_PLAYERS]; // on top
// OnPlayerconnect
OfferedDrugs[playerid] = INVALID_PLAYER_ID;
OfferingDrugs[playerid] = false;
OfferingPrice[playerid] = 0;
DrugAmount[playerid] = 0;
CMD:selldrugs(playerid,params[])
{
if(OfferingDrugs[playerid]) return SendClientMessage(playerid,COLOR_RED,"You've already offered someone drugs.");
new id, amount, price, Pname[MAX_PLAYER_NAME], Pname1[MAX_PLAYER_NAME], drugs, str[100], str1[100];
if(PlayerInfo[playerid][pDrugs] == 0) return SendClientMessage(playerid,COLOR_RED,"You dont have any drugs left on you.");
if(PlayerInfo[playerid][pDrugs] < drugs) return SendClientMessage(playerid,COLOR_RED,"You dont have that much drugs.");
if(sscanf(params,"uii",id,amount,price)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /selldrugs [ID] [Amount] [Price]");
GetPlayerName(playerid, Pname, sizeof(Pname));
GetPlayerName(id, Pname1, sizeof(Pname1));
format(str,sizeof(str)," %s has offered you %d grams of drugs for %d $, you can either /acceptdrugs or /declinedrugs",Pname,amount,price);
format(str1,sizeof(str1)," You've offered the drugs to %s",Pname1);
SendClientMessage(playerid,COLOR_ORANGE,str1);
SendClientMessage(id,COLOR_ORANGE,str);
OfferingPrice[playerid] = price; // save the price value here
DrugAmount[playerid] = amount; // save the amount
OfferedDrugs[id] = playerd;// save the seller id here you're going to use this when accepting drugs
OfferingDrugs[playerid] = true; // Here you will determine if the seller offer a drugs to other players
return 1;
}
CMD:declinedrugs(playerid,params[])
{
if(OfferedDrugs[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"No one has offered drugs to you."); // check if the player has received a selling from other players
new id = OfferedDrugs[playerid] /* Here save the sellerid to variable id */ , Pname[MAX_PLAYER_NAME], Pname1[MAX_PLAYER_NAME], str[100], str1[100];
//if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /declinedrugs [ID]"); // you can simply remove this as we're going to use OfferedDrugs (less work )
GetPlayerName(playerid, Pname, sizeof(Pname));
GetPlayerName(id, Pname1, sizeof(Pname1));
format(str,sizeof(str),"You've declined the drug offer from %s", Pname1);
format(str1,sizeof(str1)," %s has declined your drug offer", Pname);
SendClientMessage(playerid,COLOR_ORANGE,str);
SendClientMessage(id,COLOR_RED,str1);
OfferingDrugs[id] = false; // now set the seller id offering drugs to false
OfferingPrice[id] = 0; // besure to reset the amount
DrugAmount[id] = 0; // same here
OfferedDrugs[playerid] = INVALID_PLAYER_ID; // here if the player declined set it to invalid player id to avoid any bugs always put this at the bottom
return 1;
}
// for accepting drugs
CMD:acceptdrugs(playerid,params[])
{
if(OfferedDrugs[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"No one has offered drugs to you."); // check if the player has received a selling from other players
new id = OfferedDrugs[playerid] /* Here save the sellerid to variable id */ , Pname[MAX_PLAYER_NAME], Pname1[MAX_PLAYER_NAME], str[100], str1[100];
//if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /declinedrugs [ID]"); // you can simply remove this as we're going to use OfferedDrugs (less work )
GetPlayerName(playerid, Pname, sizeof(Pname));
GetPlayerName(id, Pname1, sizeof(Pname1));
format(str,sizeof(str),"You've accept the drug offer from %s", Pname1);
format(str1,sizeof(str1)," %s has accept your drug offer", Pname);
SendClientMessage(playerid,COLOR_ORANGE,str);
SendClientMessage(id,COLOR_RED,str1);
// Your code here for transfering the drugs to the one who will buy the drugs
// Remember! use the 'id' or OfferedDrugs[playerid] for the seller id because it stored the seller id to this variable use this for transaction.
// example
PlayerInfo[playerid][pDrugs] += DrugAmount[id]; // now add the drugs to the player
PlayerInfo[id][pDrugs] -= DrugAmount[id]; // subract the drugs to the seller
// for cash do it just like the one we did here from PlayerInfo[id][pCash] -= OfferingPrice[id]; just an example pCash is the one u're using variable for cash
OfferingDrugs[id] = false; // now set the seller id offering drugs to false
OfferingPrice[id] = 0; // besure to reset the amount
DrugAmount[id] = 0; // same here
OfferedDrugs[playerid] = INVALID_PLAYER_ID; // here if the player declined set it to invalid player id to avoid any bugs always put this at the bottom
return 1;
}