Jump to content
  • 0

Skin Changing on Player Wasted


PhantomNL

Question

Hello guys, just a simple question:

If I die by any reason, I get respawned at Grove Street with another skin and all my weapons are gone, how can I fix so that the skin keeps the same, and I keep my ammo on death?

Also, can I change the name of the 'play' gamemode so the gamemode doesn't show up as 'play' in the server list? (I have a custom map in the game, wich needs the gamemode 'play' to start)

Thanks! :D

Link to comment

11 answers to this question

Recommended Posts

  • 0

Everything you want here requires you to have LUA Knowledge...

In order to give the player back the skin they had before they died, you would need to use:

onPlayerWasted then get the player skin using: getElementModel, and store it in a variable or a table, after the player spawns(onPlayerSpawn), use setElementModel and set the player skin back.

Also, for the ammo and guns, you could use the same events, but you would need to loop through every slot and get the guns ammos.

Link to comment
  • 0
Everything you want here requires you to have LUA Knowledge...

In order to give the player back the skin they had before they died, you would need to use:

onPlayerWasted then get the player skin using: getElementModel, and store it in a variable or a table, after the player spawns(onPlayerSpawn), use setElementModel and set the player skin back.

Also, for the ammo and guns, you could use the same events, but you would need to loop through every slot and get the guns ammos.

I would use a setTimer too, so I give the skin 500 miliseconds later of the spawn.

Link to comment
  • 0

Ok, I'll just make this script for you, but you would need to read and learn over it:

local savedWeps = {} --Stores all the saved weps 
addEventHandler("onPlayerWasted",root, --Triggered when a player dies 
    function() 
        --Loop through all the player weapons 
        local sourceWeps = {} --player weapons table 
        for i=1,12 do 
            local WepNum = getPedWeapon(source,i) --get the weapon from slot 
            local WepAmmo = getPedTotalAmmo(source,i) --get the ammount of ammo from weapon slot 
            if WepAmmo > 0 then --check if the weapon has ammo 
                sourceWeps[i] = {WepNum,WepAmmo} --store the weapon and the ammount of ammo in the player weapons table 
            end 
        end 
        savedWeps[source] = toJSON(sourceWeps) --convert the table into JSON 
    end 
) 
addEventHandler("onPlayerSpawn",root, --Triggered when a player spawns 
    function() 
        local weps = savedWeps[source] --get the weps (JSON still) 
        if not weps then --check if there are not weps 
            return --end the script if there isn't weps 
        end 
        weps = fromJSON(weps) --convert the JSON to a table againn 
        --Loops through the weps table 
        for WepNum, WepAmmo in pairs(weps)do 
            giveWeapon(source,WepNum,WepAmmo) --give the player their weapons 
        end 
    end 
) 

Edited by Guest
Link to comment
  • 0

Thanks alot, although I can't see anything but 2 empty lines.. hehe, I figured out though on how to keep weapons on player death, not on my own, by the way :(, but I am trying to learn to script, if you can post the script you made, I can take a look at it, and maybe learn something from it, I hope :D

Link to comment
  • 0
Ok, I'll just make this script for you, but you would need to read and learn over it:
local savedWeps = {} --Stores all the saved weps 
addEventHandler("onPlayerWasted",root, --Triggered when a player dies 
    function() 
        --Loop through all the player weapons 
        local sourceWeps = {} --player weapons table 
        for i=1,12 do 
            local WepNum = getPedWeapon(source,i) --get the weapon from slot 
            local WepAmmo = getPedTotalAmmo(source,i) --get the ammount of ammo from weapon slot 
            if WepAmmo > 0 then --check if the weapon has ammo 
                sourceWeps[i] = {WepNum,WepAmmo} --store the weapon and the ammount of ammo in the player weapons table 
            end 
        end 
        savedWeps[source] = toJSON(sourceWeps) --convert the table into JSON 
    end 
) 
addEventHandler("onPlayerSpawn",root, --Triggered when a player spawns 
    function() 
        local weps = savedWeps[source] --get the weps (JSON still) 
        if not weps then --check if there are not weps 
            return --end the script if there isn't weps 
        end 
        weps = fromJSON(weps) --convert the JSON to a table againn 
        --Loops through the weps table 
        for WepNum, WepAmmo in pairs(weps)do 
            giveWeapon(source,WepNum,WepAmmo) --give the player their weapons 
        end 
    end 
) 

JSON for this matter makes no sense.

Link to comment
  • 0

Try this:

local savedWeps = {} --Stores all the saved weps 
addEventHandler("onPlayerWasted",root, --Triggered when a player dies 
    function() 
        --Loop through all the player weapons 
        local sourceWeps = {} --player weapons table 
        for i=1,12 do 
            local WepNum = getPedWeapon(source,i) --get the weapon from slot 
            local WepAmmo = getPedTotalAmmo(source,i) --get the ammount of ammo from weapon slot 
            if WepAmmo > 0 then --check if the weapon has ammo 
                sourceWeps[i] = {WepNum,WepAmmo} --store the weapon and the ammount of ammo in the player weapons table 
            end 
        end 
        savedWeps[source] = toJSON(sourceWeps) --convert the table into JSON 
    end 
) 
addEventHandler("onPlayerSpawn",root, --Triggered when a player spawns 
    function() 
        local weps = savedWeps[source] --get the weps (JSON still) 
        if not weps then --check if there are not weps 
            return --end the script if there isn't weps 
        end 
        weps = fromJSON(weps) --convert the JSON to a table againn 
        --Loops through the weps table 
        for _, wep in ipairs(weps)do 
            giveWeapon(source,wep[1],wep[2]) --give the player their weapons 
        end 
    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...