20.01.2015, 04:22
Quote:
I said that i want that the player offer get availabe in /buypp . So when any player type /buypp a dialog appears and the players offer is in it .
|
pawn Code:
//Not tested
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <foreach>
#define DIALOG_PP_1 50
#define DIALOG_PP_2 51
#define DIALOG_PP_3 52
enum pinfo
{
pp,
pp_amount,
pp_price,
};
new PlayerInfo[MAX_PLAYERS][pinfo];
new dialogarrange[MAX_PLAYERS][32];
public OnPlayerConnect(playerid)
{
for(new j; j<32; j++) dialogarrange[playerid][j] = INVALID_PLAYER_ID;
return 1;
}
CMD:sellpp(playerid, params[])
{
if(PlayerInfo[playerid][pp_amount]) return SendClientMessage(playerid, -1, "You are already selling points, wait till they're sold or use /cancelsellpp");
return ShowPlayerDialog(playerid, DIALOG_PP_1, DIALOG_STYLE_INPUT, "pp sale", "Please enter the amout of points you want to sell", "Proceed", "Cancel");
}
CMD:buypp(playerid, params[])
{
new string[512], smallstring[64], name[MAX_PLAYER_NAME];
foreach(Player, i) if(PlayerInfo[i][pp_amount])
{
GetPlayerName(i, name, MAX_PLAYER_NAME);
format(smallstring, sizeof(smallstring), "%s sells %d Points for %d $\n", name, PlayerInfo[i][pp_amount], PlayerInfo[i][pp_price]);
strcat(string, smallstring);
for(new j; j<32; j++) if(dialogarrange[playerid][j] == INVALID_PLAYER_ID) dialogarrange[playerid][j] = i;
}
if(!strlen(string)) ShowPlayerDialog(playerid, DIALOG_PP_3, DIALOG_STYLE_MSGBOX, "Premium Points", "No one's selling premium points at the moment", "", "Okay");
else ShowPlayerDialog(playerid, DIALOG_PP_3, DIALOG_STYLE_LIST, "Premium Points", string, "", "Okay");
return 1;
}
CMD:cancelsellpp(playerid, params[])
{
if(!PlayerInfo[playerid][pp_amount]) return SendClientMessage(playerid, -1, "You are not selling points");
PlayerInfo[playerid][pp_amount] = 0;
PlayerInfo[playerid][pp_price] = 0;
new string[128], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name));
format(string, 128, "[PREMIUM POINTS] %s has removed his Premium Points from the market.", name), SendClientMessageToAll(-1, string);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_PP_1:
{
if(!response) return 1;
new ppamount = strval(inputtext);
if(ppamount == 0) return ShowPlayerDialog(playerid, DIALOG_PP_1, DIALOG_STYLE_INPUT, "pp sale", "Please enter a valid amount", "Proceed", "Cancel");
if(PlayerInfo[playerid][pp] < ppamount) return ShowPlayerDialog(playerid, DIALOG_PP_1, DIALOG_STYLE_INPUT, "pp sale", "You don't have that much points", "Proceed", "Cancel");
PlayerInfo[playerid][pp_amount] = ppamount;
ShowPlayerDialog(playerid, DIALOG_PP_2, DIALOG_STYLE_INPUT, "Sell Points", "Please enter the price of the points", "Proceed", "Cancel");
}
case DIALOG_PP_2:
{
if(!response) return 1;
new ppamount = strval(inputtext);
if(ppamount == 0) return ShowPlayerDialog(playerid, DIALOG_PP_2, DIALOG_STYLE_INPUT, "pp sale", "Please enter a valid price", "Proceed", "Cancel");
PlayerInfo[playerid][pp_price] = ppamount;
new string[128], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(string, 128, "[PREMIUM POINTS] %s [ID: %d] is selling %d Premium Points for $%d. Type \"/buypp %d\" to buy them!", name, playerid, PlayerInfo[playerid][pp_amount], PlayerInfo[playerid][pp_price], playerid);
SendClientMessageToAll(-1, string);
}
case DIALOG_PP_3:
{
if(!response) return 1;
new id = dialogarrange[playerid][listitem];
if(GetPlayerMoney(playerid) < PlayerInfo[id][pp_price]) return SendClientMessage(playerid, -1, "You do not have enough money.");
PlayerInfo[playerid][pp] += PlayerInfo[id][pp_amount];
PlayerInfo[id][pp] -= PlayerInfo[id][pp_amount];
GivePlayerMoney(playerid, -PlayerInfo[id][pp_price]);
GivePlayerMoney(id, PlayerInfo[id][pp_price]);
new string[128], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME);
new othername[MAX_PLAYER_NAME]; GetPlayerName(id, othername, MAX_PLAYER_NAME);
format(string, 128, "[PREMIUM POINTS] %s has bought %d Premium Points from %s for $%d.", name, PlayerInfo[id][pp_amount], othername, PlayerInfo[id][pp_price]);
SendClientMessageToAll(-1, string);
for(new j; j<32; j++) dialogarrange[playerid][j] = INVALID_PLAYER_ID;
return 1;
}
}
return 0;
}
stock IsNumeric(string[])
{
for (new i; i < strlen(string); i++) if (string[i] > '9' || string[i] < '0') return false;
return true;
}