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