PDA

View Full Version : Problem with PVars


GuitarMan
16/02/2015, 08:12 PM
So heres a code. Its a command that lets player A to sell something to player B.

case D_Tuning+29:
{
if(response)
{
new playered = GetPVarInt(playerid, "Someone");
new CPrice = inputtext[0];
format(string, 200, "Would you like to buy this and that from %s for %s....?", sendername(playerid),CPrice);
ShowPlayerDialog(playered, D_Tunings+30, 1, "Selection", string, "yes", "No");
return 1;
}

}


CMD:onetwothree(playerid, params[])
{
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(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

ShowPlayerDialog(playered, D_Tunings+30, 1, "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:
ShowPlayerDialog(playered, D_Tunings+30, 1, "Selection", string, "yes", "No");

xVIP3Rx
16/02/2015, 08:19 PM
Nevermind.

GuitarMan
16/02/2015, 08:28 PM
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?

xVIP3Rx
16/02/2015, 08:43 PM
Sorry for misunderstanding, this should work

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.