Abbas_gamer100 Posted January 17, 2017 Share Posted January 17, 2017 (edited) I have created a GUI. It is supposed to either spawn you at a base (a base that I created and mapped) and/or kills you. It is supposed to be activated by a command. But it didn't work. Can you look at my script and tell me what have I done wrong? And if you know how to bind the GUI to a specific button please tell me how because I tried all methods. function createSpawningPanel() SpawnWindow = guiCreateWindow(319, 196, 408, 277, "Base Spawning Panel", false) guiWindowSetMovable(SpawnWindow, false) guiWindowSetSizable(SpawnWindow, false) Button[1] = guiCreateButton(17, 38, 376, 73, "Go to the base", false, SpawnWindow) Button[2] = guiCreateButton(14, 161, 379, 71, "Kill yourself", false, SpawnWindow) guiSetVisible(SpawnWindow,false) end addEventHandler("onClientGUIClick", Button[1], teleportPlayer, false) addEventHandler("onClientGUIClick", Button[2], teleportPlayer, false) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () createSpawningPanel() end ) function openSpawnWindow() guiSetVisible(SpawnWindow,true) showCursor(true,true) end addCommandHandler("teleportme",openSpawnWindow) function teleportPlayer(button,state) if button == "left" and state == "up" then if source == Button[1] then triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1479.6,-1612.8,14.0,0) elseif source == Button[2] then killPed(sourcePlayer,sourcePlayer) end guiSetVisible(SpawnWindow,false) showCursor(false) end end Edited January 17, 2017 by Abbas_gamer100 Link to comment
LoPollo Posted January 17, 2017 Share Posted January 17, 2017 (edited) Use code instead of quote next time, it helps readability a lot. just a note (not an error!): getResourceRootElement(getThisResource()) = resourceRoot, getThisResource() = resource (these are predefined variables) Calling addEventHandler with Button when it's nil won't add the handler. Even the function teleportPlayer wasn't define at that point in the code. So below there's the code without these 2 errors, try it. As always, it's untested and read quickly, so tell us if it solved the issue and if it didn't also include errors, since both of the above said problems produce errors. Use debugscript 3 when scripting an testing, otherwise check the logs (clientscript.log and server.log) function createSpawningPanel() SpawnWindow = guiCreateWindow(319, 196, 408, 277, "Base Spawning Panel", false) guiWindowSetMovable(SpawnWindow, false) guiWindowSetSizable(SpawnWindow, false) guiSetVisible(SpawnWindow,false) Button[1] = guiCreateButton(17, 38, 376, 73, "Go to the base", false, SpawnWindow) addEventHandler("onClientGUIClick", Button[1], teleportPlayer, false) Button[2] = guiCreateButton(14, 161, 379, 71, "Kill yourself", false, SpawnWindow) addEventHandler("onClientGUIClick", Button[2], teleportPlayer, false) end addEventHandler("onClientResourceStart", resourceRoot, function () createSpawningPanel() end ) function openSpawnWindow() guiSetVisible( SpawnWindow, true ) showCursor( true, true ) end addCommandHandler( "teleportme", openSpawnWindow ) function teleportPlayer(button,state) if button == "left" and state == "up" then if source == Button[1] then triggerServerEvent("movePlayerToPosition",getLocalPlayer(),1479.6,-1612.8,14.0,0) elseif source == Button[2] then killPed(sourcePlayer,sourcePlayer) end guiSetVisible(SpawnWindow,false) showCursor(false) end end Remember that the more detailed and accurated the description of the problem is, the faster and better the fix, correction or workaround come. Edited January 17, 2017 by LoPollo 1 Link to comment
Abbas_gamer100 Posted January 17, 2017 Author Share Posted January 17, 2017 It didn't work. My problem in full description is. I type the command but the GUI never shows up(in the server). I watch out for the command's spelling, nothing! I try and type it in the Console and other places, still not working. The GUI doesn't show up when I call the command in the server. Link to comment
LoPollo Posted January 17, 2017 Share Posted January 17, 2017 (edited) Another note i didn't see: getLocalPlayer() = localPlayer, just so you know. About the problem: 17 minutes ago, Abbas_gamer100 said: but the GUI never shows up(in the server) In the server? Here i can't see errors. Did you use debugscript 3? just to make sure there are no syntax errors... If there are not errors then i would do this: using outputDebugString/iprint to check where the code runs and where not. function createSpawningPanel() SpawnWindow = guiCreateWindow(319, 196, 408, 277, "Base Spawning Panel", false) guiWindowSetMovable(SpawnWindow, false) guiWindowSetSizable(SpawnWindow, false) guiSetVisible(SpawnWindow,false) Button[1] = guiCreateButton(17, 38, 376, 73, "Go to the base", false, SpawnWindow) addEventHandler("onClientGUIClick", Button[1], teleportPlayer, false) Button[2] = guiCreateButton(14, 161, 379, 71, "Kill yourself", false, SpawnWindow) addEventHandler("onClientGUIClick", Button[2], teleportPlayer, false) outputDebugString( "CreateSpawningPanel called and completed!" ) end addEventHandler("onClientResourceStart", resourceRoot, function () createSpawningPanel() end ) function openSpawnWindow() guiSetVisible( SpawnWindow, true ) showCursor( true, true ) outputDebugString( "opened window! [i feel useless]" ) end addCommandHandler( "teleportme", openSpawnWindow ) function teleportPlayer(button,state) if button == "left" and state == "up" then outputDebugString( "Executing teleportPlayer" ) if source == Button[1] then triggerServerEvent( "movePlayerToPosition", localPlayer, 1479.6,-1612.8,14.0,0 ) outputDebugString( "Button 1 pressed" ) elseif source == Button[2] then killPed(sourcePlayer,sourcePlayer) outputDebugString( "Button 2 pressed" ) end guiSetVisible(SpawnWindow,false) showCursor(false) outputDebugString( "teleportPlayer executed!" ) end end Tell us what's shown and what not Edited January 17, 2017 by LoPollo Link to comment
Abbas_gamer100 Posted January 17, 2017 Author Share Posted January 17, 2017 I am pretty certain for some reason that the problem is in my meta.xml file. Here is my meta.xml file. Maybe I didn't define the script correctly?? The script file's name is Spawn_Panel.lua <meta> <info author="YourName" type="gamemode" name="My Server" description="My first MTA server" /> <script src="script.lua" type="server"/> <scipt src="Spawn_Panel.lua" type="server"/> </meta> Link to comment
LoPollo Posted January 17, 2017 Share Posted January 17, 2017 yes, it's in the meta line 4: replace type="server" with type="client" Link to comment
Abbas_gamer100 Posted January 17, 2017 Author Share Posted January 17, 2017 (edited) It still doesn't work. And when I type the command it doesn't show/say anything... I don't know what's the problem And debugscript 3 doesn't work at all. It says incorrect client type in the Console. Edited January 17, 2017 by Abbas_gamer100 Link to comment
LoPollo Posted January 17, 2017 Share Posted January 17, 2017 (edited) Didn't see scipt, it should be script (meta.xml@Line 4) Edited January 17, 2017 by LoPollo Link to comment
Abbas_gamer100 Posted January 17, 2017 Author Share Posted January 17, 2017 YES FINALLY THANK YOU A LOT!! The GUI has showed up. But it is bugged a lot. It only shows the "Go to the base button". And it doesn't work(not teleporting on pressing the button). Link to comment
LoPollo Posted January 18, 2017 Share Posted January 18, 2017 Are there errors reported? Also try adding some output (debug/chatbox... whatever you want) so you can see what the script is executing Link to comment
Abbas_gamer100 Posted January 18, 2017 Author Share Posted January 18, 2017 It says attempt to call guiSetVisible <a nil value>... I think I made some changed to the script and they are the reason. Here is the script: function createSpawningPanel() SpawnWindow = guiCreateWindow(319, 196, 408, 277, "Base Spawning Panel", false) guiWindowSetMovable(SpawnWindow, false) guiWindowSetSizable(SpawnWindow, false) guiSetVisible(SpawnWindow,false) Button[1] = guiCreateButton(17, 38, 376, 73, "Go to the base", false, SpawnWindow) addEventHandler("onClientGUIClick", Button[1], teleportPlayer, false) Button[2] = guiCreateButton(14, 161, 379, 71, "Kill yourself", false, SpawnWindow) addEventHandler("onClientGUIClick", Button[2], teleportPlayer, false) outputDebugString( "CreateSpawningPanel called and completed!" ) end addEventHandler("onClientResourceStart", resourceRoot, function () createSpawningPanel() end ) function openSpawnWindow() guiSetVisible( SpawnWindow, true ) showCursor( true, true ) outputDebugString( "opened window! [i feel useless]" ) end addCommandHandler( "teleportme", openSpawnWindow ) function teleportPlayer(button,state) if button == "left" and state == "up" then outputDebugString( "Executing teleportPlayer" ) if source == Button[1] then triggerServerEvent( "movePlayerToPosition", localPlayer, 1479.6,-1612.8,14.0,0 ) outputDebugString( "Button 1 pressed" ) elseif source == Button[2] then killPed(sourcePlayer,sourcePlayer) outputDebugString( "Button 2 pressed" ) end guiSetVisible(SpawnWindow,false) showCursor(false) outputDebugString( "teleportPlayer executed!" ) end end Link to comment
iPrestege Posted January 18, 2017 Share Posted January 18, 2017 You have to make sure it's a client side in the meta.xml file to handle this file as client also post your new edited meta. Link to comment
LoPollo Posted January 18, 2017 Share Posted January 18, 2017 (edited) 13 hours ago, Abbas_gamer100 said: YES FINALLY THANK YOU A LOT!! The GUI has showed up. But it is bugged a lot. It only shows the "Go to the base button". And it doesn't work(not teleporting on pressing the button). the gui is partly working, that means the file is loaded in the client, and thus the meta is correct on this Edited January 18, 2017 by LoPollo Link to comment
Abbas_gamer100 Posted January 18, 2017 Author Share Posted January 18, 2017 So what is the bug currently. And how to solve it? Link to comment
LoPollo Posted January 18, 2017 Share Posted January 18, 2017 You said the gui shows up -> the meta.xml makes the script run in clientside, so the meta.xml is ok The problem is in the script: the easiest and fastest way to solve an issue is reading the errors a script produce. You can do this checking the log (since this script it's clientside you must check MTA San Andreas 1.5\MTA\logs\clientscript.log) or directly in-game using debugscript 3. So my question is: what's in these files? Look for lines like this: [date and time] [resourceName]\Spawn_Panel.lua:[Line of the error]: [error] 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