help with dialog
#1

When i buy weapon and i have 0$ the weapon is purchased and my money gets -, how to prevent this and if someone dont have money the dialog is closed and message that he dont have money is sent?



public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_GUN)
{
if(response)
{

if(listitem == 0)
{
GivePlayerMoney(playerid, -1000);
GivePlayerWeapon(playerid, 24, 100);
}
if(listitem == 1)
{
GivePlayerMoney(playerid, -2500);
GivePlayerWeapon(playerid, 25, 100);
}
if(listitem == 2)
{
GivePlayerMoney(playerid, -5000);
GivePlayerWeapon(playerid, 31, 200);
}
if(listitem == 3)
{
GivePlayerMoney(playerid, -5000);
GivePlayerWeapon(playerid, 30, 200);
}
if(listitem == 4)
{
GivePlayerMoney(playerid, -3000);
GivePlayerWeapon(playerid, 34, 50);
}
if(listitem == 5)
{
GivePlayerMoney(playerid, -1000);
GivePlayerWeapon(playerid, 16, 2);
}
if(listitem == 6)
{
GivePlayerMoney(playerid, -15000);
GivePlayerWeapon(playerid, 35, 1);
}
if(listitem == 7)
{
GivePlayerMoney(playerid, -2500);
SetPlayerArmour(playerid, 100);
}
}
//the other dialog ....
Reply
#2

GetPlayerMoney. You should really use server-sided money though, to prevent the use of cheats.
Reply
#3

i hope for this help you

if(GetPlayerMoney(playerid) < 500)
{
SendClientMessage(playerid, COLOR_RED, "You don't have enough money($500)");
}
if(GetPlayerMoney(playerid) > 500)//get's the player's money
{
GivePlayerMoney(playerid, -500);
}
}
Reply
#4

1. Why two if statements? Why not use else or even better, return?
2. Use PAWN tags (both of you!)
3. Indentation - heard of it?
4. Nothing will happen if the player has exactly $500.

pawn Код:
if(GetPlayerMoney(playerid) < 500) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money ($500).");
// Code for giving weapon here
Reply
#5

im newbie, i dont understand much, and with the zerowizard's code i get many errors, MP2 helped me thanks!
Reply
#6

This is only to show you how you can do it.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_GUN)
    {
        if(response)
        {
            if(listitem == 0)
            {
                if(GetPlayerMoney(playerid) < 1000)
                {
                    SendClientMessage(playerid, -1, "You don't have enough money.");
                    return 1;
                }
                else
                {
                    GivePlayerMoney(playerid, -1000);
                    GivePlayerWeapon(playerid, 24, 100);
                }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)