GivePlayerMoney Problem
#1

Hello, I got a problem with GivePlayerMoney. When i buy something. i dont loose money. I recive money instead.

This is my dialogid where you buy stuff from

pawn Код:
if(dialogid == WEAPON) // Credits to Etch for making half & Credits to AlexzzPro for making the other half.
    {
        if(response)
        {
            if(listitem == 0) //Knife
            {
                if(GetPlayerMoney(playerid) < 200)
                {
                    EnoughMoney(playerid,200);
                }
                else
                {
                    GivePlayerWeapon(playerid,4,1);
                    SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A Knife (200$)");
                    GivePlayerMoney(playerid,-200);
                    }
                }
             if(listitem == 1) //Deagle
             {
                if(response)
                {
                    if(GetPlayerMoney(playerid) < 500)
                    {
                        EnoughMoney(playerid,500);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid,24,50);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A Desert Eagle (500$)");
                        GivePlayerMoney(playerid,-500);
                    }
                }
            }
            if(listitem == 2) //MP5
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) < 1000)
                    {
                        EnoughMoney(playerid,1000);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid,29,200);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A MP5 (1000$)");
                        GivePlayerMoney(playerid,-1000);
                    }
                }
            }
            if(listitem == 3) //M4
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) < 1000)
                    {
                        EnoughMoney(playerid,1000);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid,31,200);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A M4 (1000$)");
                        GivePlayerMoney(playerid,-1000);
                    }
                }
            }
            if(listitem == 4) //AK47
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) < 1300)
                    {
                        EnoughMoney(playerid,1300);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid,30,200);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A AK-47 (1300$)");
                        GivePlayerMoney(playerid,-1300);
                    }
                }
            }
            if(listitem == 5) //Sniper
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) <1500)
                    {
                        EnoughMoney(playerid,1500);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid, 34, 40);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A Sniper (1500$)");
                        GivePlayerMoney(playerid,-1500);
                    }
                }
            }
            if(listitem == 6) //Shotgun
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) <1000)
                    {
                        EnoughMoney(playerid,1000);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid, 25,50);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought A Shotgun (1000$)");
                        GivePlayerMoney(playerid,-1000);
                    }
                }
            }
            if(listitem == 7) //Grenades
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) <800)
                    {
                        EnoughMoney(playerid,800);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid,16,10);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought 10 Grenades (800$)");
                        GivePlayerMoney(playerid,-800);
                    }
                }
            }
            if(listitem == 8) //Bombs
            {
                if(response)
                {
                    if(GetPlayerMoney(playerid) <1000)
                    {
                        EnoughMoney(playerid,1000);
                    }
                    else
                    {
                        GivePlayerWeapon(playerid,39,8);
                        SendClientMessage(playerid,COLOR_YELLOW,"You've Succesfully Bought 8 bombs (1000$)");
                        GivePlayerMoney(playerid,GetPlayerMoney(playerid)-1000);
                    }
                }
            }
        }
    }
    return 1;
}
What is the problem lol?

it gives money instead of taking
Reply
#2

pawn Код:
GivePlayerMoney(playerid, GetPlayerMoney(playerid) - (200));
Reply
#3

try using this stock :

pawn Код:
stock SetPlayerMoney(playerid,Money)
{
       ResetPlayerMoney(playerid);
       return GivePlayerMoney(playerid,Money);
}
then use :
pawn Код:
new pMoney = GetPlayerMoney(playerid);
SetPlayerMoney(playerid,pMoney-200)
Reply
#4

Quote:
Originally Posted by CyNiC
Посмотреть сообщение
pawn Код:
GivePlayerMoney(playerid, GetPlayerMoney(playerid) - (200));
It still gives money.

And it gives 800 :S for some reason
Reply
#5

Код:
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-200);
Further Details for anyone who might come across this post with similar problems: The above code doesn't work because GetPlayerMoney(800) - 200 is 600, so it's the same as: GivePlayerMoney(playerid,600);
Thus giving the player $600 on top of what he already has... You must reset the Player's Money in order to get it back to 0, then give the altered money as shown in the code below:

Код:
new money;
money=GetPlayerMoney(playerid);
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid,money-200);
EDIT: Fixed & Explained
Reply
#6

That fails to. But that is all i have that is with money to do
Reply
#7

Not sure about this but what does this line
pawn Код:
EnoughMoney(playerid,200);
actually do ?..maybe thats the reason for the money give back to comment it out and test it
Reply
#8

Quote:
Originally Posted by xerox8521
Посмотреть сообщение
Not sure about this but what does this line
pawn Код:
EnoughMoney(playerid,200);
actually do ?..maybe thats the reason for the money give back to comment it out and test it
Yea, Xerox is on the right track, the problem is most likely in your EnoughMoney() Function... If you still can't seem to figure out the problem that is likely in that function, then post it for the people here so they may help out
Reply
#9

This is the EnoughMoney stock.

pawn Код:
stock EnoughMoney(playerid,Money) // Credits to Etch
{
    new string[128];
    format(string,sizeof(string),"You Don't Have Enough Money (%d$)",Money);
    return SendClientMessage(playerid,COLOR_RED,string);
}
Reply
#10

Sorry for double post but i fixed the problem :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)