DarkM Posted February 13, 2010 Share Posted February 13, 2010 (edited) Alright, so I'm following the guides on the wiki and so far I've hit 2 walls. The command to spawn a vehicle doesn't work and the Login GUI doesn't show up. Here is my script.lua: function joinHandler() local x = 1743 local y = -1863 local z = 14 -- spawnPlayer(source, x, y, z) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("Welcome to DarkM's RP", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) -- 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 (createVehicle == false) 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 if (client) then spawnPlayer(client, 1959.55, -1714.46, 10) fadeCamera(client, true) outputChatBox("Welcome to DarkM's RP.", client) end else -- if the username or password are not correct, output message to player outputChatBox("Invalid username and/or password. Please re-connect and try again.",client) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) This is my gui.lua: 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 Wdith = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) -- make the window invisible guiSetVisible(wdwLogin, 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 = guiEditText(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", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) 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 Please help. P.S. I'm using the MTA Script Editor (updated to 2.9.3) Edited February 15, 2010 by Guest Link to comment
50p Posted February 13, 2010 Share Posted February 13, 2010 It's almost 6am here and I'm tired but I'll try to help. First, it's not OnClientResourceStart but onClientResourceStart. I'm not really sure what is wrong with the command but I'm sure the "if" statement at line 18 will never get executed since createVehicle is a function and it will never be false unless you set it to false. You need to debug the command. Link to comment
DarkM Posted February 13, 2010 Author Share Posted February 13, 2010 Okay the Login GUI shows up but now nothing happpens when I click on the login button. I tried doing the debugscript command but I get ACL: Denied access. Link to comment
Aibo Posted February 13, 2010 Share Posted February 13, 2010 i'm pretty sure the souce of submitLogin must be getLocalPlayer(), not the root element: triggerServerEvent("submitLogin", getLocalPlayer(), username, password) and function loginHandler(username,password) if username == "user" and password == "apple" then if (source) then spawnPlayer(source, 1959.55, -1714.46, 10) fadeCamera(source, true) outputChatBox("Welcome to DarkM's RP.", source) end else outputChatBox("Invalid username and/or password. Please re-connect and try again.", source) end end Link to comment
DarkM Posted February 13, 2010 Author Share Posted February 13, 2010 That didn't work either. How can I fix the "ACL denied access to debugscript" so that I can debug? Link to comment
50p Posted February 13, 2010 Share Posted February 13, 2010 That didn't work either.How can I fix the "ACL denied access to debugscript" so that I can debug? ACL.xml Link to comment
Aibo Posted February 13, 2010 Share Posted February 13, 2010 That didn't work either. and i didn't say that it'll fix all your problems for example, you have this in client script: local username = guiGetText(edtUser) local password = guiEditText(edtPass) what's guiEditText? Link to comment
Aibo Posted February 13, 2010 Share Posted February 13, 2010 fixed some more typos, marked with -- FIX tested, it works. except your spawnpoint was buggy, so i made it a little higher and you probably better restore login window if login failed, not asking player to reconnect. but thats up to you client: 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 -- FIX: Wdith > Width Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) -- make the window invisible guiSetVisible(wdwLogin, 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) -- FIX: guiEditText > guiGetText -- 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) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) 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 server: function joinHandler() local x = 1743 local y = -1863 local z = 14 -- spawnPlayer(source, x, y, z) -- fadeCamera(source, true) outputChatBox("Welcome to DarkM's RP", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) -- 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 spawnPlayer(source, 1959.55, -1714.46, 20) setCameraTarget(source, source) fadeCamera(source, true) outputChatBox("Welcome to DarkM's RP.", source) end else -- if the username or password are not correct, output message to player outputChatBox("Invalid username and/or password. Please re-connect and try again.",source) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) 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