Jump to content

My shop plugin doesn't save money


shoBy

Recommended Posts

My shop plugin doesn't save money when I logout and login again. Please help!!

Here is all my script:

kill_zombies.lua

  
addEventHandler( "onZombieGetsKilled", getRootElement(), 
    function( killer ) 
        givePlayerMoney( killer, 15 ); 
    end 
) 
  

kill_players.lua

function createMoney(player) 
   local x, y, z = getElementPosition(player); 
   local x1, y1, x2, y2; 
   x1 = (x-2)+(math.random()*4); 
   y1 = (y-2)+(math.random()*4); 
   x2 = (x-2)+(math.random()*4); 
   y2 = (y-2)+(math.random()*4); 
   local moneyAmmount = getPlayerMoney(player); 
   -- it is not fair too get all the player money. 
   moneyAmmount = math.floor(moneyAmmount/1); 
  
  
   -- Create the pickups 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
end 
  
function moneyPickupHit(player) 
   local money = getElementData(source, "ammount"); 
   if money then 
   givePlayerMoney(player, 30); 
      destroyElement(source); 
   end 
end 
  
  
function playerJustGotDied(ammo, attacker, weapon, bodypart) 
   createMoney(source); 
end 
  
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
addEventHandler("kilLDayZPlayer", getRootElement(), playerJustGotDied); 
  

Money_chat.lua

addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
addEventHandler("onClientRender", root, 
    function() 
        local cash = getPlayerMoney( getLocalPlayer() ) 
        dxDrawText("Money:",   625,   104,  688, 128, tocolor(30, 247, 7, 255), 0.50, "bankgothic", "left", "top", false, false, false, false, false) 
        dxDrawText(""..cash,  704,104,796,123, tocolor(255, 255, 255, 255), 0.50, "bankgothic", "left", "top", false, false, false, false, false) 
    end 
) 

Server.lua

LuaQ     @server.lua           h    
  J     Á@  b@ Š  Á   A  ¢@ Ê  
A  A  "A J Š Á  B  ¢A Ê  AB  âA
A  B  "B J Š Á  C  ¢B Ê  AC  âB
A  C  "C J€ Š€ Ê€
A  D  "D âC€ ¢C€ bC€ bB bA Š Á  B  ¢A Ê  AB  âA â@
A  A  "A "@   E€  À  Å Ü€€ $  \@ E€  @ Š܀€ $A  \@ d€  G€ E€  À Š܀€ \@ dÀ  G€ E€  À Š܀€ \@ d G€ E€  À Š܀€ \@ €        ð?       @   addEventHandler   onPlayerLogin   getRootElement
   onPlayerQuit   onJoin
   onPlayerJoin        
          E@  € ------------------------------------------------------------------------------------------------------------------------------------------------              
--||||||||||||||||||||||||||||||||||||||||||||
--|||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|||
--|||-                                    +|||
--|||+  @: Criado por iSantista / Scout   -|||
--|||-  @: 12/09/2013                     +|||
--|||+  @: Cliente.lua                    -|||
--|||-                                    +|||
--|||+                                    -|||
--|||-                                    +|||
--|||+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|||
--||||||||||||||||||||||||||||||||||||||||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Script Inico                                                                                                                                                   -
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
 
local tabPanel = {}
local buttons = {}
local labels = {}
 
local player = localPlayer
 
function shopInterface()
    shop_window = guiCreateWindow(142,35, 544, 501, "GP Shop", false)
    guiSetVisible(shop_window, false)
    guiSetAlpha(shop_window, 0.73)
    guiWindowSetSizable(shop_window, false)
 
    exports.guicols:guiSetColor (shop_window, "red");
    tabPanel.myTabPanel = guiCreateTabPanel(14, 120, 516, 318, false, shop_window)-- Create the Tab Panel
 
    tabPanel.TabArmas = guiCreateTab("Weapon", tabPanel.myTabPanel)
 
    buttons.CZ550 = guiCreateButton(43, 24, 165, 85, "CZ 550 / 1000$\n 5 Mag", false , tabPanel.TabArmas) -- M4 skill
    guiSetFont(buttons.CZ550, "default-bold-small")
 
    buttons.DesertEagle  = guiCreateButton(43, 204, 165, 69, "Desert Eagle / 500$ \n 5 Mag", false, tabPanel.TabArmas) -- AK47 skill
    guiSetFont(buttons.DesertEagle, "default-bold-small")
 
    buttons.Granada = guiCreateButton(43, 113, 165, 82, "Granada / 500$ \n 1 Szt", false, tabPanel.TabArmas) -- Sawn-off Shotgun skill
    guiSetFont(buttons.Granada , "default-bold-small")
 
    buttons.M4 = guiCreateButton(291, 24, 175, 85, "M4  / 800 $\n 3 Mag", false, tabPanel.TabArmas) -- Shotgun skill
    guiSetFont(buttons.M4 , "default-bold-small")
 
    buttons.AK47 = guiCreateButton(291, 204, 175, 69, "AK-47 / 700 $ \n 4 Mag", false, tabPanel.TabArmas) -- SPAZ-12 skill
    guiSetFont(buttons.AK47 , "default-bold-small")
 
    buttons.M9SD = guiCreateButton(291, 113, 175, 82, "M9 SD / 300 $ \n 5 Mag", false, tabPanel.TabArmas) -- Silenced Pistol skill
    guiSetFont(buttons.M9SD , "default-bold-small")
    ----------- Comidas  ----------------
 
 
    tabPanel.TabComidas = guiCreateTab("Food", tabPanel.myTabPanel)
 
    buttons.Pizza = guiCreateButton(24, 21, 184, 84, "Pizza / 30$ \n 5 Szt", false, tabPanel.TabComidas) -- M4 skill
    guiSetFont(buttons.Pizza , "default-bold-small")
 
    buttons.Milk  = guiCreateButton(291, 21, 188, 84, "Milk / 30$ \n 5 Szt", false, tabPanel.TabComidas) -- AK47 skill
    guiSetFont(buttons.Milk , "default-bold-small")
 
    buttons.Cooked = guiCreateButton(24, 120, 184, 75, "Cooked Meat / 60$ \n 5 Szt", false,tabPanel.TabComidas) -- Sawn-off Shotgun skill
    guiSetFont(buttons.Cooked , "default-bold-small")
 
    buttons.Soda = guiCreateButton(291, 123, 188, 75, "Soda Bottle / 50 $ \n 5 Szt", false, tabPanel.TabComidas) -- Shotgun skill
    guiSetFont(buttons.Soda , "default-bold-small")
 
    buttons.BeansCan = guiCreateButton(24, 204, 184, 69, "Beans Can / 40 $ \n 4 Szt", false, tabPanel.TabComidas) -- SPAZ-12 skill
    guiSetFont(buttons.BeansCan , "default-bold-small")
 
    buttons.WaterBottle  = guiCreateButton(291, 208, 188, 65, "Water Bottle / 50 $ \n 5 Szt", false, tabPanel.TabComidas) -- Silenced Pistol skill
    guiSetFont(buttons.WaterBottle , "default-bold-small")
 
    ------------  Outros ----------------
 
    tabPanel.TabOutros = guiCreateTab("Rest", tabPanel.myTabPanel)
 
 
    buttons.Alice  = guiCreateButton(17, 198, 182, 76, "Alice Backpack/ 300$ \n ", false, tabPanel.TabOutros) -- AK47 skill
    guiSetFont(buttons.Alice , "default-bold-small")
 
    buttons.Road = guiCreateButton(17, 115, 182, 73, "RoadFlare / 10$ \n 1 Szt", false, tabPanel.TabOutros) -- Sawn-off Shotgun skill
    guiSetFont(buttons.Road , "default-bold-small")
 
    buttons.Wire = guiCreateButton(309, 26, 175, 80, "WireFence / 50$ \n 1 Szt", false, tabPanel.TabOutros) -- Shotgun skill
    guiSetFont(buttons.Wire , "default-bold-small")
 
    buttons.Czech = guiCreateButton(309, 198, 175, 76, "Czech Backpack/ 600$ \n ", false, tabPanel.TabOutros) -- SPAZ-12 skill
    guiSetFont(buttons.Czech , "default-bold-small")
 
    buttons.Full = guiCreateButton(309, 116, 175, 73, "Full Patrol Canister/ 300$ \n 2 Szt", false, tabPanel.TabOutros) -- Silenced Pistol skill
    guiSetFont(buttons.Full , "default-bold-small")
 
   ------------- Municao --------------------------------------------------------------------------------------------------------------------------
 
    tabPanel.TabMunicao = guiCreateTab("Ammo",  tabPanel.myTabPanel)
 
    buttons.CZ550Mag = guiCreateButton(14, 28, 112, 60, "CZ 550 Mag / 500$ \n 5 Mag", false, tabPanel.TabMunicao) -- M4 skill
    guiSetFont(buttons.CZ550Mag , "default-bold-small")
 
    buttons.MP5Mag  = guiCreateButton(146, 179, 112, 60, "MP5A5 Mag / 100$ \n 3 Mag", false, tabPanel.TabMunicao) -- AK47 skill
    guiSetFont(buttons.MP5Mag , "default-bold-small")
 
    buttons.PDWMag = guiCreateButton(146, 103, 112, 60, "PDW Mag / 200$ \n 2 Mag", false, tabPanel.TabMunicao) -- Sawn-off Shotgun skill
    guiSetFont(buttons.PDWMag , "default-bold-small")
 
    buttons.WinchesterMAG = guiCreateButton(14, 179, 112, 60, "1866 Slug / 200$ \n 3 Mag", false, tabPanel.TabMunicao) -- Shotgun skill
    guiSetFont(buttons.WinchesterMAG , "default-bold-small")
 
    buttons.AKMag = guiCreateButton(14, 103, 112, 60, "AK Mag / 400$ \n 3 Mag", false, tabPanel.TabMunicao) -- SPAZ-12 skill
    guiSetFont(buttons.AKMag , "default-bold-small")
 
    buttons.M4Mag = guiCreateButton(146, 28, 112, 60, "M4 Mag / 450$ \n 4 Mag", false, tabPanel.TabMunicao) -- Silenced Pistol skill
    guiSetFont(buttons.M4Mag , "default-bold-small")
   ------------- Skins --------------------------------------------------------------------------------------------------------------------------
    tabPanel.TabSkins = guiCreateTab("Skins", tabPanel.myTabPanel)
 
    buttons.Civilian = guiCreateButton(302, 30, 179, 98, "Civilian Skin  $250 \n ", false, tabPanel.TabSkins)
    guiSetFont(buttons.Civilian, "default-bold-small")
 
    buttons.Camouflage = guiCreateButton(23, 147, 179, 98, "Camouflage Clothing  $200 \n ", false, tabPanel.TabSkins)
    guiSetFont(buttons.Camouflage, "default-bold-small")
 
    buttons.Survivor = guiCreateButton(302, 147, 179, 98, "Survivor Clothing 50$ \n ", false, tabPanel.TabSkins)
    guiSetFont(buttons.Survivor, "default-bold-small")
    ------------- Parte de Carros --------------------------------------------------------------------------------------------------------------------------
    tabPanel.TabParteDeCarros = guiCreateTab("Auto Parts", tabPanel.myTabPanel)
 
    buttons.Tires = guiCreateButton(23, 23, 183, 97, "1 Tire / 250 $ \n ", false, tabPanel.TabParteDeCarros)
    guiSetFont( buttons.Tires, "default-bold-small")
 
    buttons.TankParts = guiCreateButton(291, 23, 183, 97, "5 Tank Parts / 200$ \n ", false, tabPanel.TabParteDeCarros)
    guiSetFont(buttons.TankParts, "default-bold-small")
 
    buttons.Engine = guiCreateButton(62, 143, 385, 111, "1 Engine 1000$ \n ", false,tabPanel.TabParteDeCarros)
    guiSetFont(buttons.Engine , "default-bold-small")
    ------------- Medicos --------------------------------------------------------------------------------------------------------------------------
    tabPanel.TabMedico = guiCreateTab("Medics", tabPanel.myTabPanel)
 
    buttons.Medickit = guiCreateButton(33, 28, 195, 103, "2 Medic kit / 1000 $", false, tabPanel.TabMedico)
    guiSetFont(buttons.Medickit, "default-bold-small")
 
    buttons.Bandage = guiCreateButton(33, 141, 195, 122, "4 Bandage / 250 $", false, tabPanel.TabMedico)
    guiSetFont(buttons.Bandage, "default-bold-small")
 
    buttons.PainKiller = guiCreateButton(270, 28, 193, 107, "4 Painkiller / 100 $", false, tabPanel.TabMedico)
    guiSetFont(buttons.PainKiller, "default-bold-small")
 
    buttons.Morphine = guiCreateButton(270, 141, 193, 122, "4 Morphine / 500 $", false, tabPanel.TabMedico)
    guiSetFont(buttons.Morphine, "default-bold-small")
    ------------- Criador --------------------------------------------------------------------------------------------------------------------------
   
    Painel = guiCreateLabel(96, 41, 386, 68, "Global DayZ Shop", false, shop_window)
    guiSetFont(Painel, "sa-header")
   
    ----- Sair
    buttons.Sair = guiCreateButton(15, 443, 515, 48, "Zamknij", false, shop_window)
    guiSetFont(buttons.Sair , "default-bold-small")
 
    ----------- Button Color ----------------------------------------------------------------
    for _, button in pairs(buttons) do guiSetProperty(button, "HoverTextColour", "FFFF0000") end
 
end
addEventHandler("onClientResourceStart", resourceRoot, shopInterface)
 
 
----------- Buy Armas ---------------------------------------------------------------
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.CZ550) then
                    triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_CZ550")
                end
 
           end
)
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.DesertEagle) then
                    triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_DesertEagle")
                end
 
           end
)
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.Granada) then
                    triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_Granada")
                end
 
           end
)
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.M4) then
                    triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_M4")
                end
 
           end
)
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.AK47) then
                    triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_AK47")
                end
 
           end
)
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.M9SD) then
                    triggerServerEvent("onClientBuyWeapon", localPlayer, "weapon_M9SD")
                end
 
           end
)
 
----------- Comidas -----------------------------------------------------
 
 
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.Pizza) then
                    triggerServerEvent("onClientBuyComida", localPlayer, "Comida_Pizza")
                end
 
           end
)
 
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()),
        function ( )
           if (source == buttons.Milk) then
                    triggerServerEvent("onClientBuyComida", localPlayer, "Comida_Milk")
                end
 
           end
)
 
Link to comment

Can this work? if I put it in server near a meta.xml like

savemoney.lua

function playerQuit() 
    local playerAcc = getPlayerAccount(source) 
    if ( playerAcc  ) then -- You we're checking if (playeraccount == true) then, but your variable name is "playeracc". 
        local playerCash = getPlayerMoney(source) 
        setAccountData(playerAcc, "cash", playerCash) 
        setPlayerMoney(source, 0) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), playerQuit) 
addEventHandler("onPlayerLogout", getRootElement(), playerQuit) 
  
function playerLogin() 
    local playerAcc = getPlayerAccount(source) 
    if (playerAcc) then 
        local playerBank = getAccountData(playerAcc, "cash") 
        if (playerBank) then 
            setPlayerMoney(source, tonumber(playerBank)) 
        else 
            outputChatBox("You are broke.", source, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), playerLogin) 

meta.xml

<meta> 
    <info author="Nobody" version="1.0" type="script" name="savemoney" description="Save money script" /> 
                 <script src="savemoney.lua" type="server" /> 
</meta> 
  

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