Fmd01 Posted March 31, 2019 Share Posted March 31, 2019 (edited) So, the script works perfect when the server is running 24/7, if i buy something in the shop it takes off the money from the account. But when i restart the server the money will go back to where it was before i bought an item. Example:I set 20000 money,if i buy a tec-9 it will take off 400, after that i restart the server and the money will be 20000 again. client.lua local items = { --items,cena(K.B.K Points) porsion1List = { {"Pistol", 50}, {"Silenced Pistol",150}, {"Desert Eagle",150}, {"Uzi",300}, {"TEC-9",400}, {"MP5",300}, {"AK-47",450}, {"M4",300}, {"Shotgun",400}, {"Sawn-Off Shotgun",400}, {"SPAZ-12 Combat Shotgun",400}, {"Country Rifle",400}, {"Sniper Rifle",400}, {"Grenade",400}, {"Katana",400}, }, porsion2List = { {"Pistol Ammo",50}, {"Smg Ammo",100}, {"Assault Ammo",125}, {"Shotgun Ammo",100}, {"Sniper Ammo",50}, }, porsion3List = { {"Bandage",75}, {"Painkiller",125}, {"Morphine",50}, {"Medic Kit",100}, {"Blood Bag",100}, } } SHOP = { button = {}, window = {}, label = {}, tabpanel = {}, tab = {}, panel = {} } addEventHandler("onClientResourceStart", resourceRoot, function() local screenWidth, screenHeight = guiGetScreenSize() local windowWidth, windowHeight = 620, 520 local windowX, windowY = (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2) - (windowHeight / 2) SHOP.window[1] = guiCreateWindow(windowX, windowY, windowWidth, windowHeight, "Nemzeti Dohánybolt", false) guiWindowSetMovable(SHOP.window[1], false) guiWindowSetSizable(SHOP.window[1], false) guiSetProperty(SHOP.window[1], "CaptionColour", "FF075205") SHOP.label[1] = guiCreateLabel(0.02, 0.69, 0.97, 0.08, "Válaszd ki azt a tárgyat amit megszeretnél venni! \nA fizetőeszköz DP!", true, SHOP.window[1]) guiSetFont(SHOP.label[1], "default-bold-small") guiLabelSetHorizontalAlign(SHOP.label[1], "center", true) guiLabelSetVerticalAlign(SHOP.label[1], "center") SHOP.button[1] = guiCreateButton(0.35, 0.79, 0.30, 0.12, "Vásárlás", true, SHOP.window[1]) guiSetFont(SHOP.button[1], "default-bold-small") SHOP.tabpanel[1] = guiCreateTabPanel(16, 33, 587, 240, false, SHOP.window[1]) SHOP.tab[1] = guiCreateTab("Fegyverek", SHOP.tabpanel[1]) SHOP.panel[1] = guiCreateGridList(0.01, 0.03, 0.98, 0.92, true, SHOP.tab[1]) guiGridListAddColumn(SHOP.panel[1], "Tárgy", 0.5) guiGridListAddColumn(SHOP.panel[1], "Ár", 0.5) for i,v in pairs ( items.porsion1List ) do local row = guiGridListAddRow ( SHOP.panel[1] ) guiGridListSetItemText ( SHOP.panel[1], row, 1, v[1], false, false ) guiGridListSetItemText ( SHOP.panel[1], row, 2, v[2].."", false, false ) end SHOP.tab[2] = guiCreateTab("Tárak", SHOP.tabpanel[1]) SHOP.panel[2] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[2]) guiGridListAddColumn(SHOP.panel[2], "Tárgy", 0.5) guiGridListAddColumn(SHOP.panel[2], "Ár", 0.5) for i,v in pairs ( items.porsion2List ) do local row = guiGridListAddRow ( SHOP.panel[2] ) guiGridListSetItemText ( SHOP.panel[2], row, 1, v[1], false, false ) guiGridListSetItemText ( SHOP.panel[2], row, 2, v[2].."", false, false ) end SHOP.tab[3] = guiCreateTab("Gyógyító tárgyak", SHOP.tabpanel[1]) SHOP.panel[3] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[3]) guiGridListAddColumn(SHOP.panel[3], "Tárgy", 0.5) guiGridListAddColumn(SHOP.panel[3], "Ár", 0.5) for i,v in pairs ( items.porsion3List ) do local row = guiGridListAddRow ( SHOP.panel[3] ) guiGridListSetItemText ( SHOP.panel[3], row, 1, v[1], false, false ) guiGridListSetItemText ( SHOP.panel[3], row, 2, v[2].."", false, false ) end guiSetVisible(SHOP.window[1],false) addEventHandler ( "onClientGUIClick", SHOP.panel[1], click ) addEventHandler ( "onClientGUIClick", SHOP.panel[2], click ) addEventHandler ( "onClientGUIClick", SHOP.panel[3], click ) addEventHandler ( "onClientGUIClick", SHOP.button[1], buttonClick ) end ) bindKey ( "f4", "down", function ( ) if getElementData(localPlayer, "logedin") then -- if getElementData (getLocalPlayer(),"playerlevel") >= 3 then local state = ( not guiGetVisible (SHOP.window[1]) ) if not getElementData(localPlayer,"shop.viewing") then setElementData(localPlayer,"shop.viewing",1) end guiSetVisible ( SHOP.window[1], state ) showCursor ( state ) if guiGetVisible(SHOP.window[1]) == false then removeEventHandler ( "onClientGUIClick", root, onSwitch ) else addEventHandler ( "onClientGUIClick", root, onSwitch ) end -- else -- outputChatBox (" 3!") -- end end end ) function buttonClick(button,state) if getElementData(localPlayer, "logedin") then if button == "left" and state == "up" then if getElementData(localPlayer,"shop.viewing") then o = getElementData(localPlayer,"shop.viewing") local nRow, nColumn = guiGridListGetSelectedItem( SHOP.panel[o] ) if nRow ~= -1 and nColumn ~= - 1 then local selectedItem = guiGridListGetItemText ( SHOP.panel[o], guiGridListGetSelectedItem ( SHOP.panel[o] ), 1 ) local price = guiGridListGetItemText ( SHOP.panel[o], guiGridListGetSelectedItem ( SHOP.panel[o] ), 2 ) local money = getPlayerMoney(thePlayer) if (money) >= tonumber(price) then guiLabelSetColor( SHOP.label[1],255,255,255) -- guiSetText( SHOP.label[1],"pietiek nauda") setPlayerMoney(money -tonumber(price)) if selectedItem == "Pistol Ammo" then setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+17) elseif selectedItem == "Smg Ammo" then setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+50) elseif selectedItem == "Assault Ammo" then setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30) elseif selectedItem == "Shotgun Ammo" then setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10) elseif selectedItem == "Sniper Ammo" then setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10) else setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1) end guiLabelSetColor( SHOP.label[1],10,255,10) guiSetText( SHOP.label[1],"Sikeresen megvásároltad a "..selectedItem.."tárgyat, maradt még "..(money -tonumber(price)).." DP-d.") else outputChatBox("Nincs elég pénzed!",255,0,0) end end else guiLabelSetColor( SHOP.label[1],255,10,10) guiSetText( SHOP.label[1],"Gyűjts még "..(price -tonumber(money)).." DP-t") end else guiSetText( SHOP.label[1],"Válassz ki valamit először") guiLabelSetColor( SHOP.label[1],255,255,255) end end end function onSwitch() if source == SHOP.panel[1] then setElementData(localPlayer,"shop.viewing",1) elseif source == SHOP.panel[2] then setElementData(localPlayer,"shop.viewing",2) elseif source == SHOP.panel[3] then setElementData(localPlayer,"shop.viewing",3) end end function click () if source == SHOP.panel[1] or source == SHOP.panel[2] or source == SHOP.panel[3] then local selectedItem = guiGridListGetItemText ( source, guiGridListGetSelectedItem ( source ), 1 ) local price = guiGridListGetItemText ( source, guiGridListGetSelectedItem ( source ), 2 ) guiSetText( SHOP.label[1],"Hogy megvásárold a/az "..selectedItem.." tárgyat "..price.." DP-ért, nyomd le a vásárlás gombot!") guiLabelSetColor( SHOP.label[1],255,255,255) end end server.lua addEventHandler("onPlayerQuit",root, function() local acc = getPlayerAccount(source) if (acc) and not isGuestAccount(acc) then local x,y,z = getElementPosition(source) local money = getPlayerMoney(source) setAccountData(acc,"PosX",x) setAccountData(acc,"PosY",y) setAccountData(acc,"PosZ",z) setAccountData(acc,"Money",money) end end) addEventHandler("onPlayerLogin",root, function(_,acc) local x,y,z = getAccountData(acc,"PosX"),getAccountData(acc,"PosY"),getAccountData(acc,"PosZ") local Money = getAccountData(acc,"Money") or 0 setPlayerMoney(source,Money) spawnPlayer(source,x,y,z) fadeCamera(source, true) setCameraTarget(source) end) Edited March 31, 2019 by Fmd01 Link to comment
Sendy Posted March 31, 2019 Share Posted March 31, 2019 server-side -> setPlayerMoney() use triggerServerEvent() when you buy weapon Link to comment
Fmd01 Posted March 31, 2019 Author Share Posted March 31, 2019 Could you make an example? Link to comment
Fmd01 Posted March 31, 2019 Author Share Posted March 31, 2019 Okay, fixed it thanks. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now