SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/01/2015, 04:50 AM   #1
Arxalan
Banned
 
Join Date: Feb 2014
Location: In your heart
Posts: 366
Reputation: 38
Default buying and selling

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;

Arxalan is offline   Reply With Quote
Old 19/01/2015, 12:41 PM   #2
Ciarannn
Big Clucker
 
Join Date: Feb 2014
Posts: 195
Reputation: 15
Default Re: buying and selling

Can you explain more in what you need help with? It's not very clear.
The code above should work.
__________________
If it's stupid and it works, it ain't stupid.
Ciarannn is offline   Reply With Quote
Old 19/01/2015, 12:55 PM   #3
nezo2001
Gangsta
 
Join Date: Nov 2014
Location: Cairo, Egypt
Posts: 680
Reputation: 26
Default Re: buying and selling

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 ?
__________________
Quote:
Originally Posted by Human
When im met u, u were nub at scripting xD.

But now, i'm impressed. Good job.
Don't look at my history. Everyone started somewhere
nezo2001 is offline   Reply With Quote
Old 19/01/2015, 02:07 PM   #4
Schneider
Gangsta
 
Schneider's Avatar
 
Join Date: Jun 2007
Location: Netherlands
Posts: 515
Reputation: 136
Default Re: buying and selling

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;
}
Schneider is offline   Reply With Quote
Old 19/01/2015, 02:46 PM   #5
Arxalan
Banned
 
Join Date: Feb 2014
Location: In your heart
Posts: 366
Reputation: 38
Default Re: buying and selling

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.
Arxalan is offline   Reply With Quote
Old 19/01/2015, 06:24 PM   #6
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,098
Reputation: 96
Default Re: buying and selling

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;
}

Last edited by xVIP3Rx; 19/01/2015 at 07:13 PM.
xVIP3Rx is offline   Reply With Quote
Old 20/01/2015, 03:45 AM   #7
Arxalan
Banned
 
Join Date: Feb 2014
Location: In your heart
Posts: 366
Reputation: 38
Default Re: buying and selling

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 .
Arxalan is offline   Reply With Quote
Old 20/01/2015, 04:22 AM   #8
xVIP3Rx
High-roller
 
xVIP3Rx's Avatar
 
Join Date: Feb 2013
Location: Egypt
Posts: 1,098
Reputation: 96
Default Re: buying and selling

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;
}
xVIP3Rx is offline   Reply With Quote
Old 20/01/2015, 04:37 AM   #9
Arxalan
Banned
 
Join Date: Feb 2014
Location: In your heart
Posts: 366
Reputation: 38
Default Re: buying and selling

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Help] Buying and Selling Arxalan Scripting Help 0 18/01/2015 03:31 PM
Buying a VPS Black Axe Server Support 15 05/02/2012 03:59 AM
Buying GM. ricardo178 Help Archive 2 07/06/2011 08:16 PM
Buying ViruZZzZ_ChiLLL Help Archive 2 28/04/2010 08:20 AM
Buying help XtremeChio Help Archive 3 08/08/2009 09:03 PM


All times are GMT. The time now is 10:17 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.