Jump to content

SpawnScreen GUI not showing on player join


Alen141

Recommended Posts

Hey guys, recently I got a spawn script, but as player joins the server the GUI dosen't show up.. and i have to slap myself to show it

script :

local localPlayer = getLocalPlayer() 
local resX, resY = guiGetScreenSize() 
local centerX = resX / 2 
local centerY = resY / 2 
local windowX = 400 
local windowY = 410 
local leftX = 20 
local bottomY = resY - windowY - 20 
  
local xml = xmlLoadFile("spawns.xml")             -- open the XML file 
local cityNodes = xmlNodeGetChildren(xml)       -- get all child nodes of the root node () 
local cities = {}                             -- create a new global variable to store the welcome messages 
for i,node in ipairs(cityNodes) do 
    cityname = xmlNodeGetAttribute(node, "name") 
    local classnodes = xmlNodeGetChildren(node) 
    cities[cityname] = {} 
    for i2,node2 in ipairs(classnodes) do 
        classname = xmlNodeGetAttribute(node2, "name") 
        local spawnnodes = xmlNodeGetChildren(node2) 
        cities[cityname][classname] = {} 
        for i3, node3 in ipairs(spawnnodes) do 
            skinName = xmlNodeGetAttribute(node3, "name") 
            cities[cityname][classname][skinName] = {} 
            cities[cityname][classname][skinName]["spawnX"] = xmlNodeGetAttribute(node3, "spawnX") 
            cities[cityname][classname][skinName]["spawnY"] = xmlNodeGetAttribute(node3, "spawnY") 
            cities[cityname][classname][skinName]["spawnZ"] = xmlNodeGetAttribute(node3, "spawnZ") 
            cities[cityname][classname][skinName]["skin"] = xmlNodeGetAttribute(node3, "skin") 
            cities[cityname][classname][skinName]["permission"] = xmlNodeGetAttribute(node3, "permission") 
            cities[cityname][classname][skinName]["information"] = xmlNodeGetAttribute(node3, "information") 
            cities[cityname][classname][skinName]["weapons"] = xmlNodeGetAttribute(node3, "weapons") 
        end 
    end 
end 
xmlUnloadFile(xml) 
  
addEventHandler("onClientResourceStart", resourceRoot, client ) 
function drawSpawnScreen() 
  
  
spawnWindow = guiCreateWindow(55, 140, 503, 430, "Spawn Menu", false) 
guiWindowSetMovable(spawnWindow, false) 
guiWindowSetSizable(spawnWindow, false) 
  
infoMemo = guiCreateMemo(20, 19, 474, 90, "", false, spawnWindow) 
guiMemoSetReadOnly(infoMemo, true) 
cityGridList = guiCreateGridList(20, 127, 173, 284, false, spawnWindow) 
guiGridListAddColumn(cityGridList, "City's", 0.9) 
classGridList = guiCreateGridList(194, 127, 145, 183, false, spawnWindow) 
guiGridListAddColumn(classGridList, "Classe's", 0.9) 
skinGridList = guiCreateGridList(349, 127, 132, 184, false, spawnWindow) 
guiGridListAddColumn(skinGridList, "Skin's", 0.9) 
spawnScreenOKButton = guiCreateButton(277, 320, 128, 67, "Spawn", false, spawnWindow) 
         
  
    for n, v in pairs(cities) do 
        local row = guiGridListAddRow(cityGridList) 
        guiGridListSetItemText(cityGridList, row, 1, n, false, false) 
    end 
  
  
    guiSetVisible(spawnWindow, false) 
    addEventHandler("onClientGUIClick", cityGridList, onCityClick) 
    addEventHandler("onClientGUIClick", classGridList, onClassClick) 
    addEventHandler("onClientGUIClick", skinGridList, onSkinClick) 
    addEventHandler("onClientGUIClick", spawnScreenOKButton, onSpawnButtonClick) 
    fadeCamera(true) 
    guiSetVisible(spawnWindow, true) 
    guiGridListSetSelectedItem(skinGridList, -1, 0) 
    showCursor(true) 
    showPlayerHudComponent ("all",false) 
end 
  
function onCityClick(button) 
    if source == cityGridList and button == "left" then 
        if guiGridListGetSelectedCount(cityGridList) > 0 then 
            guiGridListClear(classGridList) 
            local selectedRow, selectedCol = guiGridListGetSelectedItem( cityGridList ); -- get double clicked item in the gridlist 
            local cityName = guiGridListGetItemText( cityGridList, selectedRow, selectedCol ) -- get its text 
            local cityClasses = cities[cityName] 
            for x, y in pairs(cityClasses) do 
                local row = guiGridListAddRow(classGridList) 
                guiGridListSetItemText(classGridList, row, 1, x, false, false) 
            end 
            guiSetProperty(spawnScreenOKButton, "Disabled", "True") 
        end 
    end 
end 
  
function onClassClick(button) 
    if source == classGridList and button == "left" then 
        if guiGridListGetSelectedCount(cityGridList) > 0 and guiGridListGetSelectedCount(classGridList) > 0 then 
            guiGridListClear(skinGridList) 
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( cityGridList ); -- get double clicked item in the gridlist 
            local cityName = guiGridListGetItemText( cityGridList, selectedRow, selectedCol ) -- get its text 
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( classGridList ); -- get double clicked item in the gridlist 
            local className = guiGridListGetItemText( classGridList, selectedRow, selectedCol ) -- get its text 
  
            local classSkins = cities[cityName][className] 
            for x, y in pairs(classSkins) do 
                local row = guiGridListAddRow(skinGridList) 
  
                guiGridListSetItemText(skinGridList, row, 1, x, false, false) 
            end 
            guiSetProperty(spawnScreenOKButton, "Disabled", "True") 
        end 
    end 
end 
  
function onSkinClick(button) 
    if source == skinGridList and button == "left" then 
        if guiGridListGetSelectedCount(cityGridList) > 0 and guiGridListGetSelectedCount(classGridList) > 0 and guiGridListGetSelectedCount( skinGridList ) > 0 then 
            local selectedRow, selectedCol = guiGridListGetSelectedItem( cityGridList ); -- get double clicked item in the gridlist 
            local cityName = guiGridListGetItemText( cityGridList, selectedRow, selectedCol ) -- get its text 
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( classGridList ); -- get double clicked item in the gridlist 
            local className = guiGridListGetItemText( classGridList, selectedRow, selectedCol ) -- get its text 
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( skinGridList ); -- get double clicked item in the gridlist 
            local skinName = guiGridListGetItemText( skinGridList, selectedRow, selectedCol ) -- get its text 
  
            guiSetProperty(spawnScreenOKButton, "Disabled", "False") 
            guiSetText(infoMemo, cities[cityName][className][skinName]["information"]) 
        end 
    end 
end 
  
  
function onSpawnButtonClick(button) 
    if source == spawnScreenOKButton and button == "left" then 
        if guiGridListGetSelectedCount( cityGridList ) > 0 and guiGridListGetSelectedCount( classGridList ) > 0 and guiGridListGetSelectedCount( skinGridList ) > 0 then 
            local selectedRow, selectedCol = guiGridListGetSelectedItem( cityGridList ); -- get double clicked item in the gridlist 
            local cityName = guiGridListGetItemText( cityGridList, selectedRow, selectedCol ) -- get its text 
  
            local selectedRow, selectedCol = guiGridListGetSelectedItem( classGridList ); -- get double clicked item in the gridlist 
            local className = guiGridListGetItemText( classGridList, selectedRow, selectedCol ) -- get its text 
             
            local selectedRow, selectedCol = guiGridListGetSelectedItem( skinGridList ); -- get double clicked item in the gridlist 
            local skinName = guiGridListGetItemText( skinGridList, selectedRow, selectedCol ) -- get its text 
  
            local spawninfo = cities[cityName][className][skinName] 
            setElementData ( client, "Class", skinName ) 
            triggerServerEvent("onPlayerSpawnButton", getLocalPlayer(), spawninfo["spawnX"] , spawninfo["spawnY"], spawninfo["spawnZ"], className, spawninfo['permission'], spawninfo['skin'],spawninfo['weapons'], getLocalPlayer(), skinName) 
        else 
            displayError("Please make a selection!") 
        end 
    end 
end 
  
  
function hideSpawnScreen() 
    if spawnWindow then 
        guiSetVisible(spawnWindow, false) 
        showCursor(false) 
        if errorWindow then 
            guiSetVisible(errorWindow, false) 
        end 
        guiSetText(infoMemo, "") 
        currentSpawn = false 
        currentWeapons = false 
        currentColors = {} 
        currentLocation = {} 
    end 
    showPlayerHudComponent ("all",true) 
end 
  
addEvent("onSpawnSuccessful", true) 
addEventHandler("onSpawnSuccessful", getRootElement(), hideSpawnScreen) 
  
function createMessageBox() 
    errorWindow = guiCreateWindow(resX / 2 - 150, resY / 2 - 100, 300, 200, "Spawn Error", false) 
    errorLabel = guiCreateMemo(5, 25, 295, 125, "", false, errorWindow) 
    guiMemoSetReadOnly(errorLabel, true) 
    errorWindowButton = guiCreateButton(110, 160, 80, 25, "OK", false, errorWindow) 
    guiWindowSetMovable(errorWindow, false) 
    guiWindowSetSizable(errorWindow, false) 
    guiSetVisible(errorWindow, false) 
    addEventHandler("onClientGUIClick", errorWindowButton, function() 
    guiSetVisible(errorWindow, false) 
    guiSetProperty(errorWindow, "AlwaysOnTop", "False") 
    end, false) 
end 
  
function displayError(error) 
    if not errorWindow then 
        createMessageBox() 
    end 
    guiSetText(errorLabel, error) 
    guiSetProperty(errorWindow, "AlwaysOnTop", "True") 
    guiSetVisible(errorWindow, true) 
end 
  
addEvent("onSpawnError", true) 
addEventHandler("onSpawnError", getRootElement(), displayError) 
  
  
addCommandHandler( "spawnerror",displayError) 
  
function checkPlayerAlive() 
    triggerServerEvent("wasPlayerAliveEvent", getLocalPlayer()) 
end 
  
addEvent("onPlayerLoginSuccess", true) 
addEventHandler("onPlayerLoginSuccess", getRootElement(), checkPlayerAlive) 
addEventHandler("onClientPlayerLoginSucces", getLocalPlayer(), drawSpawnScreen) 
addEventHandler("onClientPlayerWasted", getLocalPlayer(), drawSpawnScreen) 
addEvent("onPlayerWasntAlive", true) 
addEventHandler("onPlayerWasntAlive", getRootElement(), drawSpawnScreen) 
  
function stopMinigunDamage ( attacker, weapon, bodypart ) 
    if ( getTeamName(getPlayerTeam(source)) == "PanAm Trainers" ) then 
        if ( getTeamName(getPlayerTeam(attacker)) ~= "PanAm Trainers" ) then 
            cancelEvent() 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), stopMinigunDamage ) 
  
fileDelete("spawn_client.lua") 
  

Link to comment
add this;
addEventHandler("onClientPlayerJoin", getLocalPlayer(), drawSpawnScreen) 

Read beneath onClientPlayerJoin.

onClientPlayerJoinClientside event

This event is triggered when a player joins a server. It is triggered for all players except the local player, as the local player joins the server before their client-side resources are started. It would also be possible for two players to join within a few seconds of each other and for the two players' scripts may not receive onClientPlayerJoin events as their scripts wouldn't have started yet.

use onClientResourceStart.

addEventHandler("onClientResourceStart", resourceRoot, drawSpawnScreen) 

Link to comment
add this;
addEventHandler("onClientPlayerJoin", getLocalPlayer(), drawSpawnScreen) 

Read beneath onClientPlayerJoin.

onClientPlayerJoinClientside event

This event is triggered when a player joins a server. It is triggered for all players except the local player, as the local player joins the server before their client-side resources are started. It would also be possible for two players to join within a few seconds of each other and for the two players' scripts may not receive onClientPlayerJoin events as their scripts wouldn't have started yet.

use onClientResourceStart.

addEventHandler("onClientResourceStart", resourceRoot, drawSpawnScreen) 

I still get black screen.. Maybe I put it on wrong line?

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