Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 11 hours ago, The_GTA said: Look at this post above: https://forum.multitheftauto.com/topic/132730-error-loading-script-failed-car_controlpanel03/?do=findComment&comment=1002018 But still the shutters open on guiclick is not working correctly. When i click gui shutters only open for me it do not show to other players. Why is that? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 (edited) Fix the server script this way: addEvent("onVehicleWindowOpenRequest", true); addEventHandler("onVehicleWindowOpenRequest", root, function(wndid) triggerClientEvent("open", client, wndid); end ); --- Your way of creating these errors is peculiar. Who even told you to use the onPlayerResourceStart event this way? Did somebody else teach you this? Please ask before you use new things that you do not understand. Scripting is not wizardry. Also, I do not like the way you just copy paste the code without thinking how to generalize it. For instance, you should not have created 4 copies of the exactly same event handler because one could do all of the tasks. I hope you will learn the way of code sharing in the future. I cannot teach you this because it takes spirit on your side to want to improve yourself which is not easy. Also you might have a longer path before yourself. Please mind yourself that this forum is about scripting help related to small questions as hints, not about creating the entire resource for you. Hopefully you understand and try to collect your mind on this issue. What have I showed you that you can already learn from? Take a breath, don't feel overburdened. This is a lot for the beginning but I hope you actually have learned something that sticks. Edited October 6, 2021 by The_GTA 1 Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 17 hours ago, The_GTA said: Your way of creating these errors is peculiar. Who even told you to use the onPlayerResourceStart event this way? Did somebody else teach you this? Please ask before you use new things that you do not understand. Scripting is not wizardry. No dude, No one taught me anything. Everything I know is learnt by me. That's why there are many problems in my scripts. Quote Also, I do not like the way you just copy paste the code without thinking how to generalize it. I'm sorry fot it dude and I will not do that again ever. Quote addEvent("onVehicleWindowOpenRequest", true); addEventHandler("onVehicleWindowOpenRequest", root, function(wndid) triggerClientEvent("open", client, wndid); end ); But still I don't understand what to do about this. Quote Are you telling me to change this Quote addEventHandler("onPlayerResourceStart", root, function () addEvent("onVehicleWindowOpenRequest", true); addEventHandler("onVehicleWindowOpenRequest", root, function(wndid) triggerClientEvent("open", client, wndid); end ); end) as Quote addEvent("onVehicleWindowOpenRequest", true); addEventHandler("onVehicleWindowOpenRequest", root, function(wndid) triggerClientEvent("open", client, wndid); end ); or something else????? -------- Are you thinking this script is more than enough as for the begining???? i'm sorry for interrupting you but I have many question to ask and I don't have anyone to ask all of them; Please help me. Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 7 minutes ago, Heshan_Shalinda_eUnlock said: Are you telling me to change this Yes, replace the script as you have written down. Quote Are you thinking this script is more than enough as for the begining???? i'm sorry for interrupting you but I have many question to ask and I don't have anyone to ask all of them; Please help me. Don't worry. I wanted to make you aware how important it is to think about oneself. You have asked the right question. I will help you finish this script. 1 Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 Just now, The_GTA said: Don't worry. I wanted to make you aware how important it is to think about oneself. You have asked the right question. I will help you finish this script. I know scripting is very hard to very new people like me that's why I'm asking from the known people like you to help me. And by the way thanks for teaching me many things. -------------------------------------------------- When I use this Quote -- CLIENT function changeSeat01() triggerServerEvent("changeSeat01", localPlayer) end addEventHandler("onClientGUIClick", GUIEditor.button[9], changeSeat01) -- SERVER function changeSeat01 ( ) thePed = client -- client is the player who triggered the serverside event/did the request theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then warpPedIntoVehicle ( thePed, theVehicle, 0 ) outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) else outputChatBox ( getPlayerName(thePed).." is not in a vehicle." ) end end addEvent ("changeSeat01", true) addEventHandler ("changeSeat01", root, changeSeat01) There is an error message called "attemp to call global 'client' <a userdata value> And why it shows that message dude? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 (edited) 5 minutes ago, Heshan_Shalinda_eUnlock said: When I use this There is an error message called "attemp to call global 'client' <a userdata value> And why it shows that message dude? You have omitted the line number and script filename from the error message. In the script excerpt there is no call to a global variable called "client". Could you please paste the entire error message? Best is a screenshot. I know it is annoying but you are making my life hard if you are leaving information out. Edited October 6, 2021 by The_GTA 1 Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 1 minute ago, The_GTA said: You have omitted the line number and script filename from the error message. In the script excerpt there is no call to a global variable called "client". Could you please paste the entire error message? Best is a screenshot. I know it is annoying but you are making my life hard if you are leaving information out. After replacing Quote this part Quote addEvent("onVehicleWindowOpenRequest", true); addEventHandler("onVehicleWindowOpenRequest", root, function(wndid) triggerClientEvent("open", client, wndid); end ); For this part Quote addEventHandler("onPlayerResourceStart", root, function () addEvent("onVehicleWindowOpenRequest", true); addEventHandler("onVehicleWindowOpenRequest", root, function(wndid) triggerClientEvent("open", client, wndid); end ); end) In my local server it shows a message, Quote Error : car_controlpanel03\ccp_s.lua:165: attempt to call global 'client' <a userdata value> And it is exactly this line Quote thePed = client() And this is full part Quote function changeSeat01 ( ) thePed = client() theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then warpPedIntoVehicle ( thePed, theVehicle, 0 ) outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) else outputChatBox ( getPlayerName(thePed).." is not in a vehicle." ) end end addEvent ("changeSeat01", true) addEventHandler ("changeSeat01", root, changeSeat01) Thanks Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 2 minutes ago, Heshan_Shalinda_eUnlock said: After replacing In my local server it shows a message, And it is exactly this line And this is full part Thanks thePed = client() Why is there a curly-brackets? 1 Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 6 minutes ago, The_GTA said: thePed = client() Why is there a curly-brackets? I'm so sorry for this inconvenience dude so sorry I'll create it and test it in my lemehost server then I'll tell you the result. But I still don't understand how to fix showGui on resource start I want to show the gui only on the vehicle not on the resource start how to fix it plz? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 2 minutes ago, Heshan_Shalinda_eUnlock said: I still don't understand how to fix showGui on resource start I want to show the gui only on the vehicle not on the resource start how to fix it plz? Please look at the following quote from me in a previous post. On 05/10/2021 at 08:39, The_GTA said: To force it into non-visible state, you have to call the guiackapa function with false as first argument, like this: guiackapa( false ) Use the function inside your login panel script to make any GUI non-visible that should not be visible while your login panel is. For example, force the vehicle UI non-visible each time you set the login UI as visible. Use the hint I gave you. If there is any event that your login system is firing when it shows the UI, like an "onClientShowLoginUI" event, then you can use an event handler and call the guiackapa function inside of it (recommended solution). Now tell me, is there a mechanism in your login system for that? Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 28 minutes ago, The_GTA said: Please look at the following quote from me in a previous post. Use the hint I gave you. If there is any event that your login system is firing when it shows the UI, like an "onClientShowLoginUI" event, then you can use an event handler and call the guiackapa function inside of it (recommended solution). Now tell me, is there a mechanism in your login system for that? I don't have any login system I want to make this resource as an independent resource because then I only have to give this to the owner of our server to put this his resources. Isn't there any way to use this without any resource or not using login Panel. Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 5 minutes ago, Heshan_Shalinda_eUnlock said: I don't have any login system I want to make this resource as an independent resource because then I only have to give this to the owner of our server to put this his resources. Isn't there any way to use this without any resource or not using login Panel. I was confused for a second because in a previous post you have said... Quote ... but I want to fix it showing on login to the server ... which made me assume that you have a login system. Sorry, it was a mistake on my part. Here is the solution. By default if you create windows using guiCreateWindow they are visible. You need to set them to invisible after creation to prevent that. GUIEditor.window[1] = guiCreateWindow(400, 500, 478, 216, "Car Control Panel", false) guiWindowSetSizable(GUIEditor.window[1], false) ... GUIEditor.button[15] = guiCreateButton(54, 27, 41, 39, "Shutter 02", false, GUIEditor.window[3]) GUIEditor.button[16] = guiCreateButton(10, 71, 40, 39, "Shutter 03", false, GUIEditor.window[3]) -- INSERT THIS CODE AFTER GUI CREATION for m,n in ipairs(GUIEditor.window) do guiSetVisible(n, false) end Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 11 minutes ago, Heshan_Shalinda_eUnlock said: I don't have any login system I want to make this resource as an independent resource because then I only have to give this to the owner of our server to put this his resources. Isn't there any way to use this without any resource or not using login Panel. There is a little problem in seat change if there are 2 players in the vehicle and if one player click gui button which is the position of the other player the player that player will be get off from the vehicle. ( The player who didn't uses the gui will be get off from the vehicle ) How to fix this need help.. Quote 4 minutes ago, The_GTA said: I was confused for a second because in a previous post you have said... which made me assume that you have a login system. Sorry, it was a mistake on my part. Here is the solution. By default if you create windows using guiCreateWindow they are visible. You need to set them to invisible after creation to prevent that. GUIEditor.window[1] = guiCreateWindow(400, 500, 478, 216, "Car Control Panel", false) guiWindowSetSizable(GUIEditor.window[1], false) ... GUIEditor.button[15] = guiCreateButton(54, 27, 41, 39, "Shutter 02", false, GUIEditor.window[3]) GUIEditor.button[16] = guiCreateButton(10, 71, 40, 39, "Shutter 03", false, GUIEditor.window[3]) -- INSERT THIS CODE AFTER GUI CREATION for m,n in ipairs(GUIEditor.window) do guiSetVisible(n, false) end Oh thank you so much for that it works very well. Then I can use this Quote -- INSERT THIS CODE AFTER GUI CREATION for m,n in ipairs(GUIEditor.window) do guiSetVisible(n, false) end For any GUI I make in the future to make it invisible and make a function like guiackapa to make it visible on pressing a bindkey. Am I correct?????????????????????? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 (edited) 14 minutes ago, Heshan_Shalinda_eUnlock said: There is a little problem in seat change if there are 2 players in the vehicle and if one player click gui button which is the position of the other player the player that player will be get off from the vehicle. ( The player who didn't uses the gui will be get off from the vehicle ) How to fix this need help.. Whenever you use warpPedIntoVehicle to set the occupant slot inside of a vehicle, you force the player who would be otherwise on that slot out of the vehicle. This is not a bug but intended behavior. You have to tell the MTA server to find another slot for any player whose slot should be removed from the vehicle. You need the following building blocks for this: a function to find a free vehicle slot inside of a vehicle (provided by me) the getVehicleOccupant function to see if there is a player sitting on a vehicle slot prior to calling warpPedIntoVehicle adjusting the seat change event handler logic to connect the building blocks: find a free vehicle slot after calling warpPedIntoVehicle and warp the ped whose slot was replaced into that free slot. Here is the function to find a free vehicle slot: function findFreeVehicleSlot(vehicle) local seat_count = 1 + getVehicleMaxPassengers( vehicle ) for slot_off=1,seat_count do local sitting_ped = getVehicleOccupant( vehicle, slot_off - 1 ) if (sitting_ped == false) then -- is no ped sitting on that slot? return slot_off - 1 -- return the free slot index end end -- There is no free slot so return false. return false end Hope this helps! Edited October 6, 2021 by The_GTA Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 Just now, The_GTA said: Whenever you use warpPedIntoVehicle to set the occupant slot inside of a vehicle, you force the player who would be otherwise on that slot out of the vehicle. This is not a bug but intended behavior. You have to tell the MTA server to find another slot for any player whose slot should be removed from the vehicle. You need the following building blocks for this: a function to find a free vehicle slot inside of a vehicle (provided by me) the getVehicleOccupant function to see if there is a player sitting on a vehicle slot prior to calling warpPedIntoVehicle adjusting the seat change event handler logic to connect the building blocks Here is the function to find a free vehicle slot: function findFreeVehicleSlot(vehicle) local seat_count = 1 + getVehicleMaxPassengers( vehicle ) for slot_off=1,seat_count do local sitting_ped = getVehicleOccupant( vehicle, slot_off - 1 ) if (sitting_ped == false) -- is no ped sitting on that slot? return slot_off - 1 -- return the free slot index end end -- There is no free slot so return false. return false end Hope this helps! Where should I use this As my knowledge I guess this must be in server side part Am I correct??????????????? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 16 minutes ago, Heshan_Shalinda_eUnlock said: Then I can use this For any GUI I make in the future to make it invisible and make a function like guiackapa to make it visible on pressing a bindkey. Am I correct?????????????????????? If you use the same old GUIEditor resource to make your GUI, then yes. Just now, Heshan_Shalinda_eUnlock said: Where should I use this As my knowledge I guess this must be in server side part Am I correct??????????????? Your guess is correct, because you want to warp players and players are serverside elements that are synchronized with clients. You have already put the seat change code on the serverside which was correct. So why not extend it? Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 2 minutes ago, The_GTA said: If you use the same old GUIEditor resource to make your GUI, then yes. Your guess is correct, because you want to warp players and players are serverside elements that are synchronized with clients. You have already put the seat change code on the serverside which was correct. So why not extend it? Ok I'll test it with my friend later but I have seen another fault that when I click empty space in a window without clicking any button all the functions attached to buttons will be done. For example If I click an empty space in car_contol_panel window there are many buttons for opening doors but then all the doors will be opened, and lights will be on and engine will be switched. Why is that explain me please Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 (edited) 14 minutes ago, Heshan_Shalinda_eUnlock said: Ok I'll test it with my friend later but I have seen another fault that when I click empty space in a window without clicking any button all the functions attached to buttons will be done. For example If I click an empty space in car_contol_panel window there are many buttons for opening doors but then all the doors will be opened, and lights will be on and engine will be switched. Why is that explain me please Whenever you fire an event inside of MTA it is propagated to its children and parents. This is done by design: you can reach every subscriber by triggering an event on the root element but you can limit yourself to possibly just one subscriber or the root if you trigger it on a specific element. Read up on the MTA event system here. Since there is no good illustration of the event propagation space, which you should always keep in mind, here is a mock-up made by me: As you see, since you clicked on window1, the event was pushed to button1, button2 and root aswell. On each button you have told the event handler by using the implicit parameter propagate = true to the addEventHandler call of the onClientGUIClick event that you want to trigger if even the window told you about it. So how do you prevent listening to clicks on windows? You can use... addEventHandler("onClientGUIClick", button, function() -- YOUR CODE HERE. end , false) to just listen to the click event on the button itself. You can easily adjust your previous code by adding a "false" parameter as fourth parameter to any addEventHandler call done based on your buttons. Hope this helps! Edited October 6, 2021 by The_GTA Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 46 minutes ago, The_GTA said: Whenever you use warpPedIntoVehicle to set the occupant slot inside of a vehicle, you force the player who would be otherwise on that slot out of the vehicle. This is not a bug but intended behavior. You have to tell the MTA server to find another slot for any player whose slot should be removed from the vehicle. You need the following building blocks for this: a function to find a free vehicle slot inside of a vehicle (provided by me) the getVehicleOccupant function to see if there is a player sitting on a vehicle slot prior to calling warpPedIntoVehicle adjusting the seat change event handler logic to connect the building blocks: find a free vehicle slot after calling warpPedIntoVehicle and warp the ped whose slot was replaced into that free slot. Here is the function to find a free vehicle slot: function findFreeVehicleSlot(vehicle) local seat_count = 1 + getVehicleMaxPassengers( vehicle ) for slot_off=1,seat_count do local sitting_ped = getVehicleOccupant( vehicle, slot_off - 1 ) if (sitting_ped == false) then -- is no ped sitting on that slot? return slot_off - 1 -- return the free slot index end end -- There is no free slot so return false. return false end Hope this helps! I have tested this function but it does not work because the same old problem takes place in this scenario. I don't know how to fix there isn't any error message in the console but when I change seat other player in the seat will be gets off automatically. Need help fixing. thanks Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 1 minute ago, Heshan_Shalinda_eUnlock said: I have tested this function but it does not work because the same old problem takes place in this scenario. I don't know how to fix there isn't any error message in the console but when I change seat other player in the seat will be gets off automatically. Need help fixing. thanks If you are claiming that my function does not work, then I would like to see how my function is being used by you. Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 Just now, The_GTA said: If you are claiming that my function does not work, then I would like to see how my function is being used by you. Quote function findFreeVehicleSlot(vehicle) local seat_count = 1 + getVehicleMaxPassengers( vehicle ) for slot_off=1,seat_count do local sitting_ped = getVehicleOccupant( vehicle, slot_off - 1 ) if (sitting_ped == false) then-- is no ped sitting on that slot? return slot_off - 1 -- return the free slot index end end -- There is no free slot so return false. return false end function changeSeat01 ( ) thePed = client theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then warpPedIntoVehicle ( thePed, theVehicle, 0 ) outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) end end addEvent ("changeSeat01", true) addEventHandler ("changeSeat01", root, changeSeat01) I have used it alone Shouldn't I do that? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 Just now, Heshan_Shalinda_eUnlock said: I have used it alone Shouldn't I do that? No. Read again points number two and three: 1 hour ago, The_GTA said: a function to find a free vehicle slot inside of a vehicle (provided by me) the getVehicleOccupant function to see if there is a player sitting on a vehicle slot prior to calling warpPedIntoVehicle adjusting the seat change event handler logic to connect the building blocks: find a free vehicle slot after calling warpPedIntoVehicle and warp the ped whose slot was replaced into that free slot. I would like you to change the changeSeat... family of functions yourself. After your attempt, I will help you. Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 19 minutes ago, The_GTA said: No. Read again points number two and three: I would like you to change the changeSeat... family of functions yourself. After your attempt, I will help you. I have used it as this but I don't have another person to check this so tell me is this correct? Quote function findFreeVehicleSlot(vehicle) local seat_count = 1 + getVehicleMaxPassengers( vehicle ) for slot_off=0,seat_count do local sitting_ped = getVehicleOccupant( vehicle, slot_off - 1 ) if (sitting_ped == false) then -- is no ped sitting on that slot? return slot_off - 1 -- return the free slot index end end -- There is no free slot so return false. return false end addEvent("findFreeVehicleSlot", true) addEventHandler("findFreeVehicleSlot", root, findFreeVehicleSlot) function changeSeat01 ( ) thePed = client theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then warpPedIntoVehicle ( thePed, theVehicle, 0 ) outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) end end addEvent ("changeSeat01", true) addEventHandler ("changeSeat01", root, changeSeat01) Is this Correct??? Link to comment
The_GTA Posted October 6, 2021 Share Posted October 6, 2021 1 minute ago, Heshan_Shalinda_eUnlock said: I have used it as this but I don't have another person to check this so tell me is this correct? Is this Correct??? Unfortunately, this is not correct. I have told you to change the inside operations of the changeSeat01 function. You have not changed a single line of that function. Could you try to do it? Change this function only: function changeSeat01 ( ) thePed = client theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then -- PUT CODE TO FIND OCCUPANT AT SLOT 0 HERE warpPedIntoVehicle ( thePed, theVehicle, 0 ) -- PUT CODE TO WARP PREVIOUS OCCUPANT INTO FREE SLOT HERE outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) end end Maybe my green comment hints will help you solve this task. Link to comment
Heshan_Shalinda_eUnlock Posted October 6, 2021 Author Share Posted October 6, 2021 6 minutes ago, The_GTA said: Unfortunately, this is not correct. I have told you to change the inside operations of the changeSeat01 function. You have not changed a single line of that function. Could you try to do it? Change this function only: function changeSeat01 ( ) thePed = client theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then -- PUT CODE TO FIND OCCUPANT AT SLOT 0 HERE warpPedIntoVehicle ( thePed, theVehicle, 0 ) -- PUT CODE TO WARP PREVIOUS OCCUPANT INTO FREE SLOT HERE outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) end end Maybe my green comment hints will help you solve this task. Is this Correct dude Quote function findFreeVehicleSlot(vehicle) local seat_count = 1 + getVehicleMaxPassengers( vehicle ) for slot_off=0,seat_count do local sitting_ped = getVehicleOccupant( vehicle, slot_off - 1 ) if (sitting_ped == false) then -- is no ped sitting on that slot? return slot_off - 1 -- return the free slot index end end -- There is no free slot so return false. return false end addEvent("findFreeVehicleSlot", true) addEventHandler("findFreeVehicleSlot", root, findFreeVehicleSlot) function changeSeat01 ( ) thePed = client theVehicle = getPedOccupiedVehicle ( thePed ) if ( theVehicle ) then local sitting_ped = getVehicleOccupant( theVehicle, slot_off - 1 ) warpPedIntoVehicle ( thePed, theVehicle, 0 ) if (sitting_ped == false) then return slot_off - 1 end outputChatBox ( getPlayerName(thePed).." is in a vehicle in seat number " .. getPedOccupiedVehicleSeat ( thePed ) .. "." ) end end addEvent ("changeSeat01", true) addEventHandler ("changeSeat01", root, changeSeat01) I think this is good you are teaching me lot........ 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