xbenny2506x Posted June 11, 2009 Share Posted June 11, 2009 I have make with the "Guieditor" a nice menu But now i need help, i have the code for the menu: GUIEditor_Window = {} GUIEditor_Grid = {} GUIEditor_Window[1] = guiCreateWindow(509,297,437,286,"Teleport Menu",false) GUIEditor_Grid[1] = guiCreateGridList(0.0503,0.1678,0.4096,0.7378,true,GUIEditor_Window[1]) guiGridListSetSelectionMode(GUIEditor_Grid[1],2) for i = 1, 2 do guiGridListAddRow(GUIEditor_Grid[1]) end guiGridListAddColumn(GUIEditor_Grid[1],"Jumps",0.2) GUIEditor_Grid[2] = guiCreateGridList(0.5217,0.1713,0.4096,0.7378,true,GUIEditor_Window[1]) guiGridListSetSelectionMode(GUIEditor_Grid[2],2) for i = 1, 2 do guiGridListAddRow(GUIEditor_Grid[2]) end guiGridListAddColumn(GUIEditor_Grid[2],"Others",0.2) I work hard on a nice stunt server, i have a lot nice maps, many teleport points so i have create this menu. So that the player see all teleport points and when he click on it, he teleport to this point. For that i have a very nice script that work only with commands in the chat, but i have so many that i need a menu. Here is the teleport script atm: function hjwarp (player) if isPlayerInVehicle(player) then -- If the player is in a vehicle... local vehicle=getPlayerOccupiedVehicle(player) -- Obtain the vehicle the player is in if getVehicleController(vehicle)==player then -- If the player is the driver... setElementPosition (vehicle , 886.24, 2479.17, 258.32 ) -- Warp the vehicle outputChatBox ( "You're warped to High Jump hj!", player, 0, 255, 0 ) end else -- If the player isn't in a vehicle... setElementPosition (player , 886.24, 2479.17, 258.32 ) -- Warp the player outputChatBox ( "You're warped to High Jump hj!", player, 0, 255, 0 ) end end addCommandHandler ( "hj", hjwarp ) A menu is better and easier as all the time the /commands... With F1 the ülayer can start the menu... I dont know how i can do this all Its the last thing for my server since many days i read and read but i need now help with this last thing for my server! I hope somone can help me with the menu 1000000 THX Link to comment
50p Posted June 11, 2009 Share Posted June 11, 2009 First thing you need to know is that GUI is client-side and you need to set players'/vehicles' position server-side. So, you need to tell the server you want to teleport player to different position. You should start with a few buttons, and than try GridList, because GridList requires more skill than simple button. So try this: (client-side) addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), function( ) wnd = guiCreateWindow( 509,297,437,286,"Teleport Menu",false ); location1 = guiCreateButton( 10, 20, 100, 19, "Location 1", false, wnd ); addEventHandler( "onClientGUIClick", location1, teleportTo, false ); location2 = guiCreateButton( 10, 40, 100, 19, "Location 2", false, wnd ); addEventHandler( "onClientGUIClick", location1, teleportTo, false ); end ) function teleportTo( ) -- here you will send text from button to the server, -- so you know which location you want to spawn triggerServerEvent( "YOUR_CUSTOM_EVENT", getLocalPlayer( ), guiGetText( source ) ); end (server-side) LOCATIONS = { }; -- Add your locations here, -- text between [ and ] MUST be the same as on the buttons -- because client will send text from the buttons: LOCATIONS[ "Location 1" ] = { 886.24, 2479.17, 258.32 }; LOCATIONS[ "Location 2" ] = { 886.24, 2479.17, 258.32 }; addEvent( "YOUR_CUSTOM_EVENT", true ); addEventHandler( "YOUR_CUSTOM_EVENT", getRootElement( ), function( locationName ) if LOCATIONS[ locationName ] then local veh = getPlayerOccupiedVehicle( client ); if client == getVehicleOccupant( veh ) then setElementPosition( veh, unpack( LOCATIONS[ locationName ] ) ); end end end ) This was written in the browser, not tested, so it MAY NOT work. Link to comment
xbenny2506x Posted June 11, 2009 Author Share Posted June 11, 2009 omg you are nice my hero the script work when the player is in a vehicle but not when he is not in a vehicle Can you help me there too?? the menu start when the player join is there a way that the menu start when the player press "F1"? i hope you can help me with that too!!!! BIG BIG BIG THX!!!! Here is the error code: [00:05:09] WARNING: menu_server.lua: Bad argument @ 'getVehicleOccupant' - Line: 13 [00:05:13] WARNING: menu_server.lua: Bad argument @ 'getVehicleOccupant' - Line: 13 [00:05:13] WARNING: menu_server.lua: Bad argument @ 'getVehicleOccupant' - Line: 13 [00:05:13] WARNING: menu_server.lua: Bad argument @ 'getVehicleOccupant' - Line: 13 [00:05:37] WARNING: menu_server.lua: Bad argument @ 'getVehicleOccupant' - Line: 13 [00:05:50] WARNING: menu_server.lua: Bad argument @ 'getVehicleOccupant' - Line: 13 [00:06:19] QUIT: Benny left the game [Quit] Link to comment
50p Posted June 11, 2009 Share Posted June 11, 2009 Server-side file: LOCATIONS = { }; -- Add your locations here, -- text between [ and ] MUST be the same as on the buttons -- because client will send text from the buttons: LOCATIONS[ "Location 1" ] = { 886.24, 2479.17, 258.32 }; LOCATIONS[ "Location 2" ] = { 886.24, 2479.17, 258.32 }; addEvent( "YOUR_CUSTOM_EVENT", true ); addEventHandler( "YOUR_CUSTOM_EVENT", getRootElement( ), function( locationName ) if LOCATIONS[ locationName ] then local veh = getPlayerOccupiedVehicle( client ); -- if you don't want to use the 'if' 'else' than you should be able to get the same effect with only one line: -- setElementPosition( ( ( veh and getVehicleOccupant( veh ) == client) and veh or client ), unpack( LOCATION[ locationName ] ) ); -- because you use the same coords for player or vehicle and you use one of them, you can try with the line above... if ( ( veh ) and ( client == getVehicleOccupant( veh ) ) then setElementPosition( veh, unpack( LOCATIONS[ locationName ] ) ); else setElementPosition( client, unpack( LOCATIONS[ locatioName ] ) ); end end end ) Client-side file: addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), function( ) wnd = guiCreateWindow( 509,297,437,286,"Teleport Menu",false ); location1 = guiCreateButton( 10, 20, 100, 19, "Location 1", false, wnd ); addEventHandler( "onClientGUIClick", location1, teleportTo, false ); location2 = guiCreateButton( 10, 40, 100, 19, "Location 2", false, wnd ); addEventHandler( "onClientGUIClick", location1, teleportTo, false ); guiSetVisible( wnd, false ) -- hide the window when resource started and created the window bindKey( "F1", "down", function( ) -- bind the key F1, show/hide window when it's pressed: if wnd then guiSetVisible( wnd, not guiGetVisible( wnd ) ) end end ) end ) function teleportTo( ) -- here you will send text from button to the server, -- so you know which location you want to spawn triggerServerEvent( "YOUR_CUSTOM_EVENT", getLocalPlayer( ), guiGetText( source ) ); end If it still doesn't work, try to fix it yourself. Just try to understand what "warning" and "error" messages tell you and fix it. Link to comment
xbenny2506x Posted June 12, 2009 Author Share Posted June 12, 2009 BIG BIG BIG THX!!! I had a little error but i fix it! My last question is, when i start the menu, how i start the mouse cursor so that the people can use the button? BIG BIG THX for the help!!!!! Link to comment
DakiLLa Posted June 12, 2009 Share Posted June 12, 2009 you can put this in 'onClientResourceStart' event: bindKey( "lalt", "down", function () showCursor( not isCursorShowing() ) end ) when you ingame, press left alt to show cursor and press left alt again to hide cursor Link to comment
50p Posted June 12, 2009 Share Posted June 12, 2009 You should paste this: showCursor( not isCursorShowing() ) in the F1 bind function, so when you press F1 to show the window, showCursor at the same time (just like console works). Link to comment
DakiLLa Posted June 13, 2009 Share Posted June 13, 2009 so when you press F1 to show the window, showCursor at the same time (just like console works). ah, ye, true, would be better... Link to comment
xbenny2506x Posted July 25, 2009 Author Share Posted July 25, 2009 Now i have a other problem... I have some DM areas and i want that the player cant teleport with a vehicle in the DM Teleport points. Can me someone say how i can do this? Client: addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), function( ) wnd = guiCreateWindow( 311,101,1044,804,"Teleport Menu",false ); .... location9 = guiCreateButton( 370, 170, 140, 30, "Halfpipe", false, wnd ); addEventHandler( "onClientGUIClick", location9, teleportTo, false ); location6 = guiCreateButton( 370, 210, 140, 30, "Looping", false, wnd ); addEventHandler( "onClientGUIClick", location6, teleportTo, false ); location11 = guiCreateButton( 370, 250, 140, 30, "DM Test 1", false, wnd ); addEventHandler( "onClientGUIClick", location11, teleportTo, false ); location13 = guiCreateButton( 370, 350, 140, 30, "DM Test 2", false, wnd ); addEventHandler( "onClientGUIClick", location13, teleportTo, false ); guiSetVisible( wnd, false ) -- hide the window when resource started and created the window bindKey( "F1", "down", function( ) -- bind the key F1, show/hide window when it's pressed: if wnd then guiSetVisible( wnd, not guiGetVisible( wnd ) ) end end ) end ) function teleportTo( ) -- here you will send text from button to the server, -- so you know which location you want to spawn triggerServerEvent( "YOUR_CUSTOM_EVENT", getLocalPlayer( ), guiGetText( source ) ); end bindKey( "F1", "down", function () showCursor( not isCursorShowing() ) end ) Server: LOCATIONS = { }; -- Add your locations here, -- text between [ and ] MUST be the same as on the buttons -- because client will send text from the buttons: LOCATIONS[ "Looping" ] = { 1696.9108886719, -1257.9813232422, 362.45672607422 }; LOCATIONS[ "Halfpipe" ] = { 2857.1716308594, -1961.9986572266, 11.400349617004 }; LOCATIONS[ "Trampoline" ] = { -3915.4597167969, -990.92761230469, 177.80200195313 }; LOCATIONS[ "DM Test 1" ] = { -2634.2856445313, 1349.6235351563, 7.1194381713867 }; LOCATIONS[ "DM Test 2" ] = { 1442.970, -1718.917, 16 }; addEvent( "YOUR_CUSTOM_EVENT", true ); addEventHandler( "YOUR_CUSTOM_EVENT", getRootElement( ), function( locationName ) if LOCATIONS[ locationName ] then local veh = getPlayerOccupiedVehicle( client ); if ( ( veh ) and ( client == getVehicleOccupant( veh ) ) ) then setVehicleFrozen(veh, true) setElementPosition( veh, unpack( LOCATIONS[ locationName ] ) ); setTimer(setVehicleFrozen, 200, 1, veh, false) else setElementPosition( client, unpack( LOCATIONS[ locationName ] ) ); end end end ) Link to comment
xbenny2506x Posted July 25, 2009 Author Share Posted July 25, 2009 removePlayerFromVehicle is not bad... But the vehicle is the then in the DM zone, that is not so good And now i have 2 problems first the vehicle not teleport in the DM zone and i have a DM zone in a house, but the teleport point in the house not working. The player fall down in the middle of nowhere Now i need really help PLZ!!!! Link to comment
eAi Posted July 25, 2009 Share Posted July 25, 2009 I'd suggest storing teleport points in map files - that's the point of map files - storing positions. Link to comment
xbenny2506x Posted July 25, 2009 Author Share Posted July 25, 2009 This script from 50p is very very nice only i have this 2 problems... I need so a nice Teleport menu for my server... I have many nice teleport places and nice maps, DM areas... and more. And this teleport menu is perfect for my server. So i hope 50p and help me there too. And all others can see this here too, this menu is perfect for a stunt server! Link to comment
50p Posted July 25, 2009 Share Posted July 25, 2009 You must first understand how scripts work and how to use functions, xbenny2506x. From what I see you haven't changed the script too much and therefore haven't learnt anything at all. I replied to your PM and you have the same answer here because that's what you need... removePlayerFromVehicle or removePedFromVehicle (for nightly builds). Link to comment
xbenny2506x Posted July 27, 2009 Author Share Posted July 27, 2009 I have understand your script to 80%... For the vehicle teleport problem i found a way. And for the teleport in interior i have found getElementInterior and setElementInterior. It was not easy really not easy but now i check from where comes the player interior 1 2 3 ... and set him then back to 0 so that he can play normal with ">=" or back to 1 2 3... and many other checks Perfect is my script not lol I am sure it gives a easier way, i have seen many same things like in PHP, but is a long time ago that i have work with PHP... 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