Jump to content

Saving stats


Recommended Posts

Im trying to make gun license script.. but when i restart resource.. player must buy it again.. i want to save it.. everything works fine but doesn't save after restarting resource or server

Client:

GunLicense= { 
    button = {}, 
    window = {} 
} 
  
  
addEvent("CallGuiLicense",true) 
function guilicense() 
  
showCursor(true) 
local screenW, screenH = guiGetScreenSize()  
       GUIEditor.window[license] = guiCreateWindow(208, 311, 164, 171, "", false) 
        guiWindowSetSizable(GUIEditor.window[license], false) 
  
        GUIEditor.button[1] = guiCreateButton(30, 63, 97, 47, "Buy Gun License", false, GUIEditor.window[license]) 
        addEventHandler ( "onClientGUIClick", GUIEditor.button[1], license, false)       
    end 
addEventHandler ("CallGuiLicense",getRootElement(),guilicense)   
  
  
function license () 
triggerServerEvent("license", getLocalPlayer()) 
showCursor(false) 
guiSetVisible( GUIEditor.window[license] , false) 
end 
  

Server:

  
local gunlicensemarker = createMarker(-2586.7861328125,162.4683380127,-6.8921875953674,"cylinder",1.5,255,0,0,100) 
  
function gunlicense() 
     local money = getPlayerMoney(source) 
     if license_data.have_gunlicense == 1 then 
     outputChatBox("You already have Gun license",source,255,0,0,true) 
     else 
     local money = getPlayerMoney(source) 
     if (money > 4999) then 
     takePlayerMoney(source,5000) 
     
     license_data.have_gunlicense = 1 
     else 
     outputChatBox("You dont have enough money",source,255,0,0,true) 
     end 
     end 
     end 
     addEvent("license",true) 
     addEventHandler("license",getRootElement(),gunlicense) 
     
    function licenseGUI (player) 
  
     if getElementType( player ) == "player" and not isPedInVehicle(player) then 
         triggerClientEvent(player,"CallGuiLicense",player) 
          
         end 
         end 
         addEventHandler("onMarkerHit",gunlicensemarker,licenseGUI) 

Link to comment

Use setAccountData().

-- Client side

addEventHandler("onClientResourceStart",resourceRoot, 
function() 
    local screenW, screenH = guiGetScreenSize()  
    LicenseWindow = guiCreateWindow(208, 311, 164, 171, "", false) 
        guiWindowSetSizable(LicenseWindow, false) 
    guiSetVisible(LicenseWindow,false) 
       BuyLicense = guiCreateButton(30, 63, 97, 47, "Buy Gun License", false, LicenseWindow) 
       addEventHandler ( "onClientGUIClick", BuyLicense, license, false)   
end  
) 
  
function guilicense() 
guiSetVisible(LicenseWindow, true)  
showCursor(true) 
end 
addEvent("CallGuiLicense",true) 
addEventHandler ("CallGuiLicense",getRootElement(),guilicense)  
  
  
function license () 
triggerServerEvent("license", getLocalPlayer()) 
guiSetVisible(LicenseWindow, false) 
showCursor(false) 
end 

-- Server side

local gunlicensemarker = createMarker(-2586.7861328125,162.4683380127,-6.8921875953674,"cylinder",1.5,255,0,0,100) 
  
function licenseGUI (player,matchDim) 
    if matchDim and isElement(player) and getElementType( player ) == "player" and not isPedInVehicle(player) then 
        triggerClientEvent(player,"CallGuiLicense",player) 
    end 
end 
addEventHandler("onMarkerHit",gunlicensemarker,licenseGUI) 
  
function gunlicense() 
    local money = getPlayerMoney(source) 
    local account = getPlayerAccount(source) 
        if not isGuestAccount(account) then  
        local lic = getAccountData(account,"Gun.license") or 0 
        if tonumber(lic) == 1 then 
            outputChatBox("You already have Gun license",source,255,0,0,true) 
            return  
        end  
    if (money > 5000) then 
        takePlayerMoney(source,5000) 
        setAccountData(account,"Gun.license",1) 
     else 
        outputChatBox("You dont have enough money",source,255,0,0,true) 
        end 
    end 
end 
addEvent("license",true) 
addEventHandler("license",getRootElement(),gunlicense) 

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