buying and selling
#1

Hello , i have points system . I want to have function that when player type /sell he can sell his points by giving how much points he want to sell and amount of money and after clicking on sell button in dialog his points added in /buy so players can buy them from /buy if they have that amount of money .
PHP Code:
CMD:givepp(playeridparams[])
{
    
LoginCheck(playerid);
    if(
User[playerid][accountAdmin] >= 3)
    {
        new 
string[150] , idamount;
        if(
sscanf(params"ui"idamount)) return SendClientMessage(playeridCOLOR_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(string150"[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points."GetName(playerid), GetName(id), amount);
        
SendAMessage(-1string);
        
format(string150""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white"."amountUser[id][accountPP]+amount);
        
SendClientMessage(id, -1string);
        
format(string150"» You have given {%06x}%s "white"premium points of "grey"%d"white"."GetPlayerColor(id) >>> 8GetName(id), amount);
        
SendClientMessage(playerid, -1string);
        
format(string128"%s received %d Premium Points from %s."GetName(id), amountGetName(playerid));
        
Log("premium.txt"string);
          
User[id][accountPP] += amount;
          
      
    }
    else
    {
        
SendClientMessage(playerid, -1"» "red"You are not authorized to use this command.");
    }
    return 
1;

Reply
#2

Can you explain more in what you need help with? It's not very clear.
The code above should work.
Reply
#3

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 ?
Reply
#4

It's not exactly what you want, I'm not so good with dialogs yet so I've created these 3 commands which basically does the same.
A player choose how many of his premium points he can sell and for what price. "/sellpp [amount] [price]"
An other player can buy them by using /buypp [playerid]
The seller can also cancel the selling by using /cancelsellpp

I hope this will be useful for you. Change the stuff like color of strings to your own liking.

pawn Code:
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;
}
Reply
#5

Quote:
Originally Posted by nezo2001
View Post
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 ?
No , i want a function of dialog . When player use /sellpoints or /sell a dialog appears in which he enter the points how much he want to sell then another dialog appear in which he enter the amount for which he want to sell . So then his offer get available in /market and players can buy it from /market by clicking on his offer.

Schneider, Thanks bro .

If any one make a function with dialog so please make it.
Reply
#6

An edit from Schneider's one

pawn Code:
//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;
}
Reply
#7

Quote:
Originally Posted by xVIP3Rx
View Post
An edit from Schneider's one

pawn Code:
//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;
}
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 .
Reply
#8

Quote:
Originally Posted by Arxalan
View Post
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;
}
Reply
#9

It is a bit different for what i am thinking but now i can change it according to my idea. Thanks +rep .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)