Jump to content

[HELP]Same Skin on Respawn - SOLVED


TheGamingMann

Recommended Posts

So I have this code I am working on. I am trying to get the players old skin and pass it trough so they respawn with it. So far I have it so it gets the skin but it takes the one before the player chooses what he/she wants.

Here is my c_spawnlist.lua:

  
local player = getLocalPlayer() 
local skin = getElementModel(player) 
  
function createSpawnList() 
    local sW, sH = guiGetScreenSize() 
    wdwList = guiCreateWindow((sW-830)/2, (sH-538)/2, 830, 538, "Spawn List", false) 
    guiWindowSetSizable(wdwList, false) 
    guiWindowSetMovable(wdwList, false) 
  
    glistMainList = guiCreateGridList((830-711)/2, (538-441)/2, 711, 441, false, wdwList) 
    guiGridListAddColumn(glistMainList, "Spawn Points", 0.9) 
    btnSpawn = guiCreateButton((830-264)/2, (538-35), 264, 35, "Spawn", false, wdwList) 
     
    addEventHandler("onClientGUIClick", btnSpawn, spawnHandler, false) 
     
    makeList() 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        createSpawnList() 
        guiSetVisible(wdwList, false) 
        showWindow() 
    end 
) 
  
function showWindow() 
    if not guiGetVisible(wdwList) then 
        guiSetVisible(wdwList, true) 
        showCursor(true, true) 
    end 
end 
addEvent("showWindow", true) 
addEventHandler("showWindow", player, showWindow) 
  
function hideSpawnList() 
    guiSetVisible(wdwList, false) 
    showCursor(false, false) 
end 
addEvent("hideWindow", true) 
addEventHandler("hideWindow", player, hideSpawnList) 
  
function makeList() 
    local file = xmlLoadFile("spawnpoints.xml") 
    if file then 
        for _, spawns in ipairs (xmlNodeGetChildren(file)) do 
            local row = guiGridListAddRow(glistMainList) 
            local name = xmlNodeGetAttribute(spawns, "name") 
            local x = xmlNodeGetAttribute(spawns, "x") 
            local y = xmlNodeGetAttribute(spawns, "y") 
            local z = xmlNodeGetAttribute(spawns, "z") 
            local rot = xmlNodeGetAttribute(spawns, "rot") 
            guiGridListSetItemText(glistMainList, row, 1, name, false, false) 
            guiGridListSetItemData(glistMainList, row, 1, {x, y, z, rot}) 
        end 
        xmlUnloadFile(file) 
    end 
end 
  
function spawnHandler(button, state) 
    if button == "left" and state == "up" then 
        local row, col = guiGridListGetSelectedItem(glistMainList) 
        local data = guiGridListGetItemData(glistMainList, row, col) 
        if row and col and row ~= -1 and col ~=-1 then 
            local x, y, z, rot = unpack(data) 
            triggerServerEvent("spawnPlayer", player, x, y, z, rot, skin, player) 
        end 
    end 
end 
  
addCommandHandler("respawn", showWindow) 
  

Here is my s_spawnlist:

  
function startSpawn(x, y, z, rot, skin, player) 
    spawnPlayer(player, x, y, z, rot, skin) 
    fadeCamera(player, true) 
    setCameraTarget(player) 
    triggerClientEvent("hideWindow", player) 
    outputChatBox("If you wish to change your skin use /skin", player, 255, 0, 0) 
end 
addEvent("spawnPlayer", true) 
addEventHandler("spawnPlayer", getRootElement(), startSpawn) 
  
addEventHandler( "onPlayerWasted", getRootElement(), 
    function() 
        triggerClientEvent("showWindow", source) 
    end 
) 
  

Thanks for any help in advanced.

-Fixed

Edited by Guest
Link to comment

Here is just a basic example:

local playerSkins = { } 
addEventHandler ( 'onPlayerWasted', root, function ( ) 
    playerSkins[source] = getPedSkin ( source ) 
end ) 
  
addEventHandler ( "onPlayerSpawn", root, function ( ) 
    local id = 0 
    if ( playerSkins [ source ] ) then 
        id = tonumber ( playerSkins [ source ] ) 
    end 
    setPedSkin ( source, id ) 
end ) 

Link to comment
local player = getLocalPlayer() 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sW, sH = guiGetScreenSize() 
        wdwList = guiCreateWindow((sW-830)/2, (sH-538)/2, 830, 538, "Spawn List", false) 
        guiWindowSetSizable(wdwList, false) 
        guiWindowSetMovable(wdwList, false) 
      
        glistMainList = guiCreateGridList((830-711)/2, (538-441)/2, 711, 441, false, wdwList) 
        guiGridListAddColumn(glistMainList, "Spawn Points", 0.9) 
        btnSpawn = guiCreateButton((830-264)/2, (538-35), 264, 35, "Spawn", false, wdwList) 
        
        addEventHandler("onClientGUIClick", btnSpawn, spawnHandler, false) 
        
        makeList() 
        showCursor(true, true) 
    end 
) 
  
function showWindow() 
    if not guiGetVisible(wdwList) then 
        guiSetVisible(wdwList, true) 
        showCursor(true, true) 
    end 
end 
addEvent("showWindow", true) 
addEventHandler("showWindow", player, showWindow) 
  
function hideSpawnList() 
    guiSetVisible(wdwList, false) 
    showCursor(false, false) 
end 
addEvent("hideWindow", true) 
addEventHandler("hideWindow", player, hideSpawnList) 
  
function makeList() 
    local file = xmlLoadFile("spawnpoints.xml") 
    if file then 
        for _, spawns in ipairs (xmlNodeGetChildren(file)) do 
            local row = guiGridListAddRow(glistMainList) 
            local name = xmlNodeGetAttribute(spawns, "name") 
            local x = xmlNodeGetAttribute(spawns, "x") 
            local y = xmlNodeGetAttribute(spawns, "y") 
            local z = xmlNodeGetAttribute(spawns, "z") 
            local rot = xmlNodeGetAttribute(spawns, "rot") 
            guiGridListSetItemText(glistMainList, row, 1, name, false, false) 
            guiGridListSetItemData(glistMainList, row, 1, {x, y, z, rot}) 
        end 
        xmlUnloadFile(file) 
    end 
end 
  
function spawnHandler(button, state) 
    if button == "left" and state == "up" then 
        local row, col = guiGridListGetSelectedItem(glistMainList) 
        local data = guiGridListGetItemData(glistMainList, row, col) 
        if row and col and row ~= -1 and col ~=-1 then 
            local x, y, z, rot = unpack(data) 
            local skin = getElementModel(player) 
            triggerServerEvent("spawnPlayer", player, x, y, z, rot, skin) 
        end 
    end 
end 
addCommandHandler("respawn", showWindow) 

function startSpawn(x, y, z, rot, skin) 
    spawnPlayer(source, x, y, z, rot, skin) 
    fadeCamera(source, true) 
    setCameraTarget(source) 
    triggerClientEvent(source, "hideWindow", source) 
    outputChatBox("If you wish to change your skin use /skin", source, 255, 0, 0) 
end 
addEvent("spawnPlayer", true) 
addEventHandler("spawnPlayer", root, startSpawn) 
  
addEventHandler("onPlayerWasted", root, 
    function() 
        triggerClientEvent(source, "showWindow", source) 
    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...