Jump to content

Buttons in Teleport Window Don't Work


DarkM

Recommended Posts

Posted

The buttons for my teleport window don't work. Also, how would i go about making the camera fade in after teleporting? (I made it so that the screen is black until teleporting.)

gui.lua (from the beginning of teleport window):

function createTeleportWindow()
local sWidth, sHeight = guiGetScreenSize()
 
local Width,Height = 231,188
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
teleportWindow = guiCreateWindow(X,Y,Width,Height,"Starting Area",false)
 
guiWindowSetSizable(teleportWindow,false)
 
teleportLabel = guiCreateLabel(18,23,191,33,"Bus or Plane?",false,teleportWindow)
 
guiLabelSetHorizontalAlign(teleportLabel,"center",true)
 
teleportButtonBus = guiCreateButton(18,63,195,35,"Bus",false,teleportWindow)
 
teleportButtonPlane = guiCreateButton(18,143,195,35,"Plane",false,teleportWindow)
 
guiSetVisible(teleportWindow,false)
end
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
function ()
	createTeleportWindow()
end
)
 
function teleportPlayer(button,state)
if button == "left" and state == "up" then
if source == teleportButtonBus then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1743,-1863,14)
outputChatBox("You have arrived to Los Santos from the bus. Happy RPing!")
 
elseif source == teleportButtonPlane then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1686,-2239,14)
outputChatBox("You have arrived to Los Santos from the plane. Happy RPing!")
 
end
 
guiSetVisible(teleportWindow, false)
showCursor(false)
end
addEventHandler("onClientGUIClick",teleportButtonBus,teleportPlayer,false)
addEventHandler("onClientGUIClick",teleportButtonPlane,teleportPlayer,false)
end

script.lua (from moveThePlayer):

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

Am I missing something?

Posted

variable root not set in script.lua

and i would use

setElementPosition instead of spawnPlayer

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
guiSetVisible(teleportWindow, false)
showCursor(false)
end
addEventHandler("onClientGUIClick",teleportButtonBus,teleportPlayer,false)
addEventHandler("onClientGUIClick",teleportButtonPlane,teleportPlayer,false)
end

Put these event handlers inside the createTeleportWindow function.

Projects:

Slothbot | Maximap

Posted
guiSetVisible(teleportWindow, false)
showCursor(false)
end
addEventHandler("onClientGUIClick",teleportButtonBus,teleportPlayer,false)
addEventHandler("onClientGUIClick",teleportButtonPlane,teleportPlayer,false)
end

Put these event handlers inside the createTeleportWindow function.

Thank you, I tried putting those in the wrong function after posting.

EDIT: Alright so now the buttons work and it teleports me but I can't move.

EDIT2: Switched setElementPosition back to spawnPlayer and I can now move around :D

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