
pa3ck
Members-
Posts
1,141 -
Joined
-
Last visited
-
Days Won
7
Everything posted by pa3ck
-
I know you are new to scripting and you can always come to these forums for help, but before asking for help, you should try to solve it your own. There are number of ways you can debug your code, if you look at IIYAMA's tutorial here: Or the debug page on wiki here: https://wiki.multitheftauto.com/wiki/Debugging The reason why I'm saying this, is because the problem with your code is so obvious, you could have spotted yourself if you knew how to debug. Don't take this as on offence. Just to show you how easily you could have fixed it yourself (even just by looking at it): function destroyHydraGun -- missing ( ) after function declaration local vehicle = getPedOccupiedVehicle(localPlayer) if(vehicle)then if getElementModel(vehicle) == 520 then local attached = getElementAttachedTo (vehicle) if ( attached ) then destroyElement ( weapon ) end -- missing end -- missing end end When you run this code, you would have gotten all sorts of errors in your debugscript.
-
If its related to your main problem you can post it here, create a new one otherwise.
-
Button is the function that creates the GUI. If you don't call it, the GUI won't be created. You said the problem was at the eventHandler not with the guiSetVisible, what is the exact error you are getting and at which line?
-
Well I have no idea how you got that error, because the 2nd argument is clearly resourceRoot which is definitely not nil. You shouldn't set the 4th argument in addEventHandler to false and you never actually hide the window. guiGetVisible =/= guiSetVisible, guiGetVisible returns true/false, does not do anything. This one works: Confirmation = { button = {}, } function button () Confirmation.window = guiCreateWindow(699, 412, 328, 164, "Car Shop", false) Confirmation.button.no = guiCreateButton(195, 104, 85, 31, "No", false, Confirmation.window) end function cancel () if source == Confirmation.button.no then guiSetVisible (Confirmation.window, false) end end button() addEventHandler ("onClientGUIClick", root, cancel)
-
See the second argument of the event handler is a GUI element, it doesn't refer to a variable, but an element. In other words, when the addEventHandler executes and the button is not created yet, it will not work. Try this: Confirmation = { button = {}, } function button () Confirmation.window = guiCreateWindow(699, 412, 328, 164, "Car Shop", false) Confirmation.button.no = guiCreateButton(195, 104, 85, 31, "No", false, Confirmation.window) end function cancel () -- check which GUI was clicked if source == Confirmation.button.no then -- 'source' is a variable that is always present in this event and it is the GUI element that was clicked guiGetVisible (Confirmation.window, false) end end addEventHandler ("onClientGUIClick", resourceRoot, cancel, false ) -- every GUI that is being clicked in the resourceRoot
-
You can create it anywhere as long as 1. you are sure when it triggers, the button exists 2. it has access to the variable for that given button
-
addEventHandler("onClientGUIClick", resourceRoot, function(btn, state) --[[ Variable btn, state | If you go to the wiki (wiki.multitheftauto.com), you can see the list of parameters being passed to this function You don't have to put them all in, but if you will need to use them, you will want to put them in You can give them any name you want, but the order cannot be changed, every single parameter is explained on the wiki page btn -> ' the name of the button which will be clicked , it can be left, right, middle ' --> basically which mouse button was pressed state -> ' the state of the mouse button, will be down if the mouse button was pushed, or up if it was released. ' --> state of the pressed key (only 'up' is functional ATM) If you look at this event on the wiki (https://wiki.multitheftauto.com/wiki/OnClientGUIClick), you will see there are more parameters, but we don't need them, therefore I didn't put them ]] if btn == "left" and state == "up" then -- so if the user clicked the left mouse button and released it --[[ Again, the wiki says (wiki.multitheftauto.com/wiki/GuiGridListGetSelectedItem) that this function has 2 return values ' Returns the row and column indexes of the selected item if the specified grid list is valid and has a selected item, (-1, -1) if no item is selected, false otherwise. ' (quoted from wiki ) ]] local selRow, selInd = guiGridListGetSelectedItem(Carshop.gridlist[1]) -- as explained above, if nothing is selected, this will return -1 if( selRow ~= -1 ) then -- check if it's not -1 (if it's not, it means something is selected) guiSetEnabled( YOUR_GUI_BUTTON, true) -- enable the button, we know for fact that something is selected else guiSetEnabled( YOUR_GUI_BUTTON, false) -- disable the button, we know for fact that nothing is selected end end end) Hope you understood everything, if not, don't be shy to ask for further help.
-
You will need to attach your function to an event like onClientGUIClick like: addEventHandler("onClientGUIClick", resourceRoot, function(btn, state) if btn == "left" and state == "up" then local selRow, selInd = guiGridListGetSelectedItem(Carshop.gridlist[1]) if( selRow ~= -1 ) then guiSetEnabled( YOUR_GUI_BUTTON, true) else guiSetEnabled( YOUR_GUI_BUTTON, false) end end end) Make sure you disable the button when creating it so it will be enabled by the script when the user clicks a row
-
That's because of the scope of the variable "carListRow". You declared it in the first loop as a local variable, that means it will only be available in that loop. When you add a new row, you can update the name and the price at the same time. Try this: VehiclesNames = { silvia_s15 = {"Nissan Silvia S15", 40000}, sx240 = {"Nissan 240SX", 12000}, supra_mk4 = {"Toyota Supra MK4", 60000}, skyline_r32 = {"Nissan Skyline R32", 35000}, skyline_r34 = {"Nissan Skyline R34", 60000}, } function createVehicleList () Carshop.gridlist[1] = guiCreateGridList(24, 37, 465, 397, false, Carshop.window) Carshop.column[1] = guiGridListAddColumn(Carshop.gridlist[1], "Vehicle", 0.5) Carshop.column[2] = guiGridListAddColumn(Carshop.gridlist[1], "Price", 0.2) if ( Carshop.column[1] ) then for a, b in pairs( VehiclesNames ) do local carName = b[1] -- the first value is the name local carPrice = b[2] -- the second value is the price local carListRow = guiGridListAddRow ( Carshop.gridlist[1] ) guiGridListSetItemText ( Carshop.gridlist[1], carListRow, Carshop.column[1], carName , false, false ) guiGridListSetItemText ( Carshop.gridlist[1], carListRow, Carshop.column[2], carPrice , false, false ) end end end
-
Is that your full code (the one you posted)? If so, you never attached that function to an eventHandler. How would MTA know, you want that piece of code to run when the player enters a hydra?
-
Because the function is inside the (), if you close the () before closing off the function, it will complain about syntax error, it just won't go further on searching for the first end. That is LUA syntax and cannot be changed in any way.
-
Oh, okay, I haven't used files that much in MTA, but if you remove the fileSetPos @line 10 will it remove everything in the file? If so, you can do what @Necktrox said, load in everything from the file and append it after your new text.
-
This is a client-side script, make sure you set the type="client" in your meta.xml
-
Is there a specific position you will want to insert the new text or always before the old text, like [old_line1][old_line2] [ NEW LINE ] [old_line3] -> specific Or always before everything else? [NEW LINE][old_line1][old_line2] -> always there
-
That doesn't make sense, you are trying to disable the collision for player1 with player1. What I would do is: local colsEnabled = true addEventHandler( "onClientElementStreamIn", getRootElement( ), function ( ) if getElementType( source ) == "player" and not colsEnabled then setElementCollidableWith(localPlayer, source, false) end end ) function toggleCollisionsForPlayer(p, enabled) for k, v in ipairs(getElementsByType("player")) do setElementCollidableWith(p, v, enabled) end end addCommandHandler("toggle_col", function() toggleCollisionsForPlayer(localPlayer, not colsEnabled) colsEnabled = not colsEnabled end) Not tested, but should work. Basically when you enter "/toggle_col", if it is enabled, it calls toggleCollisionsForPlayer that will loop thru each player and disable the collisions between them. But if a player connects to the server, the collision with that player will still be enabled, that is why I added the event onClientElementStreamIn. When that event runs, it checks if the colsEnabled = false (so collisions are disabled) and disables the collision with the source element (the element that got streamed in)
-
No, that is not how it works. getPedArmor is a function that need arguments, you can't just compare it to other values like that. I suggest you to go and check out this topic: And this section: https://forum.multitheftauto.com/forum/123-tutorials/
-
Is amount defined anywhere?
-
function setPlayersArmor(p, cmd) if ( getPedArmor(p) < 100 ) then setPedArmor(p, 100) outputChatBox("Your armor was restored", p) end end addCommandHandler("setarmor", setPlayersArmor) You can do all of this server side, there's no need to trigger from the client.
-
That's not possible, you are definitely getting errors... You have this: setPedArmor( 0, player ) setPedArmor takes a player element first. So you are getting element expected, got number error. player is not defined in your code. When triggering from client to server and localPlayer is the source element, you can use 'client' variable server side to get the player element. triggerServerEvent("setdaarmor",true) You should use the wiki if you are new to scripting, triggerServerEvent takes an element as the 2nd argument, not a boolean. Try to look at wiki examples, they should help you out.
-
function storeArmor ( ) -> your function name addCommandHandler ( "storearmor", showArmor ) -> your commandHandler should be addCommandHandler ( "storearmor", storeArmor)
-
Because it gets enabled again in the map start event. You can find that event and remove the code that enables it again, or have a timer that runs every 2<->5 seconds and disables it, first option is probably better.
-
You already script in LUA, using SQL is waaaay easier. You should try to learn MySQL, believe me when I say it is not hard. You only need to understand couple of SQL commands like SELECT, INSERT, UPDATE, DELETE and that's basically it, if you know these, you know SQL. You don't need to create tables with commands, you can just use phpMyAdmin. Have you looked at any tutorials? I learnt SQL on w3schools, but if there are no proper tutorials on the MTA forums, I will make a tutorial video myself this weekend.