Jump to content

[SOLVED]Problem with money


HeK

Recommended Posts

Hey there! I really need help on this one, when i go to the shop "script" i buy some guns until i have no money and then when i kill a zombie my money comes back.

Shop Script:

Client Side( i used "code" for this script, for some reason i couldn't use "lua"):

GUIEditor_Window = {} 
GUIEditor_TabPanel = {}
GUIEditor_Tab = {}
GUIEditor_Button = {}
 
addEventHandler ("onClientResourceStart",getResourceRootElement(getThisResource()),
function()
 
GUIEditor_Window[1] = guiCreateWindow(0.3,0.0850,0.4000,0.4600,"Zombie Hazard - Weapon Shop",true)
guiSetAlpha(GUIEditor_Window[1],1)
GUIEditor_Window[2] = guiCreateWindow(0.3,0.15,0.30,0.1,"Oh damn!",true)
guiSetAlpha(GUIEditor_Window[2],1)
guiBringToFront(GUIEditor_Window[2])
label = guiCreateLabel (0.20,0.25,0.65,0.3,"You dont have enough money to buy that.",true,GUIEditor_Window[2])
button = guiCreateButton (0.35,0.6,0.3,0.2,"Ok",true,GUIEditor_Window[2])
GUIEditor_TabPanel[1] = guiCreateTabPanel(0.0161,0.1006,0.9678,0.8786,true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_TabPanel[1],1)
GUIEditor_Tab[1] = guiCreateTab("Pistols",GUIEditor_TabPanel[1])
guiSetAlpha(GUIEditor_Tab[1],1)
guiCreateStaticImage (0.051,0.2,0.2,0.25,"images/pistol.png",true,GUIEditor_Tab[1])
guiCreateStaticImage (0.4,0.2,0.2,0.25,"images/silenced.png",true,GUIEditor_Tab[1])
guiCreateStaticImage (0.75,0.2,0.2,0.25,"images/deagle.png",true,GUIEditor_Tab[1])
GUIEditor_Button[1] = guiCreateButton(0.025,0.5,0.2493,0.0934,"Pistol $100",true,GUIEditor_Tab[1])
guiSetAlpha(GUIEditor_Button[1],1)
guiSetFont(GUIEditor_Button[1],"default-bold-small")
GUIEditor_Button[2] = guiCreateButton(0.3786,0.5,0.2493,0.0934,"Silenced $200",true,GUIEditor_Tab[1])
guiSetAlpha(GUIEditor_Button[2],1)
guiSetFont(GUIEditor_Button[2],"default-bold-small")
GUIEditor_Button[3] = guiCreateButton(0.7204,0.5,0.2493,0.0934,"Desert Eagle $600",true,GUIEditor_Tab[1])
guiSetAlpha(GUIEditor_Button[3],1)
guiSetFont(GUIEditor_Button[3],"default-bold-small")
GUIEditor_Tab[2] = guiCreateTab("Shotguns",GUIEditor_TabPanel[1])
guiSetAlpha(GUIEditor_Tab[2],1)
guiCreateStaticImage (0.051,0.2,0.2,0.25,"images/shotgun.png",true,GUIEditor_Tab[2])
guiCreateStaticImage (0.4,0.2,0.2,0.25,"images/sawnoff.png",true,GUIEditor_Tab[2])
guiCreateStaticImage (0.75,0.2,0.2,0.25,"images/SPAZ-12.png",true,GUIEditor_Tab[2])
GUIEditor_Button[4] = guiCreateButton(0.025,0.5,0.2493,0.0934,"Shotgun $500",true,GUIEditor_Tab[2])
guiSetAlpha(GUIEditor_Button[4],1)
guiSetFont(GUIEditor_Button[4],"default-bold-small")
GUIEditor_Button[5] = guiCreateButton(0.3786,0.5,0.2493,0.0934,"Sawn off $700",true,GUIEditor_Tab[2])
guiSetAlpha(GUIEditor_Button[5],1)
guiSetFont(GUIEditor_Button[5],"default-bold-small")
GUIEditor_Button[6] = guiCreateButton(0.7204,0.5,0.2493,0.0934,"SPAZ-12 $1000",true,GUIEditor_Tab[2])
guiSetAlpha(GUIEditor_Button[6],1)
guiSetFont(GUIEditor_Button[6],"default-bold-small")
GUIEditor_Tab[3] = guiCreateTab("SMG",GUIEditor_TabPanel[1])
guiSetAlpha(GUIEditor_Tab[3],1)
guiCreateStaticImage (0.051,0.2,0.2,0.25,"images/tec9.png",true,GUIEditor_Tab[3])
guiCreateStaticImage (0.4,0.2,0.2,0.25,"images/uzi.png",true,GUIEditor_Tab[3])
guiCreateStaticImage (0.75,0.2,0.2,0.25,"images/mp5.png",true,GUIEditor_Tab[3])
GUIEditor_Button[7] = guiCreateButton(0.025,0.5,0.2493,0.0934,"TEC-9 $400",true,GUIEditor_Tab[3])
guiSetAlpha(GUIEditor_Button[7],1)
guiSetFont(GUIEditor_Button[7],"default-bold-small")
GUIEditor_Button[8] = guiCreateButton(0.3786,0.5,0.2493,0.0934,"Uzi $600",true,GUIEditor_Tab[3])
guiSetAlpha(GUIEditor_Button[8],1)
guiSetFont(GUIEditor_Button[8],"default-bold-small")
GUIEditor_Button[9] = guiCreateButton(0.7204,0.5,0.2493,0.0934,"MP5 $800",true,GUIEditor_Tab[3])
guiSetAlpha(GUIEditor_Button[9],1)
guiSetFont(GUIEditor_Button[9],"default-bold-small")
GUIEditor_Tab[4] = guiCreateTab("Assault Rifles",GUIEditor_TabPanel[1])
guiSetAlpha(GUIEditor_Tab[4],1)
guiCreateStaticImage (0.2,0.2,0.2,0.25,"images/M4.png",true,GUIEditor_Tab[4])
guiCreateStaticImage (0.58,0.2,0.2,0.25,"images/AK-47.png",true,GUIEditor_Tab[4])
GUIEditor_Button[10] = guiCreateButton(0.18,0.5,0.2493,0.0934,"M4 $2000",true,GUIEditor_Tab[4])
guiSetAlpha(GUIEditor_Button[10],1)
guiSetFont(GUIEditor_Button[10],"default-bold-small")
GUIEditor_Button[11] = guiCreateButton(0.556,0.5,0.2493,0.0934,"AK-47 $1000",true,GUIEditor_Tab[4])
guiSetAlpha(GUIEditor_Button[11],1)
guiSetFont(GUIEditor_Button[11],"default-bold-small")
GUIEditor_Tab[5] = guiCreateTab("Sniper Rifles",GUIEditor_TabPanel[1])
guiSetAlpha(GUIEditor_Tab[5],1)
guiCreateStaticImage (0.2,0.2,0.2,0.25,"images/rifle.png",true,GUIEditor_Tab[5])
guiCreateStaticImage (0.58,0.2,0.2,0.25,"images/sniper.png",true,GUIEditor_Tab[5])
GUIEditor_Button[12] = guiCreateButton(0.18,0.5,0.2493,0.0934,"Country Sniper $1000",true,GUIEditor_Tab[5])
guiSetAlpha(GUIEditor_Button[12],1)
guiSetFont(GUIEditor_Button[12],"default-bold-small")
GUIEditor_Button[13] = guiCreateButton(0.556,0.5,0.2493,0.0934,"Sniper $3000",true,GUIEditor_Tab[5])
guiSetAlpha(GUIEditor_Button[13],1)
guiSetFont(GUIEditor_Button[13],"default-bold-small")
GUIEditor_Tab[8] = guiCreateTab("Special",GUIEditor_TabPanel[1])
guiSetAlpha(GUIEditor_Tab[8],1)
guiCreateStaticImage (0.2,0.2,0.2,0.25,"images/health.png",true,GUIEditor_Tab[8])
guiCreateStaticImage (0.58,0.2,0.2,0.25,"images/armor.png",true,GUIEditor_Tab[8])
GUIEditor_Button[25] = guiCreateButton(0.18,0.5,0.2493,0.0934,"Health $1000",true,GUIEditor_Tab[8])
guiSetAlpha(GUIEditor_Button[25],1)
guiSetFont(GUIEditor_Button[25],"default-bold-small")
GUIEditor_Button[26] = guiCreateButton(0.556,0.5,0.2493,0.0934,"Protection $1500",true,GUIEditor_Tab[8])
guiSetAlpha(GUIEditor_Button[26],1)
guiSetFont(GUIEditor_Button[26],"default-bold-small")
GUIEditor_Button[29] = guiCreateButton(0.85,0.0574,0.1420,0.0400,"Exit",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Button[29],1)
guiSetFont(GUIEditor_Button[29],"default-bold-small")
GUIEditor_Button[30] = guiCreateButton(0,0,0.2453,0.0854,"Exit",true,GUIEditor_Window[2])
guiSetAlpha(GUIEditor_Button[30],1)
guiSetFont(GUIEditor_Button[30],"default-bold-small")
 
guiSetVisible (GUIEditor_Window[1],false)
guiSetVisible (GUIEditor_Window[2],false)
end)
 
 
addEventHandler("onClientGUIClick",getRootElement(),
function (player)
            if (source == GUIEditor_Button[29]) then
                guiSetVisible (GUIEditor_Window[1],false)
                showCursor (false)
            elseif (source == GUIEditor_Button[30]) then
                guiSetVisible (GUIEditor_Window[2],false)
                showCursor (false)
            elseif (source == GUIEditor_Button[1]) then
                money = getPlayerMoney (source)
                if (money >= 100) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Pistol $100",225,225,0)
                takePlayerMoney(100)
                triggerServerEvent ("give45",getLocalPlayer(),give45)
                else
                guiSetVisible(GUIEditor_Window[2],true)
                guiSetVisible(GUIEditor_Window[1],false)
                end
            elseif (source == GUIEditor_Button[2]) then
                money = getPlayerMoney (source)
                if (money >= 200) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Silenced $200",225,225,0)
                takePlayerMoney(200)
                triggerServerEvent ("givesilenced",getLocalPlayer(),givesilenced)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[3]) then
                money = getPlayerMoney (source)
                if (money >= 600) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Desert Eagle $600",225,225,0)
                takePlayerMoney(600)
                triggerServerEvent ("givedeagle",getLocalPlayer(),givedeagle)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[4]) then
                money = getPlayerMoney (source)
                if (money >= 500) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Shotgun $500",225,225,0)
                takePlayerMoney(500)
                triggerServerEvent ("givesh",getLocalPlayer(),givesh)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[5]) then
                money = getPlayerMoney (source)
                if (money >= 700) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Sawn Off $700",225,225,0)
                takePlayerMoney(700)
                triggerServerEvent ("giveso",getLocalPlayer(),giveso)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[6]) then
                money = getPlayerMoney (source)
                if (money >= 1000) then
                player = getLocalPlayer()
                outputChatBox ("You bought a SPAZ-12 $1000",225,225,0)
                takePlayerMoney(1000)
                triggerServerEvent ("giveSP",getLocalPlayer(),giveSP)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[7]) then
                money = getPlayerMoney (source)
                if (money >= 400) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Tec-9 $400",225,225,0)
                takePlayerMoney(400)
                triggerServerEvent ("givetec",getLocalPlayer(),givetec)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[8]) then
                money = getPlayerMoney (source)
                if (money >= 600) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Uzi $600",225,225,0)
                takePlayerMoney(600)
                triggerServerEvent ("giveuzi",getLocalPlayer(),giveuzi)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[9]) then
                money = getPlayerMoney (source)
                if (money >= 800) then
                player = getLocalPlayer()
                outputChatBox ("You bought a MP5 $800",225,225,0)
                takePlayerMoney(800)
                triggerServerEvent ("givemp5",getLocalPlayer(),givemp5)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[11]) then
                money = getPlayerMoney (source)
                if (money >= 1000) then
                player = getLocalPlayer()
                outputChatBox ("You bought an AK-47 $1000",225,225,0)
                takePlayerMoney(1000)
                triggerServerEvent ("giveak",getLocalPlayer(),giveak)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[10]) then
                money = getPlayerMoney (source)
                if (money >= 2000) then
                player = getLocalPlayer()
                outputChatBox ("You bought a M4 $2000",225,225,0)
                takePlayerMoney(2000)
                triggerServerEvent ("givem4",getLocalPlayer(),givem4)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[13]) then
                money = getPlayerMoney (source)
                if (money >= 3000) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Sniper $3000",225,225,0)
                takePlayerMoney(3000)
                triggerServerEvent ("gives",getLocalPlayer(),gives)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
            elseif (source == GUIEditor_Button[12]) then
                money = getPlayerMoney (source)
                if (money >= 1000) then
                player = getLocalPlayer()
                outputChatBox ("You bought a Country Sniper $1000",225,225,0)
                takePlayerMoney(1000)
                triggerServerEvent ("givecs",getLocalPlayer(),givecs)
                else
                guiSetVisible(GUIEditor_Window[1],false)
                guiSetVisible(GUIEditor_Window[2],true)
                end
Edited by Guest
Link to comment
addEvent("wep1", true) 
addEventHandler("wep1", l_0_0, function() 
  if getPlayerMoney(source) >= 150 then 
    takePlayerMoney(source, 150) 
    giveWeapon(source, 24, 700) 
    setPedWeaponSlot(source, getSlotFromWeapon(24)) 
    local l_2_0 = getPlayerName(source) 
    outputChatBox("#ffffff[#FFFF00 " .. l_2_0 .. "#ffffff]===>#ffccff Has Bought deagle #00ff00$150 #ffccff...", getRootElement(), 255, 0, 0, true) 
  else 
    outputChatBox("You don't have $150 to buy deagle", source, 255, 0, 0, true) 
  end 
end 
) 

Link to comment

Ok i changed it to Server Side, but now it says "TakePlayerMoney" bad argument.

This is how i did it:

function gives () 
giveWeapon (source,34,40,true) 
takePlayerMoney(3000) 
end 
addEvent("gives",true) 
addEventHandler("gives",getRootElement(),gives) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...