CMD:givepp(playerid, params[])
{
LoginCheck(playerid);
if(User[playerid][accountAdmin] >= 3)
{
new string[150] , id, amount;
if(sscanf(params, "ui", id, amount)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givepp [playerid] [amount]");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "» "red"Player not connected.");
if(User[id][accountLogged] == false) return SendClientMessage(playerid, -1, "» "red"Player not logged in.");
format(string, 150, "[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points.", GetName(playerid), GetName(id), amount);
SendAMessage(-1, string);
format(string, 150, ""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white".", amount, User[id][accountPP]+amount);
SendClientMessage(id, -1, string);
format(string, 150, "» You have given {%06x}%s "white"premium points of "grey"%d"white".", GetPlayerColor(id) >>> 8, GetName(id), amount);
SendClientMessage(playerid, -1, string);
format(string, 128, "%s received %d Premium Points from %s.", GetName(id), amount, GetName(playerid));
Log("premium.txt", string);
User[id][accountPP] += amount;
}
else
{
SendClientMessage(playerid, -1, "» "red"You are not authorized to use this command.");
}
return 1;
}
new pp_amount[MAX_PLAYERS];
new pp_price[MAX_PLAYERS];
COMMAND:sellpp(playerid, params[])
{
new amount, price, string[150];
if(sscanf(params, "ii", amount, price)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /sellpp [amount] [price]");
if(pp_amount[playerid] > 0) return SendClientMessage(playerid, COLOR_RED, "You are already selling points, wait till they're sold or use /cancelsellpp");
if(User[playerid][accountPP] < amount) return SendClientMessage(playerid, COLOR_RED, "You do not have that many points");
if(price < 1) return SendClientMessage(playerid, COLOR_RED, "Set a price of at least $1");
pp_amount[playerid] = amount;
pp_price[playerid] = price;
format(string, 150, "[PREMIUM POINTS] %s [ID: %d] is selling %d Premium Points for $%d. Type \"/buypp %d\" to buy them!", GetName(playerid), playerid, amount, price, playerid);
SendClientMessageToAll(-1, string);
return 1;
}
COMMAND:buypp(playerid, params[])
{
new id, string[150];
if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /buypp [playerid]");
if(pp_amount[id] > 1) return SendClientMessage(playerid, COLOR_RED, "This player is not selling Premium Points");
if(GetPlayerMoney(playerid) < pp_price[id]) return SendClientMessage(playerid, COLOR_RED, "You do not have enough money.");
User[playerid][accountPP] += pp_amount[id];
User[id][accountPP] -= pp_amount[id];
GivePlayerMoney(playerid, -pp_price[id]);
GivePlayerMoney(id, pp_price[id]);
format(string, 150, "[PREMIUM POINTS] %s has bought %d Premium Points from %s for $%d.", GetName(playerid), pp_amount[id], GetName(id), pp_price[id]);
SendClientMessageToAll(-1, string);
return 1;
}
COMMAND:cancelsellpp(playerid, params[])
{
if(pp_amount[playerid] < 1) return SendClientMessage(playerid, COLOR_RED, "You are not selling points");
pp_amount[playerid] = 0;
pp_price[playerid] = 0;
format(string, 150, "[PREMIUM POINTS] %s has removed his Premium Points from the market.", GetName(playerid));
SendClientMessageToAll(-1, string);
return 1;
}
Do you want to sell it to specific player that you wrote his id or to make it buyable so any one can buy it ?
|
//Not tested, might have some slight bugs
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define DIALOG_PP_1 50
#define DIALOG_PP_2 51
enum pinfo
{
pp,
pp_amount,
pp_price,
};
new PlayerInfo[MAX_PLAYERS][pinfo];
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 id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, -1, "USAGE: /buypp [playerid]");
if(PlayerInfo[id][pp_amount] > 1) return SendClientMessage(playerid, -1, "This player is not selling Premium Points");
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);
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 0;
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 0;
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);
}
}
return 0;
}
stock IsNumeric(string[])
{
for (new i; i < strlen(string); i++) if (string[i] > '9' || string[i] < '0') return false;
return true;
}
An edit from Schneider's one
pawn Code:
|
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 .
|
//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;
}