DarkM Posted February 16, 2010 Share Posted February 16, 2010 I don't know what I did but the teleport window shows up at the start and the cursor doesn't go away after teleporting the second time it pops up. Please fix and clean up my script. I haven't a clue what I did and cant seem to fix it. script.lua(server): function joinHandler() local x = 1743 local y = -1863 local z = 14 -- spawnPlayer(source, x, y, z) -- fadeCamera(source, true) outputChatBox("--------------------", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) local time = getRealTime() setMinuteDuration(60000) setTime(time.hour, time.minute) -- create the function the command handler calls, with the arguments: thePlayer, command, vehicleModel function createVehicleForPlayer(thePlayer, command, vehicleModel) -- create a vehicle and stuff local x,y,z = getElementPosition(thePlayer) x = x + 5 -- ensures vehicle wont spawn in player -- create the vehicle and store the returned vehicle element in the ''createdVehicle'' variable local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) if (createdVehicle == false) then -- FIX: createVehicle > createdVehicle outputChatBox("Failed to create vehicle.",thePlayer) end end -- create a command handler addCommandHandler("createvehicle", createVehicleForPlayer) -- create our loginHandler function, with username and password parameters (passed from the client gui) function loginHandler(username,password) -- check that the username and password are correct if username == "user" and password == "apple" then -- the player has successfully logged in, so spawn them if (source) then setCameraTarget(source, source) fadeCamera(source, false) outputChatBox("Thank you for logging in.", source) end else -- if the username or password are not correct, output message to player outputChatBox("Invalid username and/or password. Please try again.",source) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) function kickInactivePlayer() kickPlayer(client,"Please accept our rules.") end 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) setCameraTarget(client,client) end end addEvent("movePlayerToPosition",true) addEventHandler("movePlayerToPosition",root,moveThePlayer) addEvent("clientKickInactivePlayer",true) addEventHandler("clientKickInactivePlayer",root,kickInactivePlayer) gui.lua(client): local rulesWarningTimer = nil function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save its element value into the variable 'wdwLogin' -- click on the function's name to read its documentation wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) -- define new X and Y positions for the first label X = 0.0825 Y = 0.2 -- define new Width and Height values for the first label Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window) guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value, so the second lebel is slightly below the first Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) -- Max chars to 50 guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) -- make the window invisible guiSetVisible(wdwLogin, false) -- stop players from being able to simply move the window out of the way guiWindowSetMovable(rulesWindow,false) -- stop players from being able to resize the window guiWindowSetSizable(rulesWindow,false) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) end -- attach the event handler to the root element of the resource -- this means it will only trigger when ts own resource is started addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and its components createLoginWindow() -- output a bried welcome message tot he player outputChatBox("Welcome to DarkM's RP, please log in.") -- if the GUI was successfully created, the show the GUI to the player if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly created, tell the player outputChatBox("An unexpected error has occured and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on components) showCursor(true) -- set the input focus onto the GUI, allowing players (For example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end ) -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'unsername' field local username = guiGetText(edtUser) -- get the text entered in the 'password' field local password = guiGetText(edtPass) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getLocalPlayer(), username, password) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide thr gui outputChatBox("Please enter a username and password.") end if username == "user" and password == "apple" then guiGetEnabled(false) guiSetVisible(wdwLogin, false) guiSetVisible(rulesWindow,true) end end end -- create the function that will hold our gui creation code function createRulesWindow() -- get the screen width and height local sWidth, sHeight = guiGetScreenSize() -- create the window, using some maths to find the centre of the screen local Width, Height = 445,445 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) -- create the window rulesWindow = guiCreateWindow(X,Y,Width,Height,"Rules",false) -- stop players from being able to simply move the window out of the way guiWindowSetMovable(rulesWindow,false) -- stop players from being able to resize the window guiWindowSetSizable(rulesWindow,false) guiSetVisible(rulesWindow,false) -- create the button and save the button gui element in a variable called 'rulesButton' rulesButton = guiCreateButton(137,394,158,37,"Accept",false,rulesWindow) -- create the label and save the label gui element in a variable calle 'rulesLabel' -- we set the text odf the label to our rules rulesLabel = guiCreateLabel(10,25,425,359,[[ Welcome to DarkM's RP Please carefully read the rules before accepting. By accepting the rules, you are agreeing to play by them. Anyone caught breaking these rules will be kicked and/or banned from this server. If you do not accept the rules within 90 seconds, you will be kicked. 1: No cheating. 2: No bug abuse. 3: No vehicle handling mods or other beneficial mods. 4: RP at all times. This is a strict RP server, any non-RP is punishable.]],false,rulesWindow) -- set the horizontal alignment of the label to center (ie: in the middle of the window) -- also note the final argument "true" -- this turns on wordwrap so if your text goes over the edge of the label, it will wrap around and start a new line automatically guiLabelSetHorizontalAlign(rulesLabel,"center",true) rulesWarningTimer = setTimer(inactivePlayer,30000,1,1) addEventHandler("onClientGUIClick", rulesButton, acceptRules, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- call the createRulesWindow function to create our gui createRulesWindow() -- show the cursor to the player showCursor(true,true) end ) function acceptRules(button,state) if button == "left" and state == "up" then guiSetVisible(rulesWindow, false) guiSetVisible(teleportWindow, true) showCursor(false,false) outputChatBox("Thank you for accepting the rules. Have fun RPing!") if rulesWarningTimer then killTimer(rulesWarningTimer) rulesWarningTimer = nil end end end function inactivePlayer(status) if status == 1 then outputChatBox("Please accept rules or else you will be kicked.") rulesWarningTimer = setTimer(inactivePlayer,30000,1,2) elseif status == 2 then triggerServerEvent("clientKickInactivePlayer",getLocalPlayer()) end end 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) addEventHandler("onClientGUIClick",teleportButtonBus,teleportPlayer,false) addEventHandler("onClientGUIClick",teleportButtonPlane,teleportPlayer,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,0) outputChatBox("You have arrived to Los Santos from the bus. Happy RPing!") elseif source == teleportButtonPlane then triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1686,-2239,14,0) outputChatBox("You have arrived to Los Santos from the plane. Happy RPing!") end guiSetVisible(teleportWindow, false) showCursor(false) fadeCamera(true) end end EDIT: fixed the teleport window popping up early but the mouse still wont go away... Link to comment
Aibo Posted February 16, 2010 Share Posted February 16, 2010 1. you forgot to guiSetInputEnabled(false), fixed 2. dont store login/passwords in client files, its unsafe and uhm... just weird added a server event if player succesfully logged in. 3. your rules timer was starting when rules window was created, not shown, moved it to login event. server: function joinHandler() outputChatBox("--------------------", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) local time = getRealTime() setMinuteDuration(60000) setTime(time.hour, time.minute) -- create the function the command handler calls, with the arguments: thePlayer, command, vehicleModel function createVehicleForPlayer(thePlayer, command, vehicleModel) -- create a vehicle and stuff local x,y,z = getElementPosition(thePlayer) x = x + 5 -- ensures vehicle wont spawn in player -- create the vehicle and store the returned vehicle element in the ''createdVehicle'' variable local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) if not createdVehicle then outputChatBox("Failed to create vehicle.",thePlayer) end end -- create a command handler addCommandHandler("createvehicle", createVehicleForPlayer) -- create our loginHandler function, with username and password parameters (passed from the client gui) function loginHandler(username,password) -- check that the username and password are correct if username == "user" and password == "apple" then -- the player has successfully logged in, so spawn them setCameraTarget(source, source) fadeCamera(source, false) outputChatBox("Thank you for logging in.", source) triggerClientEvent(source, "playerHasLoggedIn", source) else -- if the username or password are not correct, output message to player outputChatBox("Invalid username and/or password. Please try again.",source) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) function kickInactivePlayer() kickPlayer(client,"Please accept our rules.") end 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) setCameraTarget(client,client) end end addEvent("movePlayerToPosition",true) addEventHandler("movePlayerToPosition",root,moveThePlayer) addEvent("clientKickInactivePlayer",true) addEventHandler("clientKickInactivePlayer",root,kickInactivePlayer) client: local rulesWarningTimer = nil function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save its element value into the variable 'wdwLogin' -- click on the function's name to read its documentation wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) -- define new X and Y positions for the first label X = 0.0825 Y = 0.2 -- define new Width and Height values for the first label Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window) guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value, so the second lebel is slightly below the first Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) -- Max chars to 50 guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) -- make the window invisible guiSetVisible(wdwLogin, false) -- stop players from being able to simply move the window out of the way guiWindowSetMovable(rulesWindow,false) -- stop players from being able to resize the window guiWindowSetSizable(rulesWindow,false) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) end -- attach the event handler to the root element of the resource -- this means it will only trigger when ts own resource is started addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and its components createLoginWindow() -- output a bried welcome message tot he player outputChatBox("Welcome to DarkM's RP, please log in.") -- if the GUI was successfully created, the show the GUI to the player if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly created, tell the player outputChatBox("An unexpected error has occured and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on components) showCursor(true) -- set the input focus onto the GUI, allowing players (For example) to press 'T' without the chatbox opening guiSetInputEnabled(true) end ) -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'unsername' field local username = guiGetText(edtUser) -- get the text entered in the 'password' field local password = guiGetText(edtPass) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getLocalPlayer(), username, password) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide thr gui outputChatBox("Please enter a username and password.") end end end -- create the function that will hold our gui creation code function createRulesWindow() -- get the screen width and height local sWidth, sHeight = guiGetScreenSize() -- create the window, using some maths to find the centre of the screen local Width, Height = 445,445 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) -- create the window rulesWindow = guiCreateWindow(X,Y,Width,Height,"Rules",false) -- stop players from being able to simply move the window out of the way guiWindowSetMovable(rulesWindow,false) -- stop players from being able to resize the window guiWindowSetSizable(rulesWindow,false) guiSetVisible(rulesWindow,false) -- create the button and save the button gui element in a variable called 'rulesButton' rulesButton = guiCreateButton(137,394,158,37,"Accept",false,rulesWindow) -- create the label and save the label gui element in a variable calle 'rulesLabel' -- we set the text odf the label to our rules rulesLabel = guiCreateLabel(10,25,425,359,[[ Welcome to DarkM's RP Please carefully read the rules before accepting. By accepting the rules, you are agreeing to play by them. Anyone caught breaking these rules will be kicked and/or banned from this server. If you do not accept the rules within 90 seconds, you will be kicked. 1: No cheating. 2: No bug abuse. 3: No vehicle handling mods or other beneficial mods. 4: RP at all times. This is a strict RP server, any non-RP is punishable.]],false,rulesWindow) -- set the horizontal alignment of the label to center (ie: in the middle of the window) -- also note the final argument "true" -- this turns on wordwrap so if your text goes over the edge of the label, it will wrap around and start a new line automatically guiLabelSetHorizontalAlign(rulesLabel,"center",true) addEventHandler("onClientGUIClick", rulesButton, acceptRules, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- call the createRulesWindow function to create our gui createRulesWindow() -- show the cursor to the player showCursor(true,true) end ) function acceptRules(button,state) if button == "left" and state == "up" then guiSetVisible(rulesWindow, false) guiSetVisible(teleportWindow, true) showCursor(false,false) outputChatBox("Thank you for accepting the rules. Have fun RPing!") if rulesWarningTimer then killTimer(rulesWarningTimer) rulesWarningTimer = nil end end end function inactivePlayer(status) if status == 1 then outputChatBox("Please accept rules or else you will be kicked.") rulesWarningTimer = setTimer(inactivePlayer,30000,1,2) elseif status == 2 then triggerServerEvent("clientKickInactivePlayer",getLocalPlayer()) end end 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) addEventHandler("onClientGUIClick",teleportButtonBus,teleportPlayer,false) addEventHandler("onClientGUIClick",teleportButtonPlane,teleportPlayer,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,0) outputChatBox("You have arrived to Los Santos from the bus. Happy RPing!") elseif source == teleportButtonPlane then triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1686,-2239,14,0) outputChatBox("You have arrived to Los Santos from the plane. Happy RPing!") end guiSetVisible(teleportWindow, false) guiSetInputEnabled(false) showCursor(false) fadeCamera(true) end end addEvent("playerHasLoggedIn", true) addEventHandler("playerHasLoggedIn", getRootElement(), function() guiSetVisible(wdwLogin, false) guiSetVisible(rulesWindow,true) rulesWarningTimer = setTimer(inactivePlayer,30000,1,1) end ) Link to comment
DarkM Posted February 16, 2010 Author Share Posted February 16, 2010 Xbost saves the day once again. Thank you Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now