Guest Posted February 7, 2009 Share Posted February 7, 2009 Hi, I am hoping that it would be possible to take just the vehicle menu from freeroam (https://community.multitheftauto.com/index.php?p= ... ails&id=43) and put it as a resource on my server for a different gamemode - is this possible? if so can anybody help? Thanks Link to comment
Gamesnert Posted February 7, 2009 Share Posted February 7, 2009 Guide on doing this on your own: Way 1: The friendliest way: Try to remake it in this way: GUI tutorial, GUI classes resource and GUI scripting functions. Way 2: The lessfriendlybutstillquitefriendly way: Look up in the resource what you need and type it over, for better understanding. Way 3: The notsofriendly way: Copy it. ------------------------------------------- And to remember: We're not here to chew food for you to swallow. You need to start chewing it, and we might help chewing. (sounds pretty grouse though... ) Link to comment
Guest Posted February 7, 2009 Share Posted February 7, 2009 That's the problem I don't know what I need to do #1 or #2 and #3 will just make it a gamemode. ARGH. Link to comment
Gamesnert Posted February 7, 2009 Share Posted February 7, 2009 That's the problem I don't know what I need to do #1 or #2 and #3 will just make it a gamemode.ARGH. Have you read THIS and THIS? Because as far as I can understand your post, you don't know how to script. Am I right? Link to comment
Guest Posted February 7, 2009 Share Posted February 7, 2009 Yep, I can't script to save my life. I'm not sure why that first link is useful but the second would be.... if I could actually learn and pick up stuff although I'm not really willing to - I just want to have some fun. So far I've come up with this... addEventHandler('onClientResourceStart', g_ResRoot, function() bindKey('f1', 'down', toggleFRWindow) createWindow(wndCreateVehicle) --hideAllWindows() end ) function toggleFRWindow() if isWindowOpen(wndCreateVehicle) then showCursor(false) hideAllWindows() else showCursor(true) showAllWindows() end end wndCreateVehicle = { 'wnd', text = 'Create vehicle', width = 300, controls = { { 'lst', id='vehicles', width=280, height=340, columns={ {text='Vehicle', attr='name'} }, rows={xml='vehicles.xml', attrs={'id', 'name'}}, onitemdoubleclick=createSelectedVehicle }, {'btn', id='create', onclick=createSelectedVehicle}, {'btn', id='close', closeswindow=true} } } function createSelectedVehicle(leaf) if not leaf then leaf = getSelectedGridListLeaf(wndCreateVehicle, 'vehicles') if not leaf then return end end server.giveMeVehicles(leaf.id) end function createVehicleCommand(cmd, ...) local vehID local vehiclesToCreate = {} local args = { ... } for i,vehID in ipairs(args) do vehID = tonumber(args[i]) if not vehID then vehID = getVehicleIDFromName(args[i]) end if vehID then table.insert(vehiclesToCreate, vehID) end end server.giveMeVehicles(vehiclesToCreate) end addCommandHandler('createvehicle', createVehicleCommand) addCommandHandler('cv', createVehicleCommand) Who the hell knows if it's right. Edit: All I want is a menu that opens and closes by pressing F1 to let people spawn a vehicle from a list. Link to comment
50p Posted February 7, 2009 Share Posted February 7, 2009 This is a very simple script (not exactly the same as the one in freeroam) made with GUI Classes. To make it work, just download those classes and replace what's inside "test.lua" with this: addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), function( ) local screenSize = { guiGetScreenSize( ) } local numberOfVehicles = 212; -- there is 212 vehicles in GTA (inc. trailers) local gridList = GridList:Create( screenSize[ 1 ] - 210, screenSize[ 2 ] / 2 - 200, 200, 400 ); gridList:Visible( false ); gridList:AddColumn( "ID", .22 ); gridList:AddColumn( "Name", .6 ); for i = 0, numberOfVehicles do local tempID = i + 400; -- first vehicle ID is 400 (Landstalker) local vehName = getVehicleNameFromID( tempID ); gridList:AddRow( tostring( tempID ), vehName ); end gridList:AddOnClick( -- when you click the gridlist a car will be created function( ) local x, y, z = getElementPosition( getLocalPlayer( ) ); local rowID = gridList:SelectedItem(); createVehicle( tonumber( gridList:ItemText( rowID, 1 ) ), x + 5, y, z ); -- CREATE VEHICLES SERVER-SIDE TO BE ABLE TO ENTER THEM! end ); bindKey( "F1", "down", function( ) showCursor( not isCursorShowing( ) ); gridList:Visible( not gridList:Visible() ); end ); end ) NOTE: THIS CREATES VEHICLES CLIENT-SIDE. YOU CANNOT ENTER VEHICLES CREATED CLIENT-SIDE! Maybe someone here will make another piece of code for you that creates the cars server-side... It's just a few more lines of code. Link to comment
Guest Posted February 7, 2009 Share Posted February 7, 2009 Wow - thank you! That is very good and close to what I was looking for. Is it possible to have the cursor on when the menu is available? And server side use would be muchly appreciated if someone could chip in. Link to comment
50p Posted February 8, 2009 Share Posted February 8, 2009 OK, as I said it's not long code so I can do it... I always say "I was born to help other people", but some people are so lazy that I don't even want to help them... Here, make a new file and paste this code into it: addEvent( "test_ClientCreateVehicle", true ) addEventHandler( "test_ClientCreateVehicle", getResourceRootElement( getThisResource() ), function( vehID ) --"client" is a hidden player that triggered server side event local x, y, z = getElementPosition( client ); -- here's the client createVehicle( vehID, x + 5, y, z ); end ) Add new line to meta.xml: <script src="THE_FILE_NAME_YOU_JUST_CREATED.lua" /> And change line where you created car client-side with this: triggerServerEvent( "test_ClientCreateVehicle", getRootElement(), tonumber( gridList:ItemText( rowID, 1 ) ) ); That's all you need. Basically, when you used addEvent() in server-side script you will have a new event that client can trigger and send some data... What you wanted to do was create a car server-side, right? Right, so, you just send an id of the vehicle you want to create (which is taken from the Grid List) and create it with createVehicle(). If you want to know more (it will be useful in the future if you want to extend server's gameplay) about events go to: http://development.mtasa.com/index.php? ... ent_system Link to comment
Guest Posted February 8, 2009 Share Posted February 8, 2009 Thanks alot for all the time and effort you put into this, it works brilliantly (using admin panel to bypass the following) EXCEPT a cursor doesn't appear when the menu is open, and only appears when it is closed - meaning you can't play the game or select a vehicle! EDIT: Fixed. Replaced gridlist statement with gridList:Visible ( isCursorShowing() ) 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