[HELP] /selldrugs CMD :(
#1

Hello everyone im getting trouble with /selldrug commands, can someone help me please? IT consists that u do /selldrugs <id> <amount> and when player clicks on yes on the dialog he gets 1 drug and gets - amount of money, and the seller gets one less drug and more money.. here is my script.. i have already defined all ...

pawn Код:
CMD:selldrugs(playerid, params[])
{
    new pName[24], string[200];
   
    if(sscanf(params, "ui", iId, iAmount))
        return SendClientMessage(playerid, DEEPPINK, "USAGE: /selldrugs <id> <amount>");
       
    if(!IsPlayerConnected(iId))
        return SendClientMessage(playerid, DEEPPINK, "ERROR: Player is not connected");
       
    if(PlayerInfo[playerid][pDrugs] = 0)
        return SendClientMessage(playerid, DEEPPINK, "ERROR: You don't have any drugs to sell");

    if(playerid == iId)
        return SendClientMessage(playerid, DEEPPINK, "ERROR: You can't sell drugs to yourself");
       
    if (GetPlayerMoney(playerid) < iAmount)
        return SendClientMessage(playerid, DEEPPINK, "ERROR: Insufficent funds");
       
    {
        GetPlayerName(playerid, pName, sizeof pName);
        format(string, sizeof(string), ""COL_RED"\t\tDrug Sellers\n\n"COL_RED"%s "COL_WHITE"wants to sell you a drug for "COL_RED"%d "COL_WHITE"amount\nDo you want to you buy one?", pName, iAmount);
        ShowPlayerDialog(iId, DIALOG_SELLDRUGS, DIALOG_STYLE_MSGBOX, ""COL_WHITE"Drug Sellers", string, "Yes", "No");
    }
    return 1;
}
OnDialogResponse

pawn Код:
case DIALOG_SELLDRUGS:
        {
            if(!response)
            {
                return 1;
            }
            if(response)
            {
                PlayerInfo[playerid][pDrugs]--;
                PlayerInfo[iId][pDrugs]++;
                GivePlayerMoney(playerid, iAmount);
                GivePlayerMoney(iId, - iAmount);
            }
            return 1;
        }
please help me , reegards, MiGu3X
Reply
#2

I'd suggest using SetPVarInt and GetPVarInt to store the player ID and amount of cash temporarily so that they can be used when the player hits Yes on the dialog. Here is the wiki documentation on both:

SetPVarInt
GetPVarInt

If you need help understanding how you need to use them just reply and I'll help.
Reply
#3

Yes, idk how to use them, can u help me pleasE? ()_() :=

+

the problem i get is that when i press yes, nothing happens .
Reply
#4

Alrighty, this is what you need to do :

PHP код:
CMD:selldrugs(playeridparams[])
{
    new 
pName[24], string[200];
    
    if(
sscanf(params"ui"iIdiAmount))
        return 
SendClientMessage(playeridDEEPPINK"USAGE: /selldrugs <id> <amount>");
        
    if(!
IsPlayerConnected(iId))
        return 
SendClientMessage(playeridDEEPPINK"ERROR: Player is not connected");
        
    if(
PlayerInfo[playerid][pDrugs] = 0)
        return 
SendClientMessage(playeridDEEPPINK"ERROR: You don't have any drugs to sell");
    if(
playerid == iId)
        return 
SendClientMessage(playeridDEEPPINK"ERROR: You can't sell drugs to yourself");
        
    if (
GetPlayerMoney(playerid) < iAmount)
        return 
SendClientMessage(playeridDEEPPINK"ERROR: Insufficent funds");
        
    {
        
GetPlayerName(playeridpNamesizeof pName);
        
format(stringsizeof(string), ""COL_RED"\t\tDrug Sellers\n\n"COL_RED"%s "COL_WHITE"wants to sell you a drug for "COL_RED"%d "COL_WHITE"amount\nDo you want to you buy one?"pNameiAmount);
        
SetPVarInt(playerid"iAmount"iAmount); //This basically saves a player variable onto that playerid with the names iAmount and iId 
        
SetPVarInt(playerid"iId"iId); // The middle option doesnt have to be the same as the variable you are storing
        
ShowPlayerDialog(iIdDIALOG_SELLDRUGSDIALOG_STYLE_MSGBOX""COL_WHITE"Drug Sellers"string"Yes""No");
    }
    return 
1;
}
//Now onto OnPlayerDialogResponse. 
case DIALOG_SELLDRUGS:
        {
            if(!
response)
            {
                return 
1;
            }
            if(
response)
            {
                new 
iAmountiId
                
iAmount GetPVarInt(playerid"iAmount"); 
                
iId GetPVarInt(playerid"iId"); //Now we are simply getting the player variables which we stored in the command. 
                
DeletePVar(playerid"iAmount");
                
DeletePVar(playerid"iId"); //Just deleting the player variables since we are no longer using them. 
                
                
PlayerInfo[playerid][pDrugs]--;
                
PlayerInfo[iId][pDrugs]++;
                
GivePlayerMoney(playeridiAmount);
                
GivePlayerMoney(iId, - iAmount);
            }
            return 
1;
        } 
It's very easy once you understand how it works.
Reply
#5

the new iAmount, iId; i have at the top of the script, it will maybe bug it or not?
Reply
#6

Just change iAmount and iId in case DIALOG_SELLDRUGS to something else and change it in that dialog to match. Like this:

PHP код:
case DIALOG_SELLDRUGS
        { 
            if(!
response
            { 
                return 
1
            } 
            if(
response
            { 
                new 
AmountpID;  
                
Amount GetPVarInt(playerid"iAmount");  
                
pID GetPVarInt(playerid"iId"); //Now we are simply getting the player variables which we stored in the command.  
                
DeletePVar(playerid"iAmount"); 
                
DeletePVar(playerid"iId"); //Just deleting the player variables since we are no longer using them.  
                 
                
PlayerInfo[playerid][pDrugs]--; 
                
PlayerInfo[pID][pDrugs]++; 
                
GivePlayerMoney(playeridAmount); 
                
GivePlayerMoney(pID, - Amount); 
            } 
            return 
1
        } 
Reply
#7

Bump, still need help, nothing happened :Y
Reply
#8

bump. i got the new iAmount and iID at the top of the script, i did sscanf params after the Ondialogresponse, maybe thats the error, please help :/
Reply
#9

Can i get any help here? N;;;;
Reply
#10

Quote:
Originally Posted by MiGu3X
Посмотреть сообщение
Can i get any help here? N;;;;
it might be because OnDialogResponse is supposed to end with a return 0 according to here (!At The End)
https://sampwiki.blast.hk/wiki/OnDialogResponse
Quote:
Originally Posted by SampWiki;
You MUST return 0 here! Just like OnPlayerCommandText.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)