Problem with PVars
#1

So heres a code. Its a command that lets player A to sell something to player B.

PHP Code:
        case D_Tuning+29:
        {
            if(
response)
            {
                new 
playered GetPVarInt(playerid"Someone");
                new 
CPrice inputtext[0];
                
format(string200"Would you like to buy this and that from %s for %s....?"sendername(playerid),CPrice);
                
ShowPlayerDialog(playeredD_Tunings+301"Selection"string"yes""No");
                return 
1;
            }
        }
        
        
CMD:onetwothree(playeridparams[])
{
        
format(string200"Insert the amount of cash you want to get for something...");
        
ShowPlayerDialog(playeridD_Tunings+291"amount"string"yes""No");
        
SetPVarInt(params[0], "Someone"playerid);
    return 
1;

So what i was trying to do there is, after the command "onetwothree is called, player A chooses how much cash he wants to get, and the system is supposed to set PVar on player B so that i can use player B inside my dialogs. So in dialogs playered is ment to be the player B, but somehow it displays it as player A

PHP Code:
                ShowPlayerDialog(playeredD_Tunings+301"Selection"string"yes""No"); 
It displays this code to player A not player B altho it should display it to player B.

Also, im struggling to set the input from the dialog to variable. After player A makes the choice how much cash he would like to get for this thing, the price gets saved to variable CPrice. But after trying to display it in the string, it prints just the first number.... Lets say, if i chose to sell something for 4000 euros, it would only display the 4.... Speaking abt this line:
PHP Code:
                ShowPlayerDialog(playeredD_Tunings+301"Selection"string"yes""No"); 
Reply
#2

Nevermind.
Reply
#3

Well the command is used like
/onetwothree 2

2 represents the players ID. Like, if player A wants to sell something to player B, than 2 represents the player B ID.

Anyways how do i save the players ID then and pass it to the dialog?
Reply
#4

Sorry for misunderstanding, this should work
pawn Code:
case D_Tuning+29:
        {
            if(response)
            {
                if(!IsNumeric(params)) ShowPlayerDialog(playerid, D_Tunings+29, 1, "amount", "Please insert a valid price", "yes", "No");

                new CPrice = strval(inputtext);
                format(string, 200, "Would you like to buy something from %s for $%s....?", GetName(playerid), CPrice);
                ShowPlayerDialog(GetPVarInt(playerid,"Someone"), D_Tunings+30, 1, "Selection", string, "yes", "No");
               
                return 1;
            }
        }
        case D_Tunings+30:
        {
            if(response)
            {
                //if he clicked on YES, do this.
                return 1;
            }
            else //If he clicked on no
        }


CMD:onetwothree(playerid, params[])
{
    if(!IsNumeric(params)) return SendClientMessage(playerid, -1, "Not a valid id/number");

    format(string, 200, "Insert the amount of cash you want to get for something...");
    ShowPlayerDialog(playerid, D_Tunings+29, 1, "amount", string, "yes", "No");
   
    SetPVarInt(playerid, "Someone", strval(params));
    return 1;
}

stock IsNumeric(string[])
{
    for (new i; i < strlen(string); i++) if('0' >= string[i] >= '9') return 0;

    return 1;
}
I suggest adding more checks, check if the string is empty or if the price is 0 or more than some number.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)