Jump to content

setElementData help


Raizel

Recommended Posts

hello, im trying to make a bank system and when i try to withdraw the money it doesnt take away my money in the bank,

 

this is the client side script

loadstring(exports.dgs:dgsImportFunction())()
local windows = window,label1,label2,button1,button2

sx, sy = dgsGetScreenSize()
easing = "OutBack"
--data
setElementData(localPlayer, "bank", "100")
bank11 = getElementData (localPlayer, "bank")

--window 
window = dgsCreateImage(sx*0.360, sy*0.3, sx*0.330, sy*0.2,_,false,_, tocolor(0,0,0,140))


label1 = dgsCreateImage(sx*0.360, sy*0.270, sx*0.330, sy*0.030,_,false,_, tocolor(0,255,255,100))
label2 = dgsCreateLabel(sx*0.450, sy*0.270, sx*0.330, sy*0.030, "Bank !!")
dgsSetProperty(label2,"textSize",{sx*0.004, sy*0.002})

-- buttons
button1 = dgsCreateButton(sx*0.370, sy*0.360, sx*0.150, sy*0.080, "kivetel",false, _, _, _,_,_, _,_,tocolor(0,255,255,100), tocolor(0,255,255,150), tocolor(0,255,255,255))
button2 = dgsCreateButton(sx*0.530, sy*0.360, sx*0.150, sy*0.080, "befektetes",false, _, _, _,_,_, _,_,tocolor(255,255,255,100), tocolor(255,255,255,150), tocolor(255,255,255,255))
 

--animations

dgsSetAlpha(window, 0)
dgsAlphaTo(window, 1, "OutQuad", 1000)

dgsSetAlpha(label1, 0)
dgsAlphaTo(label1, 1, "OutQuad", 1000)

dgsSetAlpha(label2, 0)
dgsAlphaTo(label2, 1, "OutQuad", 1000)

dgsSetAlpha(button1, 0)
dgsAlphaTo(button1, 1, "OutQuad", 1000)

dgsSetAlpha(button2, 0)
dgsAlphaTo(button2, 1, "OutQuad", 1000)

-- button func 1

addEventHandler("onDgsMouseClickDown", button1, function()
    dgsSetVisible(window, false)
    dgsSetVisible(label1, false)
    dgsSetVisible(label2, false)
    dgsSetVisible(button1, false)
    dgsSetVisible(button2, false)
    window2 = dgsCreateImage(sx*0.360, sy*0.3, sx*0.330, sy*0.2,_,false,_, tocolor(0,0,0,140))
	label3 = dgsCreateImage(sx*0.360, sy*0.270, sx*0.330, sy*0.030,_,false,_, tocolor(0,255,255,100))
	label4 = dgsCreateLabel(sx*0.360, sy*0.320, sx*0.330, sy*0.030, "a penzed a bankba :  " .. tostring(bank11).. "$")
	dgsSetProperty(label4,"textSize",{sx*0.002, sy*0.002})
	button3 = dgsCreateButton(sx*0.450, sy*0.360, sx*0.150, sy*0.080, "kivetel",false, _, _, _,_,_, _,_,tocolor(0,255,255,100), tocolor(0,255,255,150), tocolor(0,255,255,255))

	dgsSetAlpha(label4, 0)
	dgsAlphaTo(label4, 1, "OutQuad", 1000)

	addEventHandler("onDgsMouseClickDown", button3, function()
		if bankmoney == 0 then
			    dgsSetVisible(window, true)
    			dgsSetVisible(label1, true)
    			dgsSetVisible(label2, true)
    			dgsSetVisible(button1, true)
    			dgsSetVisible(button2, true)


    			dgsSetVisible(window2, false)
    			dgsSetVisible(label3, false)
    			dgsSetVisible(label4, false)
    			dgsSetVisible(button3, false)
		else
			givePlayerMoney(bank11, localPlayer)

			setElementData(localPlayer, "bank", "-100")
		end

	end
	)

end 
)

 

this is the server side script

createObject(2942, -30.522729873657 , -1.5657294988632 , 2.70)

createColSphere(-30.522729873657 , -1.90 , 3.05, 1)

 

  • Like 1
Link to comment
4 hours ago, Raizel said:

hello, im trying to make a bank system and when i try to withdraw the money it doesnt take away my money in the bank,

 

this is the client side script

loadstring(exports.dgs:dgsImportFunction())()
local windows = window,label1,label2,button1,button2

sx, sy = dgsGetScreenSize()
easing = "OutBack"
--data
setElementData(localPlayer, "bank", "100")
bank11 = getElementData (localPlayer, "bank")

--window 
window = dgsCreateImage(sx*0.360, sy*0.3, sx*0.330, sy*0.2,_,false,_, tocolor(0,0,0,140))


label1 = dgsCreateImage(sx*0.360, sy*0.270, sx*0.330, sy*0.030,_,false,_, tocolor(0,255,255,100))
label2 = dgsCreateLabel(sx*0.450, sy*0.270, sx*0.330, sy*0.030, "Bank !!")
dgsSetProperty(label2,"textSize",{sx*0.004, sy*0.002})

-- buttons
button1 = dgsCreateButton(sx*0.370, sy*0.360, sx*0.150, sy*0.080, "kivetel",false, _, _, _,_,_, _,_,tocolor(0,255,255,100), tocolor(0,255,255,150), tocolor(0,255,255,255))
button2 = dgsCreateButton(sx*0.530, sy*0.360, sx*0.150, sy*0.080, "befektetes",false, _, _, _,_,_, _,_,tocolor(255,255,255,100), tocolor(255,255,255,150), tocolor(255,255,255,255))
 

--animations

dgsSetAlpha(window, 0)
dgsAlphaTo(window, 1, "OutQuad", 1000)

dgsSetAlpha(label1, 0)
dgsAlphaTo(label1, 1, "OutQuad", 1000)

dgsSetAlpha(label2, 0)
dgsAlphaTo(label2, 1, "OutQuad", 1000)

dgsSetAlpha(button1, 0)
dgsAlphaTo(button1, 1, "OutQuad", 1000)

dgsSetAlpha(button2, 0)
dgsAlphaTo(button2, 1, "OutQuad", 1000)

-- button func 1

addEventHandler("onDgsMouseClickDown", button1, function()
    dgsSetVisible(window, false)
    dgsSetVisible(label1, false)
    dgsSetVisible(label2, false)
    dgsSetVisible(button1, false)
    dgsSetVisible(button2, false)
    window2 = dgsCreateImage(sx*0.360, sy*0.3, sx*0.330, sy*0.2,_,false,_, tocolor(0,0,0,140))
	label3 = dgsCreateImage(sx*0.360, sy*0.270, sx*0.330, sy*0.030,_,false,_, tocolor(0,255,255,100))
	label4 = dgsCreateLabel(sx*0.360, sy*0.320, sx*0.330, sy*0.030, "a penzed a bankba :  " .. tostring(bank11).. "$")
	dgsSetProperty(label4,"textSize",{sx*0.002, sy*0.002})
	button3 = dgsCreateButton(sx*0.450, sy*0.360, sx*0.150, sy*0.080, "kivetel",false, _, _, _,_,_, _,_,tocolor(0,255,255,100), tocolor(0,255,255,150), tocolor(0,255,255,255))

	dgsSetAlpha(label4, 0)
	dgsAlphaTo(label4, 1, "OutQuad", 1000)

	addEventHandler("onDgsMouseClickDown", button3, function()
		if bankmoney == 0 then
			    dgsSetVisible(window, true)
    			dgsSetVisible(label1, true)
    			dgsSetVisible(label2, true)
    			dgsSetVisible(button1, true)
    			dgsSetVisible(button2, true)


    			dgsSetVisible(window2, false)
    			dgsSetVisible(label3, false)
    			dgsSetVisible(label4, false)
    			dgsSetVisible(button3, false)
		else
			givePlayerMoney(bank11, localPlayer)

			setElementData(localPlayer, "bank", "-100")
		end

	end
	)

end 
)

 

this is the server side script

createObject(2942, -30.522729873657 , -1.5657294988632 , 2.70)

createColSphere(-30.522729873657 , -1.90 , 3.05, 1)

 

1. Please never use setElementData with things like money or health, armour on client side because i dont think it will sync with the server and the cheaters can inject data so they can change your values.

2. Also givePlayerMoney wont sync with the server so u have to use it server side.

-- server side 
-- well also u can make a new event on server side createBank and trigger  it on a button click or the way u want. i made a command for simple example.
createBank = function(player,commandName)
    if getElementData(player,"bank") == true or  getElementData(player,"bank") >= 0 then
        outputChatBox("[BANK] U have the bank created already",player)
    else
    outputChatBox("[BANK] New bank created!",player)
    setElementData(player,"bank",100)
    end 
end 
addCommandHandler("newBank",createBank,false,false)


addEvent("withdrawMoney",true)
withdraw = function(player,amount)
if player == client then
  if amount ~= nil and amount > 0 then
    local current_data = getElementData(player,"bank")
    if current_data >= tonumber(amount) then
    setElementData(player,"bank",current_data - amount)
    givePlayerMoney(player,tonumber(amount))
    else 
        outputChatBox("[BANK] U dont have enough money for this tranzaction",player)
        end 
    end
  end
end 

addEventHandler("withdrawMoney",getRootElement(),withdraw)


-- client side 
--1 remove givePlayerMoney
--2 remove the line with setElementData
-- now add this line in you function o outside
local money_to_withdraw = 10  -- u can change the value the way u want
-- and add in your funcion this
triggerServerEvent("withdrawMoney",localPlayer,localPlayer,money_to_withdraw)

i hope it helps the code is tested all u have to do is just add my code in your script where i told u to add it.

Also u can use a guiCreateEdit on client side window and type the amount.

https://wiki.multitheftauto.com/wiki/GuiCreateEdit

https://wiki.multitheftauto.com/wiki/DgsCreateEdit

and then get the input with

https://wiki.multitheftauto.com/wiki/GuiGetText

https://wiki.multitheftauto.com/wiki/DgsGetText

Edited by FlorinSzasz
Link to comment
  • 3 weeks later...

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...