Jump to content

[NEED HELP]


justn

Recommended Posts

so, when the player dies, i'd like it to get the weapons he had before he died, and return it back to him when he respawns.

function onQuit () 
    local account = getPlayerAccount(source) 
    if account and not (isGuestAccount (account)) then 
    local x,y,z = getElementPosition (source) 
        setAccountData (account, "myCash", tostring (getPlayerMoney (source))) 
        setAccountData (account, "posX", x) 
        setAccountData (account, "posY", y) 
        setAccountData (account, "posZ", z) 
        setAccountData (account, "theSkin", tostring (getPedSkin (source))) 
        setAccountData (account, "theInt", getElementInterior (source)) 
        setAccountData (account, "theDim", getElementDimension (source)) 
        setAccountData (account, "theWep0", getPedWeapon (source, 0)) 
        setAccountData (account, "theWep1", getPedWeapon (source, 1)) 
        setAccountData (account, "theWep2", getPedWeapon (source, 2)) 
        setAccountData (account, "theWep3", getPedWeapon (source, 3)) 
        setAccountData (account, "theWep4", getPedWeapon (source, 4)) 
        setAccountData (account, "theWep5", getPedWeapon (source, 5)) 
        setAccountData (account, "theWep6", getPedWeapon (source, 6)) 
        setAccountData (account, "theWep7", getPedWeapon (source, 7)) 
        setAccountData (account, "theWep8", getPedWeapon (source, -- s8) -->) 
        setAccountData (account, "theWep9", getPedWeapon (source, 9)) 
        setAccountData (account, "theWep10", getPedWeapon (source, 10)) 
        setAccountData (account, "theWep11", getPedWeapon (source, 11)) 
        setAccountData (account, "theWep12", getPedWeapon (source, 12)) 
        setAccountData (account, "theAmmo0", getPedTotalAmmo (source, 0)) 
        setAccountData (account, "theAmmo1", getPedTotalAmmo (source, 1)) 
        setAccountData (account, "theAmmo2", getPedTotalAmmo (source, 2)) 
        setAccountData (account, "theAmmo3", getPedTotalAmmo (source, 3)) 
        setAccountData (account, "theAmmo4", getPedTotalAmmo (source, 4)) 
        setAccountData (account, "theAmmo5", getPedTotalAmmo (source, 5)) 
        setAccountData (account, "theAmmo6", getPedTotalAmmo (source, 6)) 
        setAccountData (account, "theAmmo7", getPedTotalAmmo (source, 7)) 
        setAccountData (account, "theAmmo8", getPedTotalAmmo (source, -- s8) -->) 
        setAccountData (account, "theAmmo9", getPedTotalAmmo (source, 9)) 
        setAccountData (account, "theAmmo10", getPedTotalAmmo (source, 10)) 
        setAccountData (account, "theAmmo11", getPedTotalAmmo (source, 11)) 
        setAccountData (account, "theAmmo12", getPedTotalAmmo (source, 12)) 
        local team = getPlayerTeam(source) 
    if (team) and not isGuestAccount(account) then 
        setAccountData(account, "team", getTeamName(team)) 
        
    end 
end 
end 
addEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
  
function assigntheteam (old, acc) 
    local acc = acc or getPlayerAccount(source) 
    local firstTime = getAccountData(acc, 'firstTime') 
    if not firstTime then 
        setPlayerTeam(source, Unemployed) 
        spawnPlayer(source, 1643.40002, -2249.10009, 13.300, 178.0004, 0, 0, 0, Unemployed) 
        fadeCamera(source, true) 
        setPlayerMoney ( source, 2000 ) 
        setCameraTarget(source, source) 
        setAccountData(acc, 'firstTime', 'true') 
    else 
        local playerMoney = getAccountData (acc, "myCash") 
        local playerSkin = getAccountData (acc, "theSkin") 
        local playerInt = getAccountData (acc, "theInt") 
        local playerDim = getAccountData (acc, "theDim") 
        local playerX = getAccountData (acc, "posX") 
        local playerY = getAccountData (acc, "posY") 
        local playerZ = getAccountData (acc, "posZ") 
        local playerWeaponID0 = getAccountData (acc, "theWep0") 
      local playerWeaponID1 = getAccountData (acc, "theWep1") 
      local playerWeaponID2 = getAccountData (acc, "theWep2") 
      local playerWeaponID3 = getAccountData (acc, "theWep3") 
      local playerWeaponID4 = getAccountData (acc, "theWep4") 
      local playerWeaponID5 = getAccountData (acc, "theWep5") 
      local playerWeaponID6 = getAccountData (acc, "theWep6") 
      local playerWeaponID7 = getAccountData (acc, "theWep7") 
      local playerWeaponID8 = getAccountData (acc, "theWep8") 
      local playerWeaponID9 = getAccountData (acc, "theWep9") 
      local playerWeaponID10 = getAccountData (acc, "theWep10") 
      local playerWeaponID11 = getAccountData (acc, "theWep11") 
      local playerWeaponID12 = getAccountData (acc, "theWep12") 
      local playerWeaponAmmo0 = getAccountData (acc, "theAmmo0") 
      local playerWeaponAmmo1 = getAccountData (acc, "theAmmo1") 
      local playerWeaponAmmo2 = getAccountData (acc, "theAmmo2") 
      local playerWeaponAmmo3 = getAccountData (acc, "theAmmo3") 
      local playerWeaponAmmo4 = getAccountData (acc, "theAmmo4") 
      local playerWeaponAmmo5 = getAccountData (acc, "theAmmo5") 
      local playerWeaponAmmo6 = getAccountData (acc, "theAmmo6") 
      local playerWeaponAmmo7 = getAccountData (acc, "theAmmo7") 
      local playerWeaponAmmo8 = getAccountData (acc, "theAmmo8") 
      local playerWeaponAmmo9 = getAccountData (acc, "theAmmo9") 
      local playerWeaponAmmo10 = getAccountData (acc, "theAmmo10") 
      local playerWeaponAmmo11 = getAccountData (acc, "theAmmo11") 
      local playerWeaponAmmo12 = getAccountData (acc, "theAmmo12") 
        setPlayerMoney (source, tonumber(playerMoney)) 
        spawnPlayer (source, playerX, playerY, playerZ +1, 0, playerSkin, playerInt, playerDim) 
        giveWeapon(source, playerWeaponID0, playerWeaponAmmo0, true) 
      giveWeapon(source, playerWeaponID1, playerWeaponAmmo1, false) 
      giveWeapon(source, playerWeaponID2, playerWeaponAmmo2, false) 
      giveWeapon(source, playerWeaponID3, playerWeaponAmmo3, false) 
      giveWeapon(source, playerWeaponID4, playerWeaponAmmo4, false) 
      giveWeapon(source, playerWeaponID5, playerWeaponAmmo5, false) 
      giveWeapon(source, playerWeaponID6, playerWeaponAmmo6, false) 
      giveWeapon(source, playerWeaponID7, playerWeaponAmmo7, false) 
      giveWeapon(source, playerWeaponID8, playerWeaponAmmo8, false) 
      giveWeapon(source, playerWeaponID9, playerWeaponAmmo9, false) 
      giveWeapon(source, playerWeaponID10, playerWeaponAmmo10, false) 
      giveWeapon(source, playerWeaponID11, playerWeaponAmmo11, false) 
      giveWeapon(source, playerWeaponID12, playerWeaponAmmo12, false) 
        -- 
        -- FOR TEAM 
        local team = getAccountData (acc, "team") 
        if (team) and getTeamFromName(team) then 
        setPlayerTeam(source, getTeamFromName(team)) 
        -- 
        fadeCamera(source, true) 
        setCameraTarget(source, source) 
    end 
 end 
end 
addEvent ( "IfNewPlayerJoin", true ) 
addEventHandler ( "IfNewPlayerJoin", getRootElement(), assigntheteam ) 
addEventHandler ("onPlayerLogin", getRootElement(), assigntheteam) 
  
function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) 
  if not( isGuestAccount (getPlayerAccount(source)) ) then 
    local theWeapon = getPedWeapon (source) 
    local weaponAmmo = getPedTotalAmmo (source) 
    fadeCamera (source, false) 
    setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, getPedSkin (source), 0, 0, getPlayerTeam(source)) 
    setTimer (setCameraTarget, 1250, 1, source, source) 
    setTimer (fadeCamera, 2000, 1, source, true) 
  end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), onWasted) 

Edited by Guest
Link to comment
What's the error?

It doesn't have an error, i need help getting all the player's weapons he had before he died, and giving it back to him when he spawns again.

function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) 
  if not( isGuestAccount (getPlayerAccount(source)) ) then 
    local theWeapon = getPedWeapon (source) 
    local weaponAmmo = getPedTotalAmmo (source) 
    fadeCamera (source, false) 
    setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, getPedSkin (source), 0, 0, getPlayerTeam(source)) 
    setTimer (setCameraTarget, 1250, 1, source, source) 
    setTimer (fadeCamera, 2000, 1, source, true) 
  end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), onWasted) 

Link to comment

You can use this script I made long ago.

local playerWeapons = { } 
  
addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        if ( not playerWeapons [ source ] ) then 
            playerWeapons [ source ] = { } 
        end 
  
        for slot = 0, 12 do 
            local weapon = getPedWeapon ( source, slot ) 
            if ( weapon > 0 ) then 
                local ammo = getPedTotalAmmo ( source, slot ) 
                if ( ammo > 0 ) then 
                    playerWeapons [ source ] [ weapon ] = ammo 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerSpawn", root, 
    function ( ) 
        if ( playerWeapons [ source ] ) then 
            for weapon, ammo in pairs ( playerWeapons [ source ] ) do 
                giveWeapon ( source, tonumber ( weapon ), tonumber ( ammo ) ) 
            end 
        end 
  
        playerWeapons [ source ] = nil 
    end 
) 

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