Jump to content

Save Skin and Money


Mefisto_PL

Recommended Posts

Posted

I have not working script that save skin and money.. How to fix that?

function joinHandler ( ) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    fadeCamera (source, true) 
     setCameraTarget ( source, source ) 
 end 
 addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
 function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawnWasted, 1800, 1, source, getElementModel(source)) 
    end 
) 
  
function greetPlayer ( ) 
    outputChatBox ( "Witaj na Polskim Serwerze Zabawy stworzonym przez Mefisto_PL !" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getPlayerSkin(source) 
            setAccountData(playerAccount, "money", playerMoney) 
            setAccountData(playerAccount, "skin", playerSkin) 
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local playerMoney = getAccountData(playerAccount, "money") 
            local playerSkin = getAccountData(playerAccount, "skin") 
            if (playerMoney, playerSkin) then 
                  setPlayerMoney(source, playerMoney) 
                  setPlayerSkin(source, playerSkin) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Posted

There is no function called getPlayerSkin, use getElementModel instead.

skin in joinHandler is not defined.

function joinHandler ( ) 
    --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
     setCameraTarget ( source, source ) 
 end 
 addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
 function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawnWasted, 1800, 1, source, getElementModel(source)) 
    end 
) 
  
function greetPlayer ( ) 
    outputChatBox ( "Witaj na Polskim Serwerze Zabawy stworzonym przez Mefisto_PL !" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getElementModel(source) 
            setAccountData(playerAccount, "money", playerMoney) 
            setAccountData(playerAccount, "skin", playerSkin) 
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local playerMoney = getAccountData(playerAccount, "money") 
            local playerSkin = getAccountData(playerAccount, "skin") 
            if (playerMoney, playerSkin) then 
                  setPlayerMoney(source, playerMoney) 
                  setPlayerSkin(source, playerSkin) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Posted
function joinHandler ( ) 
    --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
     setCameraTarget ( source, source ) 
 end 
 addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
 function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawnWasted, 1800, 1, source, getElementModel(source)) 
    end 
) 
  
function greetPlayer ( ) 
    outputChatBox ( "Witaj na Polskim Serwerze Zabawy stworzonym przez Mefisto_PL !" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getElementModel(source) 
            setAccountData(playerAccount, "money", playerMoney) 
            setAccountData(playerAccount, "skin", playerSkin) 
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
            local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
            if (playerMoney, playerSkin) then 
                  setPlayerMoney(source, playerMoney) 
                  setElementModel(source, playerSkin) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Try that.

Spawns with cj because you haven't logged in yet, you must login first.

Posted
function joinHandler ( ) 
    --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
    setCameraTarget ( source, source ) 
 end 
 addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawnWasted, 1800, 1, source, getElementModel(source)) 
    end 
) 
  
function greetPlayer ( ) 
    outputChatBox ( "Witaj na Polskim Serwerze Zabawy stworzonym przez Mefisto_PL !" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = getPlayerMoney(source) 
        local playerSkin = getElementModel(source) 
        setAccountData(playerAccount, "money", playerMoney) 
        setAccountData(playerAccount, "skin", playerSkin) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) then 
        local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
        local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
        if (playerMoney and playerSkin) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Posted
function joinHandler ( ) 
    --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
    setCameraTarget ( source, source ) 
 end 
 addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawnWasted, 1800, 1, source, getElementModel(source)) 
    end 
) 
  
function greetPlayer ( ) 
    outputChatBox ( "Witaj na Polskim Serwerze Zabawy stworzonym przez Mefisto_PL !" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = getPlayerMoney(source) 
        local playerSkin = getElementModel(source) 
        setAccountData(playerAccount, "money", playerMoney) 
        setAccountData(playerAccount, "skin", playerSkin) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
        local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
        if (playerMoney and playerSkin) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

I added isGuestAccount check to onPlayerLogin.

I can't find any difference between Castillo's and mine, I took yours anyway.

Posted

Compare your line 42 (in the post behind mine) with mine.

Yours:

if (playerMoney, playerSkin) then -- You can't use a comma, you must use "and". 

Mine:

if (playerMoney and playerSkin) then 

Posted

Well I did this, still random character on death

function player_Wasted ( ammo, attacker, weapon, bodypart ) 
end 
-- add the player_Wasted function as a handler for onPlayerWasted 
addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted ) 

Posted

That's nothing, a event handler attached to a empty function, what do you think it'll do?

If you want to save the skin on death, try this:

addEventHandler("onPlayerWasted",root, 
function () 
     setElementData(source,"tempSkin",getElementModel(source)) 
end) 
  
addEventHandler("onPlayerSpawn",root, 
function () 
     local skin = tonumber(getElementData(source,"tempSkin")) 
     if (skin) then 
          setElementModel(source, skin) 
     end 
     removeElementData(source,"tempSkin") 
end) 

Posted
That's nothing, a event handler attached to a empty function, what do you think it'll do?

If you want to save the skin on death, try this:

addEventHandler("onPlayerWasted",root, 
function () 
     setElementData(source,"tempSkin",getElementModel(source)) 
end) 
  
addEventHandler("onPlayerSpawn",root, 
function () 
     local skin = tonumber(getElementData(source,"tempSkin")) 
     if (skin) then 
          setElementModel(source, skin) 
     end 
     removeElementData(source,"tempSkin") 
end) 

Hmm thanks for the help, but still random character..

Posted
local spawnpoint 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        spawnpoint = getRandomSpawnPoint() 
        resetMapInfo() 
        for i,player in ipairs(getElementsByType("player")) do 
            spawn(player) 
        end 
    end 
) 
  
    function joinHandler ( ) 
        --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
        spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
        fadeCamera (source, true) 
        setCameraTarget ( source, source ) 
     end 
     addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
      
    function spawnWasted(player, skin) 
        repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
        fadeCamera(player, true) 
        setCameraTarget(player, player) 
    end 
      
    addEventHandler("onPlayerWasted", root, 
        function() 
            setTimer(spawnWasted, 1800, 1, source, getElementModel(source)) 
        end 
    ) 
      
    function greetPlayer ( ) 
        outputChatBox ( "Welcome to Zer0w's server" , source, 0, 159, 255 ) 
    end 
    addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
     
    addEventHandler("onPlayerWasted",root, 
    function () 
         setElementData(source,"tempSkin",getElementModel(source)) 
    end) 
      
    addEventHandler("onPlayerSpawn",root, 
    function () 
         local skin = tonumber(getElementData(source,"tempSkin")) 
         if (skin) then 
              setElementModel(source, skin) 
         end 
         removeElementData(source,"tempSkin") 
    end) 
      
    function onPlayerQuit() 
        local playerAccount = getPlayerAccount(source) 
        if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getElementModel(source) 
            setAccountData(playerAccount, "money", playerMoney) 
            setAccountData(playerAccount, "skin", playerSkin) 
        end 
    end 
    addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
      
    function onPlayerLogin() 
        local playerAccount = getPlayerAccount(source) 
        if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
            local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
            if (playerMoney and playerSkin) then 
                setPlayerMoney(source, playerMoney) 
                setElementModel(source, playerSkin) 
            end 
        end 
    end 
    addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
  
function spawn(player) 
    if not isElement(player) then return end 
    if get("spawnreset") == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint() 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
    repeat until setElementModel(player,math.random(312)) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
end 
  
function getRandomSpawnPoint () 
    local spawnpoints = getElementsByType("spawnpoint") 
    return spawnpoints[math.random(1,#spawnpoints)] 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        spawn(source) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setTimer(spawn, 1800, 1, source) 
    end 
) 

Posted

Well, you are using two respawn systems there.

local spawnpoint 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        spawnpoint = getRandomSpawnPoint() 
        resetMapInfo() 
        for i,player in ipairs(getElementsByType("player")) do 
            spawn(player) 
        end 
    end 
) 
  
function joinHandler ( ) 
    --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
    setCameraTarget ( source, source ) 
end 
addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
--[[ 
function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
function() 
    setTimer(spawnWasted, 1800, 1, source, tonumber(getElementData(source,"tempSkin"))) 
end 
) 
--]] 
  
function greetPlayer ( ) 
    outputChatBox ( "Welcome to Zer0w's server" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = getPlayerMoney(source) 
        local playerSkin = getElementModel(source) 
        setAccountData(playerAccount, "money", playerMoney) 
        setAccountData(playerAccount, "skin", playerSkin) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
        local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
        if (playerMoney and playerSkin) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
  
function spawn(player) 
    if not isElement(player) then return end 
    if get("spawnreset") == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint() 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
    setElementModel(player, tonumber(getElementData(player,"tempSkin"))) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
end 
  
function getRandomSpawnPoint () 
    local spawnpoints = getElementsByType("spawnpoint") 
    return spawnpoints[math.random(1,#spawnpoints)] 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        spawn(source) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        setElementData(source,"tempSkin",getElementModel(source)) 
        setTimer(spawn, 1800, 1, source) 
    end 
) 

I don't know, it should work as I commented out one of them.

Posted (edited)
local spawnpoint 
  
function spawn( player ) 
    local player = player or source 
    if get( getResourceName( getThisResource( ) )..".spawnreset" ) == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint( ) 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint ( player,spawnpoint,false ) 
    setElementModel( player, tonumber( getElementData( player,"tempSkin" ) or 0 ) ) 
    fadeCamera( player, true ) 
    setCameraTarget( player, player ) 
    showChat( player, true )  
end 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        spawnpoint = getRandomSpawnPoint( ) 
        --resetMapInfo() is triggered in mapmanager 
        for i,player in ipairs(getElementsByType("player")) do 
            spawn(player) 
        end 
    end 
) 
  
function joinHandler ( ) 
    --spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, skin, 0) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
    setCameraTarget ( source, source ) 
end 
addEventHandler ( "onPlayerJoin" , root , joinHandler ) 
  
--[[ 
function spawnWasted(player, skin) 
    repeat until spawnPlayer ( player, -2655.02, 625.30, 14.45, 180, skin, 0) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 
  
addEventHandler("onPlayerWasted", root, 
function() 
    setTimer(spawnWasted, 1800, 1, source, tonumber(getElementData(source,"tempSkin"))) 
end 
) 
--]] 
  
function greetPlayer ( ) 
    outputChatBox ( "Welcome to Zer0w's server" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", root, greetPlayer ) 
  
function onPlayerQuit() 
    local playerAccount = getPlayerAccount( source ) 
    if playerAccount and not isGuestAccount( playerAccount ) then 
        local playerMoney = getPlayerMoney( source ) 
        local playerSkin = getElementModel( source ) 
        setAccountData( playerAccount, "money", playerMoney ) 
        setAccountData( playerAccount, "skin", playerSkin ) 
    end 
end 
addEventHandler( "onPlayerQuit", root, onPlayerQuit ) 
  
function onPlayerLogin( ) 
    local playerAccount = getPlayerAccount( source ) 
    if playerAccount and not isGuestAccount( playerAccount ) then 
        local playerMoney = tonumber( getAccountData( playerAccount, "money" ) ) 
        local playerSkin = tonumber( getAccountData( playerAccount, "skin" ) ) 
        if playerMoney and playerSkin then 
            setPlayerMoney( source, playerMoney ) 
            setElementModel( source, playerSkin ) 
        end 
    end 
end 
addEventHandler( "onPlayerLogin", root, onPlayerLogin ) 
  
function getRandomSpawnPoint( ) 
    local spawnpoints = getElementsByType( "spawnpoint" ) 
    return spawnpoints[ math.random( 1,#spawnpoints ) ] 
end 
  
addEventHandler( "onPlayerJoin", root, 
    function() 
        spawn( source ) 
    end 
) 
  
addEventHandler( "onPlayerQuit",root, 
    function ( ) 
        if getPlayerCount( ) == 1 and get( getResourceName( getThisResource( ) )..".spawnreset" ) == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint( ) 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function( ) 
        setElementData( source,"tempSkin",getElementModel( source ) ) 
        setTimer( spawn, 1800, 1, source ) 
    end 
) 

Edited by Guest
Posted

I still thank you guys for the perfectly working script, but now I'm trying to figure out a working weapon save system.

I didn't code this, but a guy called Jason wrote the code :

    weaponSlots = 11 
    ammoSlot = {} 
    gunSlot = {} 
      
    for slot = 1, weaponSlots do 
        if getPedWeapon ( player, slot ) then 
              ammoSlot[slot] = getPedTotalAmmo ( player, slot ) 
              gunSlot[slot] = getPedWeapon ( player, slot ) 
        end 
    end 
    -- If you want save your WEAPON CODE later than you can use ElementData -> global 
    for gun = 1, #gunSlot do 
          if gunSlot[gun] ~= nil then 
              setElementData(player, "weapon#"..gun, getWeaponNameFromID(gunSlot[gun]) 
              setElementData(player, "ammo#"..gun, ammoSlot[gun]) 
         end 
    end 

Somehow I think it's missing a function, I tried lots of functions but none of them were working, I even used the search button.

Help would be appreciated.

Posted
What respawn system are you using?

I used your code, for freeroam so broph.lua

the weapon saving is clientside so I made a meta.xml and a weaponsave.lua containing that code that I posted above

Posted

Ok, then, try this:

local spawnpoint 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        spawnpoint = getRandomSpawnPoint() 
        resetMapInfo() 
        for i,player in ipairs(getElementsByType("player")) do 
            spawn(player) 
        end 
    end 
) 
  
function joinHandler ( ) 
    spawnPlayer (source, -1969.2669677734, 137.71185302734, 30, 0, 0, 0) 
    fadeCamera (source, true) 
    setCameraTarget ( source, source ) 
end 
addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
  
function greetPlayer ( ) 
    outputChatBox ( "Welcome to Zer0w's server" , source, 0, 159, 255 ) 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
function onPlayerQuit() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = getPlayerMoney(source) 
        local playerSkin = getElementModel(source) 
        setAccountData(playerAccount, "money", playerMoney) 
        setAccountData(playerAccount, "skin", playerSkin) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
        local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
        if (playerMoney and playerSkin) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
  
function spawn(player) 
    if not isElement(player) then return end 
    if get("spawnreset") == "onSpawn" then 
        spawnpoint = getRandomSpawnPoint() 
    end 
    exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
    setElementModel(player, tonumber(getElementData(player,"tempSkin"))) 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
    showChat(player, true) 
    local weapons = getElementData(player,"tempWeapons") 
    if (weapons and weapons ~= "") then 
        for weapon, ammo in pairs(fromJSON(weapons)) do 
            if (weapon and ammo) then 
                giveWeapon(player, tonumber(weapon), tonumber(ammo)) 
            end 
        end 
    end 
end 
  
function getRandomSpawnPoint () 
    local spawnpoints = getElementsByType("spawnpoint") 
    return spawnpoints[math.random(1,#spawnpoints)] 
end 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        spawn(source) 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function () 
        if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        weaponSlots = 12 
        local weaponsTable = {} 
        for slot=1, weaponSlots do 
            local weapon = getPedWeapon( source, slot ) 
            local ammo = getPedTotalAmmo( source, slot ) 
            if (weapon > 0 and ammo > 0) then 
                weaponsTable[weapon] = ammo 
            end 
        end 
        setElementData(source,"tempSkin",getElementModel(source)) 
        setElementData(source,"temWeapons",toJSON(weaponsTable)) 
        setTimer(spawn, 1800, 1, source) 
    end 
) 

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