Jump to content

[SOLVED] Unable to create spawn window


Recommended Posts

Hi! So, I am still extremely new to Lua and MTA:SA scripting, but I was doing my best at trying to follow the tutorials on the wiki.

I wanted to create a window, that shows when the player loads in, and has them choose a location to spawn in. (Very similar to the wiki's provided example) However, when I load into the game, nothing happens. I was met with a black screen. I added in fadeCamera before the GUI calls to see if that helped (I tried to call it client side after they teleport), and still nothing!

Any help on this is MUCH appreciated!

Below is my client side code:

function createSpawnWindow()
    --Establish base for GUI window
    local sWidth, sHeight = guiGetScreenSize()
    local Width,Height = 231,188
    local X = (sWidth/2) - (Width/2)
    local Y = (sHeight/2) - (Height/2)
    --Create the window
    spawnWindow = guiCreateWindow(X,Y,Width,Height,"City Spawn", false)
    guiWindowSetSizable(spawnWindow,false)
    --Create the label
    spawnLabel = guiCreateLabel(18,23,191,33,"Please choose a city to spawn at",false,spawnWindow)
    guiLabelSetHorizontalAlign(spawnLabel,"center",true)
    --Create the buttons
    spawnButtonLS = guiCreateButton(18,63,195,35,"Los Santos",false,spawnWindow)
    spawnButtonSF = guiCreateButton(18,103,195,35,"San Fierro",false,spawnWindow)
    spawnButtonLV = guiCreateButton(18,143,195,35,"Las Venturas",false,spawnWindow)
    --Add the events to detect if the buttons are clicked
    addEventHandler("onClientGUIClick",spawnButtonLS,spawnThePlayer,false)
    addEventHandler("onClientGUIClick",spawnButtonSF,spawnThePlayer,false)
    addEventHandler("onClientGUIClick",spawnButtonLV,spawnThePlayer,false)
    --Show the UI and Mouse
    showCursor(true)
    guiSetVisible(spawnWindow,true)
end

addEventHandler("onClientResourceStart",resourceRoot,createSpawnWindow)

function spawnThePlayer(button,state)
    --Determine if the mouse has clicked
    if button == "left" and state == "up" then
        --Determine if the moust has clicked a button, and which
        if source == spawnPlayerLS then
            triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1479.6,-1612.8,14.0,0)
            outputChatBox("Welcome to Los Santos!",0,255,0)
        elseif source == spawnPlayerSF then
            triggerServerEvent("movePlayerToPosition",getLocalPlayer(),-2265.5,534.0,35.0,270)
            outputChatBox("Welcome to San Fierro!",0,255,0)
        elseif source == spawnPlayerLV then
            triggerServerEvent("movePlayerToPosition",getLocalPlayer(),2036.9,1545.2,10.8,270)
            outputChatBox("Welcome to Las Venturas!",0,255,0)
        end
        --Hide the window and the mouse
        guiSetVisible(spawnWindow,false)
        showCursor(false)
    end
end

and my server side:

function joinHandler()
    outputChatBox("Welcome to our server!",source,0,255,0)
    outputChatBox(" ",source,0,255,0)
    outputChatBox("Please choose a spawn location.",source,0,255,0)
end
addEventHandler("onPlayerJoin",getRootElement(),joinHandler)

function moveThePlayer(x,y,z,rotation)
    if x and y and z and rotation then
        local skin = getElementModel(client)
        spawnPlayer(client,x,y,z,rotation,skin,0,0)
        setCameraTarget(client,client)
    end
end
addEvent("movePlayerToPosition",true)
addEventHandler("movePlayerToPosition",root,moveThePlayer)

EDIT: The window now appears after discovering my initial code had multiple calls for fadeCamera improperly placed.

Edited by Stealthy Serval
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...