Jump to content
  • 0

Skin Changing on Player Wasted


PhantomNL

Question

Posted

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

11 answers to this question

Recommended Posts

  • 0
Posted

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.

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

  • 0
Posted
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.

  • 0
Posted (edited)

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

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

  • 0
Posted
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.

I used to know how to code, but then I took an arrow in the knee.

Project Redivivus - Remaking Old School MTA With New Code

MTA 0.6 Nightly 1 released

  • 0
Posted

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 
) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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