Ekko Posted November 1, 2018 Share Posted November 1, 2018 local siren = false function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) if isPedInVehicle(player) then if id == 560 then if siren == false then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) siren = true elseif siren == true then local attachedElements = getAttachedElements (vehicle) for i,v in ipairs (attachedElements) do detachElements (v, vehicle) siren = false end end end end end addCommandHandler("taxion",undercover) Hello basically this script attach taxi sing in vehicle ID 560 but the problem just one can use it in the server pls help me , make it many players can use it Link to comment
Moderators IIYAMA Posted November 1, 2018 Moderators Share Posted November 1, 2018 (edited) A very quick and basic solution, would be: local siren = #getAttachedElements (vehicle) > 0 Place it where you think it would make sense in your code. And if you do not know where to place it, you can always try it at all 24 lines till the code finally does what you want... @Ekko Edited November 1, 2018 by IIYAMA Link to comment
Ekko Posted November 1, 2018 Author Share Posted November 1, 2018 (edited) 17 minutes ago, IIYAMA said: A very quick and basic solution, would be: local siren = #getAttachedElements (vehicle) > 0 Place it where you think it would make sense in your code. And if you do not know where to place it, you can always try it at all 24 lines till the code finally does what you want... @Ekko i did like you said it didn't work explain more pls Edited November 1, 2018 by Ekko Link to comment
Moderators IIYAMA Posted November 1, 2018 Moderators Share Posted November 1, 2018 getAttachedElements (vehicle) This returns a table with attached elements. #table # gets the length of a table. value > 0 This returns true or false depending if the value is higher than 0. local serin = result This saves the result in to serin. Link to comment
Ekko Posted November 1, 2018 Author Share Posted November 1, 2018 1 minute ago, IIYAMA said: getAttachedElements (vehicle) This returns a table with attached elements. #table # gets the length of a table. value > 0 This returns true or false depending if the value is higher than 0. local serin = result This saves the result in to serin. Ok man but i tryied the code at all 24 lanes didn't work i dont know what to do now Link to comment
Moderators IIYAMA Posted November 1, 2018 Moderators Share Posted November 1, 2018 2 minutes ago, Ekko said: Ok man but i tryied the code at all 24 lanes didn't work i dont know what to do now Debug your code? https://wiki.multitheftauto.com/index.php?title=Debugging Learn the basics of lua? Write down what all functions do? (in order to understand what the code does) You could do that. Link to comment
LyricalMM Posted November 3, 2018 Share Posted November 3, 2018 (edited) function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) local siren = getElementData(vehicle, "siren") if isPedInVehicle(player) then if id == 560 then if not siren then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) setElementData(vehicle, "siren", true) else local attachedElements = #getAttachedElements (vehicle) for i,v in ipairs (attachedElements) do detachElements (v, vehicle) setElementData(vehicle, "siren", false) end end end end end addCommandHandler("taxion",undercover) try this or you can make a function to getVehicleByType, then make a db reference Edited November 3, 2018 by LyricalMM Link to comment
Ekko Posted November 4, 2018 Author Share Posted November 4, 2018 13 hours ago, LyricalMM said: function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) local siren = getElementData(vehicle, "siren") if isPedInVehicle(player) then if id == 560 then if not siren then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) setElementData(vehicle, "siren", true) else local attachedElements = #getAttachedElements (vehicle) for i,v in ipairs (attachedElements) do detachElements (v, vehicle) setElementData(vehicle, "siren", false) end end end end end addCommandHandler("taxion",undercover) try this or you can make a function to getVehicleByType, then make a db reference didn't work Link to comment
Dimos7 Posted November 4, 2018 Share Posted November 4, 2018 function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) local siren = getElementData(vehicle, "siren") if isPedInVehicle(player) then if id == 560 then if not siren then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) setElementData(vehicle, "siren", true) else for i,v in ipairs (getAttachedElements(vehicle) ) do detachElements (v, vehicle) setElementData(vehicle, "siren", false) end end end end end addCommandHandler("taxion",undercover) Try this Link to comment
Ekko Posted November 4, 2018 Author Share Posted November 4, 2018 4 minutes ago, Dimos7 said: function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) local siren = getElementData(vehicle, "siren") if isPedInVehicle(player) then if id == 560 then if not siren then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) setElementData(vehicle, "siren", true) else for i,v in ipairs (getAttachedElements(vehicle) ) do detachElements (v, vehicle) setElementData(vehicle, "siren", false) end end end end end addCommandHandler("taxion",undercover) Try this damn you are so good wow , can you make it when i enter elevetor the object dont disappear pls !! ? Link to comment
Dimos7 Posted November 4, 2018 Share Posted November 4, 2018 42 minutes ago, Ekko said: damn you are so good wow , can you make it when i enter elevetor the object dont disappear pls !! ? What do you mean? Link to comment
Ekko Posted November 4, 2018 Author Share Posted November 4, 2018 1 minute ago, Dimos7 said: What do you mean? i mean when i enter an elevator to tp to a garage the object disappear Link to comment
LyricalMM Posted November 4, 2018 Share Posted November 4, 2018 4 hours ago, Ekko said: i mean when i enter an elevator to tp to a garage the object disappear you need to tp the vehicle into the same dimension and interior, then use warpPlayerIntoVehicle Link to comment
Dimos7 Posted November 4, 2018 Share Posted November 4, 2018 function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) local siren = getElementData(vehicle, "siren") if isPedInVehicle(player) then if id == 560 then if not siren then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) setElementData(vehicle, "siren", true) setElementInterior(Object, getElementInterior(vehicle)) setElementDimension(Object, getElementDimension(vehicle)) else for i,v in ipairs (getAttachedElements(vehicle) ) do detachElements (v, vehicle) setElementData(vehicle, "siren", false) end end end end end addCommandHandler("taxion",undercover) This should work Link to comment
Ekko Posted November 4, 2018 Author Share Posted November 4, 2018 (edited) 5 hours ago, Dimos7 said: function undercover (player) local vehicle = getPedOccupiedVehicle(player) local id = getElementModel(vehicle) local siren = getElementData(vehicle, "siren") if isPedInVehicle(player) then if id == 560 then if not siren then local Object = createObject(1668,5,5,5) attachElements ( Object, vehicle, -0.4, 0.5, 0.868 ) setElementData(vehicle, "siren", true) setElementInterior(Object, getElementInterior(vehicle)) setElementDimension(Object, getElementDimension(vehicle)) else for i,v in ipairs (getAttachedElements(vehicle) ) do detachElements (v, vehicle) setElementData(vehicle, "siren", false) end end end end end addCommandHandler("taxion",undercover) This should work the object still dont show inside the garage (dimension/interior) Edited November 4, 2018 by Ekko Link to comment
Dimos7 Posted November 4, 2018 Share Posted November 4, 2018 go to tp script and do getAttachedElements and make it go with the element go to interior Link to comment
Ekko Posted November 4, 2018 Author Share Posted November 4, 2018 1 hour ago, Dimos7 said: go to tp script and do getAttachedElements and make it go with the element go to interior when i add it specifically pls her is the tp marker = {} marker[1] = createMarker(1906.501953125, -2294.4736328125, 13.75768661499, "corona", 1.5, 100, 0, 100, 100) setElementInterior(marker[1], 56) setElementDimension (marker[1], 44 ) function TelePort(Element, hitElement) setElementInterior(Element, 0) setElementDimension (Element, 0) setElementInterior(hitElement, 0) setTimer(setElementInterior, 10, 1, Element, 0) setTimer(setElementInterior, 10, 1, hitElement, 0) setElementPosition(Element, 1335.4150390625, 446.3466796875, 20.284374237061, true) setElementFrozen(Element, true) setTimer(setElementFrozen, 1000, 1,Element, false) setElementRotation ( Element, 0, 0, 248.84687805176 ) end addEventHandler("onMarkerHit",marker[1], function (player) if getElementType(player)=="player" then local vehicle = getPedOccupiedVehicle(player) if vehicle then local pTeam = getPlayerTeam(player) if pTeam and getTeamName(pTeam) == 'Gendarmerie Royale' then TelePort(vehicle, player) return end outputChatBox ('You are not in this Faction!',player, 255, 0, 0 ) else outputChatBox ('You need to be in Vehicle to enter this Garage!',player, 255, 0, 0 ) end end end) Link to comment
Dimos7 Posted November 4, 2018 Share Posted November 4, 2018 marker = {} marker[1] = createMarker(1906.501953125, -2294.4736328125, 13.75768661499, "corona", 1.5, 100, 0, 100, 100) setElementInterior(marker[1], 56) setElementDimension (marker[1], 44 ) function TelePort(Element, hitElement) for k, v in ipairs(getAttachedElements(Element)) do setElementInterior(v, 0) setElementDimension(v, 0) setElementInterior(Element, 0) setElementDimension (Element, 0) setElementInterior(hitElement, 0) setTimer(setElementInterior, 10, 1, Element, 0) setTimer(setElementInterior, 10, 1, hitElement, 0) setElementPosition(Element, 1335.4150390625, 446.3466796875, 20.284374237061, true) setElementFrozen(Element, true) setTimer(setElementFrozen, 1000, 1,Element, false) setElementRotation ( Element, 0, 0, 248.84687805176 ) end end addEventHandler("onMarkerHit",marker[1], function (player) if getElementType(player)=="player" then local vehicle = getPedOccupiedVehicle(player) if vehicle then local pTeam = getPlayerTeam(player) if pTeam and getTeamName(pTeam) == 'Gendarmerie Royale' then TelePort(vehicle, player) return end outputChatBox ('You are not in this Faction!',player, 255, 0, 0 ) else outputChatBox ('You need to be in Vehicle to enter this Garage!',player, 255, 0, 0 ) end end end) try something like this Link to comment
Ekko Posted November 4, 2018 Author Share Posted November 4, 2018 9 minutes ago, Dimos7 said: marker = {} marker[1] = createMarker(1906.501953125, -2294.4736328125, 13.75768661499, "corona", 1.5, 100, 0, 100, 100) setElementInterior(marker[1], 56) setElementDimension (marker[1], 44 ) function TelePort(Element, hitElement) for k, v in ipairs(getAttachedElements(Element)) do setElementInterior(v, 0) setElementDimension(v, 0) setElementInterior(Element, 0) setElementDimension (Element, 0) setElementInterior(hitElement, 0) setTimer(setElementInterior, 10, 1, Element, 0) setTimer(setElementInterior, 10, 1, hitElement, 0) setElementPosition(Element, 1335.4150390625, 446.3466796875, 20.284374237061, true) setElementFrozen(Element, true) setTimer(setElementFrozen, 1000, 1,Element, false) setElementRotation ( Element, 0, 0, 248.84687805176 ) end end addEventHandler("onMarkerHit",marker[1], function (player) if getElementType(player)=="player" then local vehicle = getPedOccupiedVehicle(player) if vehicle then local pTeam = getPlayerTeam(player) if pTeam and getTeamName(pTeam) == 'Gendarmerie Royale' then TelePort(vehicle, player) return end outputChatBox ('You are not in this Faction!',player, 255, 0, 0 ) else outputChatBox ('You need to be in Vehicle to enter this Garage!',player, 255, 0, 0 ) end end end) try something like this thanks man it work perfectly your the best 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