Hugo_Almeidowski Posted January 27, 2019 Share Posted January 27, 2019 CLIENT: function playerJoin() local chooseSpawn = guiCreateWindow (0.25, 0.15, 0.30, 0.4, "Spawn", true) guiWindowSetMovable(chooseSpawn, true) guiWindowSetSizable(chooseSpawn, false) showCursor(true) buttonLS = guiCreateButton(0.6, 0.87, 0.3, 0.1, "Los Santos", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos) buttonSF = guiCreateButton(0.1, 0.87, 0.3, 0.1, "San Fierro", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro) end addEventHandler("onClientPlayerJoin", getRootElement(), playerJoin) So. Supposedly, whenever a player joined the server a window with two buttons should appear. When he clicked in one button he would spawn LS, when he clicked on the other button he would spawn in SF. The problem is that the window doesn't even show up. The spawn functions are working because I made them triggable with commands and they work. Link to comment
DNL291 Posted January 27, 2019 Share Posted January 27, 2019 "onClientPlayerJoin" does not trigger for the local player, use the event "onClientResourceStart" instead. Also, put false in the fourth argument here: addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro) -- like this: addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) Link to comment
Hugo_Almeidowski Posted January 27, 2019 Author Share Posted January 27, 2019 8 minutes ago, DNL291 said: "onClientPlayerJoin" does not trigger for the local player, use the event "onClientResourceStart" instead. Also, put false in the fourth argument here: addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro) -- like this: addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) Thanks! But what does it trigger for then? Why false? It still isn't showing Link to comment
DNL291 Posted January 27, 2019 Share Posted January 27, 2019 It triggers for all players except the local player according to the wiki page: onClientPlayerJoin: 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. Regarding the "false" in "addEventHandler": Setting "false" will trigger the event only when the source element is clicked (in this case the button). By default, the event triggers when the parent element is clicked too. 28 minutes ago, Hugo_Almeidowski said: It still isn't showing Show the code you're trying here. Link to comment
Hugo_Almeidowski Posted January 27, 2019 Author Share Posted January 27, 2019 (edited) 49 minutes ago, DNL291 said: It triggers for all players except the local player according to the wiki page: onClientPlayerJoin: 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. Regarding the "false" in "addEventHandler": Setting "false" will trigger the event only when the source element is clicked (in this case the button). By default, the event triggers when the parent element is clicked too. Show the code you're trying here. Got it! Ok: meta.xml <meta> <info author="HugoAlmeida" name="O meu humilde servidor" description="Prepara-te, Bill Gates! Eu venho aí!" /> <script src="server.lua" type="server" /> <script src="client.lua" type="client" /> <script src="client/gui.lua" type="client" /> <script src="ficheiro.lua" /> <scrpt src="markets.lua" type="server" /> <script src="markersclient.lua" type="client" /> </meta> client.lua: function playerJoin() local chooseSpawn = guiCreateWindow (0.25, 0.15, 0.30, 0.4, "Spawn", true) guiWindowSetMovable(chooseSpawn, true) guiWindowSetSizable(chooseSpawn, false) showCursor(true) buttonLS = guiCreateButton(0.6, 0.87, 0.3, 0.1, "Los Santos", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) buttonSF = guiCreateButton(0.1, 0.87, 0.3, 0.1, "San Fierro", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) end addEventHandler("onClientResourceStart", getRootElement(), playerJoin) function spawnLosSantos() triggerServerEvent(spawnarLosSantos) end function spawnSanFierro() triggerServerEvent(spawnarSanFierro) end server.lua (the functions seem to be working here, because the commands that activate them work): function spawnLS(source) spawnPlayer (source, 1479, -1672, 14) setCameraTarget(source, source) end addEvent("spawnarLosSantos") addEventHandler("spawnarLosSantos", root, spawnLS) addCommandHandler("spawnls", spawnLS) addCommandHandler("ls", spawnLS) function spawnSF(source) spawnPlayer (source, -2706, 376, 5) setCameraTarget(source, source) end addEvent("spawnarSanFierro") addEventHandler("spawnarSanFierro", root, spawnSF) addCommandHandler("spawnsf", spawnSF) addCommandHandler("sf", spawnSF) function joinHandler() local playerName = getPlayerName(source) fadeCamera(source, true) outputChatBox (horaS.. corMS.. "Sê bem-vindo ao meu servidor, caro " ..corJogador.. playerName.. corMS..".", source, 66, 212, 244, true) end addEventHandler("onPlayerJoin", root, joinHandler) Edited January 27, 2019 by Hugo_Almeidowski Link to comment
DNL291 Posted January 27, 2019 Share Posted January 27, 2019 Well, those are the errors I can see: This line in meta.xml: <scrpt src="markets.lua" type="server" /> There's a typo, replace "scrpt" with "script". Use resourceRoot instead of getRootElement() here: addEventHandler("onClientResourceStart", getRootElement(), playerJoin) Incorrect use of triggerServerEvent, it must be like this: triggerServerEvent( "spawnarLosSantos", localPlayer ) Set to "true" the 2nd argument (the arg: allowRemoteTrigger) of addEvent: addEvent("spawnarLosSantos", true) In the spawning function, do this: function spawnLS(thePlayer) local thePlayer = thePlayer and thePlayer or source spawnPlayer (thePlayer, 1479, -1672, 14) setCameraTarget(thePlayer, thePlayer) end Hope you understood it ;) Link to comment
Hugo_Almeidowski Posted January 27, 2019 Author Share Posted January 27, 2019 1 hour ago, DNL291 said: Well, those are the errors I can see: This line in meta.xml: <scrpt src="markets.lua" type="server" /> There's a typo, replace "scrpt" with "script". Use resourceRoot instead of getRootElement() here: addEventHandler("onClientResourceStart", getRootElement(), playerJoin) Incorrect use of triggerServerEvent, it must be like this: triggerServerEvent( "spawnarLosSantos", localPlayer ) Set to "true" the 2nd argument (the arg: allowRemoteTrigger) of addEvent: addEvent("spawnarLosSantos", true) In the spawning function, do this: function spawnLS(thePlayer) local thePlayer = thePlayer and thePlayer or source spawnPlayer (thePlayer, 1479, -1672, 14) setCameraTarget(thePlayer, thePlayer) end Hope you understood it I think I did. Thanks for the help!!! But it's stil not showing up haha Link to comment
DNL291 Posted January 27, 2019 Share Posted January 27, 2019 Have you used the /debugscript 3 command? Make sure there's no errors related to this code showing. Btw, show your code so I can see how it is. Link to comment
Hugo_Almeidowski Posted January 27, 2019 Author Share Posted January 27, 2019 49 minutes ago, DNL291 said: Have you used the /debugscript 3 command? Make sure there's no errors related to this code showing. Btw, show your code so I can see how it is. It says Incorrect client type for this command. My code: meta.xml <meta> <info author="HugoAlmeida" name="O meu humilde servidor" description="Prepara-te, Bill Gates! Eu venho aí!" /> <script src="server.lua" type="server" /> <script src="client.lua" type="client" /> <script src="ficheiro.lua" /> <script src="markers.lua" type="server" /> <script src="markersclient.lua" type="client" /> </meta> client.lua function playerJoin() local chooseSpawn = guiCreateWindow (0.25, 0.15, 0.30, 0.4, "Spawn", true) guiWindowSetMovable(chooseSpawn, true) guiWindowSetSizable(chooseSpawn, false) showCursor(true) buttonLS = guiCreateButton(0.6, 0.87, 0.3, 0.1, "Los Santos", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) buttonSF = guiCreateButton(0.1, 0.87, 0.3, 0.1, "San Fierro", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) end addEventHandler("onClientResourceStart", resourceRoot, playerJoin) function spawnLosSantos() triggerServerEvent("spawnarLosSantos", localPlayer) end function spawnSanFierro() triggerServerEvent("spawnarSanFierro", localPlayer) end server.lua function spawnLS(thePlayer) local thePlayer = thePlayer and thePlayer or source spawnPlayer (thePlayer, 1479, -1672, 14) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarLosSantos", true) addEventHandler("spawnarLosSantos", root, spawnLS) addCommandHandler("spawnls", spawnLS) addCommandHandler("ls", spawnLS) function spawnSF(thePlayer) local thePlayer = thePlayer and thePlayer or source spawnPlayer (thePlayer, -2706, 376, 5) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarSanFierro", true) addEventHandler("spawnarSanFierro", root, spawnSF) addCommandHandler("spawnsf", spawnSF) addCommandHandler("sf", spawnSF) function joinHandler() local playerName = getPlayerName(source) fadeCamera(source, true) outputChatBox (horaS.. corMS.. "Sê bem-vindo ao meu servidor, caro " ..corJogador.. playerName.. corMS..".", source, 66, 212, 244, true) end addEventHandler("onPlayerJoin", root, joinHandler) Link to comment
DNL291 Posted January 28, 2019 Share Posted January 28, 2019 4 hours ago, Hugo_Almeidowski said: It says Incorrect client type for this command. It does not work on server console, you should type this command in-game. 4 hours ago, Hugo_Almeidowski said: My code: meta.xml <meta> <info author="HugoAlmeida" name="O meu humilde servidor" description="Prepara-te, Bill Gates! Eu venho aí!" /> <script src="server.lua" type="server" /> <script src="client.lua" type="client" /> <script src="ficheiro.lua" /> <script src="markers.lua" type="server" /> <script src="markersclient.lua" type="client" /> </meta> client.lua function playerJoin() local chooseSpawn = guiCreateWindow (0.25, 0.15, 0.30, 0.4, "Spawn", true) guiWindowSetMovable(chooseSpawn, true) guiWindowSetSizable(chooseSpawn, false) showCursor(true) buttonLS = guiCreateButton(0.6, 0.87, 0.3, 0.1, "Los Santos", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) buttonSF = guiCreateButton(0.1, 0.87, 0.3, 0.1, "San Fierro", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) end addEventHandler("onClientResourceStart", resourceRoot, playerJoin) function spawnLosSantos() triggerServerEvent("spawnarLosSantos", localPlayer) end function spawnSanFierro() triggerServerEvent("spawnarSanFierro", localPlayer) end server.lua function spawnLS(thePlayer) local thePlayer = thePlayer and thePlayer or source spawnPlayer (thePlayer, 1479, -1672, 14) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarLosSantos", true) addEventHandler("spawnarLosSantos", root, spawnLS) addCommandHandler("spawnls", spawnLS) addCommandHandler("ls", spawnLS) function spawnSF(thePlayer) local thePlayer = thePlayer and thePlayer or source spawnPlayer (thePlayer, -2706, 376, 5) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarSanFierro", true) addEventHandler("spawnarSanFierro", root, spawnSF) addCommandHandler("spawnsf", spawnSF) addCommandHandler("sf", spawnSF) function joinHandler() local playerName = getPlayerName(source) fadeCamera(source, true) outputChatBox (horaS.. corMS.. "Sê bem-vindo ao meu servidor, caro " ..corJogador.. playerName.. corMS..".", source, 66, 212, 244, true) end addEventHandler("onPlayerJoin", root, joinHandler) I see no errors by looking at the code. Test this code with debug messages and post here what it shows in chatbox: Client: function playerJoin() outputChatBox("onClientResourceStart 1") local chooseSpawn = guiCreateWindow (0.25, 0.15, 0.30, 0.4, "Spawn", true) guiWindowSetMovable(chooseSpawn, true) guiWindowSetSizable(chooseSpawn, false) showCursor(true) buttonLS = guiCreateButton(0.6, 0.87, 0.3, 0.1, "Los Santos", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) buttonSF = guiCreateButton(0.1, 0.87, 0.3, 0.1, "San Fierro", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) outputChatBox("onClientResourceStart window: "..tostring(chooseSpawn)) outputChatBox("onClientResourceStart button #1: "..tostring(buttonLS)) outputChatBox("onClientResourceStart button #2: "..tostring(buttonSF)) end addEventHandler("onClientResourceStart", resourceRoot, playerJoin) function spawnLosSantos() outputChatBox("spawnLosSantos") triggerServerEvent("spawnarLosSantos", localPlayer) end function spawnSanFierro() outputChatBox("spawnSanFierro") triggerServerEvent("spawnarSanFierro", localPlayer) end Server: function spawnLS(thePlayer) local thePlayer = thePlayer and thePlayer or source outputChatBox("thePlayer: "..tostring(thePlayer)) spawnPlayer (thePlayer, 1479, -1672, 14) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarLosSantos", true) addEventHandler("spawnarLosSantos", root, spawnLS) addCommandHandler("spawnls", spawnLS) addCommandHandler("ls", spawnLS) function spawnSF(thePlayer) local thePlayer = thePlayer and thePlayer or source outputChatBox("thePlayer: "..tostring(thePlayer)) spawnPlayer (thePlayer, -2706, 376, 5) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarSanFierro", true) addEventHandler("spawnarSanFierro", root, spawnSF) addCommandHandler("spawnsf", spawnSF) addCommandHandler("sf", spawnSF) function joinHandler() outputChatBox("joinHandler") local playerName = getPlayerName(source) fadeCamera(source, true) outputChatBox (horaS.. corMS.. "Sê bem-vindo ao meu servidor, caro " ..corJogador.. playerName.. corMS..".", source, 66, 212, 244, true) end addEventHandler("onPlayerJoin", root, joinHandler) Link to comment
Hugo_Almeidowski Posted January 28, 2019 Author Share Posted January 28, 2019 (edited) 10 hours ago, DNL291 said: It does not work on server console, you should type this command in-game. I see no errors by looking at the code. Test this code with debug messages and post here what it shows in chatbox: Client: function playerJoin() outputChatBox("onClientResourceStart 1") local chooseSpawn = guiCreateWindow (0.25, 0.15, 0.30, 0.4, "Spawn", true) guiWindowSetMovable(chooseSpawn, true) guiWindowSetSizable(chooseSpawn, false) showCursor(true) buttonLS = guiCreateButton(0.6, 0.87, 0.3, 0.1, "Los Santos", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonLS, spawnLosSantos, false) buttonSF = guiCreateButton(0.1, 0.87, 0.3, 0.1, "San Fierro", true, chooseSpawn) addEventHandler ("onClientGUIClick", buttonSF, spawnSanFierro, false) outputChatBox("onClientResourceStart window: "..tostring(chooseSpawn)) outputChatBox("onClientResourceStart button #1: "..tostring(buttonLS)) outputChatBox("onClientResourceStart button #2: "..tostring(buttonSF)) end addEventHandler("onClientResourceStart", resourceRoot, playerJoin) function spawnLosSantos() outputChatBox("spawnLosSantos") triggerServerEvent("spawnarLosSantos", localPlayer) end function spawnSanFierro() outputChatBox("spawnSanFierro") triggerServerEvent("spawnarSanFierro", localPlayer) end Server: function spawnLS(thePlayer) local thePlayer = thePlayer and thePlayer or source outputChatBox("thePlayer: "..tostring(thePlayer)) spawnPlayer (thePlayer, 1479, -1672, 14) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarLosSantos", true) addEventHandler("spawnarLosSantos", root, spawnLS) addCommandHandler("spawnls", spawnLS) addCommandHandler("ls", spawnLS) function spawnSF(thePlayer) local thePlayer = thePlayer and thePlayer or source outputChatBox("thePlayer: "..tostring(thePlayer)) spawnPlayer (thePlayer, -2706, 376, 5) setCameraTarget(thePlayer, thePlayer) end addEvent("spawnarSanFierro", true) addEventHandler("spawnarSanFierro", root, spawnSF) addCommandHandler("spawnsf", spawnSF) addCommandHandler("sf", spawnSF) function joinHandler() outputChatBox("joinHandler") local playerName = getPlayerName(source) fadeCamera(source, true) outputChatBox (horaS.. corMS.. "Sê bem-vindo ao meu servidor, caro " ..corJogador.. playerName.. corMS..".", source, 66, 212, 244, true) end addEventHandler("onPlayerJoin", root, joinHandler) I can't use the command, it says I don't have permission, even tho I gave myself admin. About the debugging messages, I just received one saying joinHandler and the ones when I teleport. The spawn functions are working. Edited January 28, 2019 by Hugo_Almeidowski Link to comment
Hugo_Almeidowski Posted January 28, 2019 Author Share Posted January 28, 2019 4 hours ago, Hugo_Almeidowski said: I can't use the command, it says I don't have permission, even tho I gave myself admin. About the debugging messages, I just received one saying joinHandler and the ones when I teleport. The spawn functions are working. I made it work. I created a new client2.lua Copied literally the same code Now it works... wat 1 minute ago, Hugo_Almeidowski said: I made it work. I created a new client2.lua Copied literally the same code Now it works... wat And it stopped working again... wtf 2 minutes ago, Hugo_Almeidowski said: I made it work. I created a new client2.lua Copied literally the same code Now it works... wat And it stopped working again... wtf It's something related with this code (that comes after the one we were trying to fix) function checkPing() local ping = getPlayerPing(getLocalPlayer()) outputChatBox(ping, localPlayer) if (ping > 200) then outputChatBox("O teu ping é".. ping.. ". Está muito elevado! Tenta reduzi-lo se possível.") else if (ping <100) then outputChatBox("O teu ping é".. ping.. ". Está ótimo! Tenta mantê-lo assim.") else outputChatBox("O teu ping é".. ping.. ". Está razoável! Tenta que não aumente.") end end addCommandHandler("pingz", checkPing) Whenever I take it out of the script, it works. Link to comment
DNL291 Posted January 28, 2019 Share Posted January 28, 2019 5 hours ago, Hugo_Almeidowski said: I can't use the command, it says I don't have permission, even tho I gave myself admin. It should have worked, maybe it's some problem with your ACL. 1 hour ago, Hugo_Almeidowski said: I made it work. I created a new client2.lua Copied literally the same code Now it works... wat And it stopped working again... wtf It's something related with this code (that comes after the one we were trying to fix) function checkPing() local ping = getPlayerPing(getLocalPlayer()) outputChatBox(ping, localPlayer) if (ping > 200) then outputChatBox("O teu ping é".. ping.. ". Está muito elevado! Tenta reduzi-lo se possível.") else if (ping <100) then outputChatBox("O teu ping é".. ping.. ". Está ótimo! Tenta mantê-lo assim.") else outputChatBox("O teu ping é".. ping.. ". Está razoável! Tenta que não aumente.") end end addCommandHandler("pingz", checkPing) Whenever I take it out of the script, it works. I guess that's because it has an extra symbol in the code that appears when copying from the forums. This is happening to me when I copy the client-side code (look at the end of the code): Converting to ANSI: Be sure to remove these symbols and test your script again. 1 Link to comment
Hugo_Almeidowski Posted January 28, 2019 Author Share Posted January 28, 2019 1 hour ago, DNL291 said: It should have worked, maybe it's some problem with your ACL. I guess that's because it has an extra symbol in the code that appears when copying from the forums. This is happening to me when I copy the client-side code (look at the end of the code): Converting to ANSI: Be sure to remove these symbols and test your script again. No symbols whatsoever Link to comment
DNL291 Posted January 28, 2019 Share Posted January 28, 2019 You'll need to fix your admin permissions to be able to use the /debugscript 3 command. Sorry but there's nothing else I can help you with, I even tested the code and it works. Link to comment
Hugo_Almeidowski Posted January 29, 2019 Author Share Posted January 29, 2019 18 hours ago, DNL291 said: You'll need to fix your admin permissions to be able to use the /debugscript 3 command. Sorry but there's nothing else I can help you with, I even tested the code and it works. Alright. Thanks! 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