Help needed with Drug System
#1

I've started making the Drug System just now, it compiled without errors. But now i don't know how exactly to make the /acceptdrugs command. Here's the code:

The /selldrugs command.
Код:
CMD:selldrugs(playerid,params[])
{
	if(OfferedDrugs[playerid] == 1) 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);
		OfferedDrugs[id] = 1;
		OfferedDrugs[playerid] = 1;
	}
	return 1;
}
The /declinedrugs command.
Код:
CMD:declinedrugs(playerid,params[])
{
	if(OfferedDrugs[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"No one has offered drugs to you.");
	{
	    new 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]");
	    if(OfferedDrugs[id] == 0) return SendClientMessage(playerid,COLOR_RED,"That player havent made you the drug offer.");
	    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);
	    OfferedDrugs[id] = 0;
	    OfferedDrugs[playerid] = 0;
	}
	return 1;
}
And i have no clue how to make the /acceptdrugs one, any help?

ALSO, is this code written good? I dont want the player to sell the amount of drugs he doesen't have.
Код:
if(PlayerInfo[playerid][pDrugs] < drugs) return SendClientMessage(playerid,COLOR_RED,"You dont have that much drugs.");
Reply
#2

What is the purpose of declaring the variable "drugs"? Why do you want to use that? It pops up as an error because you don't assign a value to it.
Reply
#3

Quote:
Originally Posted by frouzen
Посмотреть сообщение
What is the purpose of declaring the variable "drugs"? Why do you want to use that? It pops up as an error because you don't assign a value to it.
I wanted the variable to check if the player has that amount of drugs, but now i see myself that doesen't make any sense. I'll remove it. But how should i check if the player has that amount? So he doesen't sell more than he has?

EDIT: I'm looking at Talha's Drug Tutorial, and i think this will work.
Код:
if(drugs > PlayerInfo[playerid][pDrugs]) return SendClientMessage(playerid,COLOR_RED,"You dont have that much drugs.");
Any help around /acceptdrugs though?
Reply
#4

Your command is very badly done I hope you do not have your more commands haha
Create many unnecessary variables, I leave the first command without the need for those unnecessary variables, and also now if you no longer let it sell if you do not have enough

PHP код:
CMD:selldrugs(playerid,params[])
{
    if(
OfferedDrugs[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"You've already offered someone drugs.");
    {
        new 
idamountpricePname[MAX_PLAYER_NAME], str[100];
        if(
sscanf(params,"uii",id,amount,price)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /selldrugs [ID] [Amount] [Price]");
        if(
PlayerInfo[playerid][pDrugs] == 0) return SendClientMessage(playerid,COLOR_RED,"You dont have any drugs left on you.");
        if(
PlayerInfo[playerid][pDrugs] < amount) return SendClientMessage(playerid,COLOR_RED,"You dont have that much drugs.");
        
GetPlayerName(playeridPnamesizeof(Pname));
        
format(str,sizeof(str)," %s has offered you %d grams of drugs for %d $, you can either /acceptdrugs or /declinedrugs",Pname,amount,price);
        
SendClientMessage(id,COLOR_ORANGE,str);
        
GetPlayerName(idPnamesizeof(Pname));
        
format(str,sizeof(str)," You've offered the drugs to %s",Pname);
        
SendClientMessage(playerid,COLOR_ORANGE,str);
        
SendClientMessage(id,COLOR_ORANGE,str);
        
OfferedDrugs[id] = 1;
        
OfferedDrugs[playerid] = 1;
    }
    return 
1;

If you want the command to accept drugs I could guide you a little to learn
Reply
#5

Quote:
Originally Posted by Swankeh
Посмотреть сообщение
Your command is very badly done I hope you do not have your more commands haha
Create many unnecessary variables, I leave the first command without the need for those unnecessary variables, and also now if you no longer let it sell if you do not have enough

PHP код:
CMD:selldrugs(playerid,params[])
{
    if(
OfferedDrugs[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"You've already offered someone drugs.");
    {
        new 
idamountpricePname[MAX_PLAYER_NAME], str[100];
        if(
sscanf(params,"uii",id,amount,price)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /selldrugs [ID] [Amount] [Price]");
        if(
PlayerInfo[playerid][pDrugs] == 0) return SendClientMessage(playerid,COLOR_RED,"You dont have any drugs left on you.");
        if(
PlayerInfo[playerid][pDrugs] < amount) return SendClientMessage(playerid,COLOR_RED,"You dont have that much drugs.");
        
GetPlayerName(playeridPnamesizeof(Pname));
        
format(str,sizeof(str)," %s has offered you %d grams of drugs for %d $, you can either /acceptdrugs or /declinedrugs",Pname,amount,price);
        
SendClientMessage(id,COLOR_ORANGE,str);
        
GetPlayerName(idPnamesizeof(Pname));
        
format(str,sizeof(str)," You've offered the drugs to %s",Pname);
        
SendClientMessage(playerid,COLOR_ORANGE,str);
        
SendClientMessage(id,COLOR_ORANGE,str);
        
OfferedDrugs[id] = 1;
        
OfferedDrugs[playerid] = 1;
    }
    return 
1;

If you want the command to accept drugs I could guide you a little to learn
I've already changed the structure of the Drug System completely.

By the way, i see you're using 1 variable with multiple formats. Is that better? Or worse?
Reply
#6

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 
idamountpricePname[MAX_PLAYER_NAME], Pname1[MAX_PLAYER_NAME], drugsstr[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(playeridPnamesizeof(Pname));
    
GetPlayerName(idPname1sizeof(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(playeridPnamesizeof(Pname));
    
GetPlayerName(idPname1sizeof(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(playeridPnamesizeof(Pname));
    
GetPlayerName(idPname1sizeof(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;

ps: sorry for indention i just wrote this in notepad.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)