Mr.Solo Posted February 10, 2016 Share Posted February 10, 2016 so hai..well i made my first script that detatch Truck Trailer if you press "o" . but after i asked and tried all , i gave up..because bindkey dosn't seems to work with function.. help me!! this is script i used for server side. function unhookTrailer(source, commandName) if (source and isPedInVehicle(source)) then local theVehicle = getPedOccupiedVehicle(source) local success = detachTrailerFromVehicle(theVehicle) if (success) then outputChatBox("Trailer detached!", source) else outputConsole("Trailer not attatched.", source) end end end addCommandHandler("unhook", unhookTrailer) bindkey( source, "o", "up", unhookTrailer) Link to comment
Bonsai Posted February 10, 2016 Share Posted February 10, 2016 bindkey( source, "o", "up", unhookTrailer) What is the source there? If its outside of any function, it won't work like that. You could loop through all players and just bind the key for each of them. Also you should probably rather name the first parameter of the unhookTrailer function "player" instead of "source", since "source" is predefined when working with events. Link to comment
Mr.Solo Posted February 11, 2016 Author Share Posted February 11, 2016 so are you saying i need to put it in it's own function? well idk how , btw i tried make it in Client script with triggerServerEvent but failed.. Link to comment
Dimos7 Posted February 11, 2016 Share Posted February 11, 2016 addEventHandler("onPlayerLogin", root, function() bindKey(source, "o", "up", unhookTrailer) end ) addEventHandler("onResourceStart", resourceRoot, function() for _, v ipairs(getElementsByType("player")) do bindKey(v, "o", "up", unhookTrailer) end end ) function unhookTrailer(thePlayer, commandName) if (thePlayer and isPedInVehicle(thePlayer)) then local theVehicle = getPedOccupiedVehicle(thePlayer) local success = detachTrailerFromVehicle(theVehicle) if (success) then outputChatBox("Traller detached!", thePlayer) else outputChatBox("Traller not attatched.". thePlayer) end end end addCommandHandler("unhook", unhookTrailer) Link to comment
Mr.Solo Posted February 11, 2016 Author Share Posted February 11, 2016 addEventHandler("onPlayerLogin", root, function() bindKey(source, "o", "up", unhookTrailer) end ) addEventHandler("onResourceStart", resourceRoot, function() for _, v ipairs(getElementsByType("player")) do bindKey(v, "o", "up", unhookTrailer) end end ) function unhookTrailer(thePlayer, commandName) if (thePlayer and isPedInVehicle(thePlayer)) then local theVehicle = getPedOccupiedVehicle(thePlayer) local success = detachTrailerFromVehicle(theVehicle) if (success) then outputChatBox("Traller detached!", thePlayer) else outputChatBox("Traller not attatched.". thePlayer) end end end addCommandHandler("unhook", unhookTrailer) well tried using your code didn't work , tried edit it , same thing , i'm not even sure if i can do this script .. i guess i will try another idea , anyways thanks for trying.. Link to comment
Dimos7 Posted February 11, 2016 Share Posted February 11, 2016 addEventHandler("onPlayerLogin", root, function() bindKey(source, "o", "up", unhookTrailer) end ) addEventHandler("onResourceStart", resourceRoot, function() for _, v ipairs(getElementsByType("player")) do bindKey(v, "o", "up", unhookTrailer) end end ) function unhookTrailer(thePlayer, commandName) if (isPedInVehicle(thePlayer)) then local theVehicle = getPedOccupiedVehicle(thePlayer) local success = detachTrailerFromVehicle(theVehicle) if (success) then outputChatBox("Traller detached!", thePlayer) else outputChatBox("Traller not attatched.". thePlayer) end end end addCommandHandler("unhook", unhookTrailer) try that Link to comment
Mr.Solo Posted February 12, 2016 Author Share Posted February 12, 2016 addEventHandler("onPlayerLogin", root, function() bindKey(source, "o", "up", unhookTrailer) end ) addEventHandler("onResourceStart", resourceRoot, function() for _, v ipairs(getElementsByType("player")) do bindKey(v, "o", "up", unhookTrailer) end end ) function unhookTrailer(thePlayer, commandName) if (isPedInVehicle(thePlayer)) then local theVehicle = getPedOccupiedVehicle(thePlayer) local success = detachTrailerFromVehicle(theVehicle) if (success) then outputChatBox("Traller detached!", thePlayer) else outputChatBox("Traller not attatched.". thePlayer) end end end addCommandHandler("unhook", unhookTrailer) try that both command and bindkey dosn't work , it's hopeless nvm bro, i will try make other things Link to comment
Dimos7 Posted February 12, 2016 Share Posted February 12, 2016 use /debugscript 3 and see if there is any erors Link to comment
tosfera Posted February 12, 2016 Share Posted February 12, 2016 You guys are all forgetting a single thing.. if you detach a trailer, it'll get attached right away again due to the position of the trailer and the truck. @OP: try to use setElementPosition on the trailer when it gets detached to move it away from the truck to avoid it being attached again. Also, try to avoid isPedInVehicle since it fails quite often, a more reliable approach would be getPedOccupiedVehicle. also make sure that this script is on the server's side, not a client sided file. Link to comment
Dimos7 Posted February 12, 2016 Share Posted February 12, 2016 addEventHandler("onPlayerLogin", root, function() bindKey(source, "o", "up", unhookTrailer) end ) addEventHandler("onResourceStart", resourceRoot, function() for _, v in ipairs(getElementsByType("player")) do bindKey(v, "o", "up", unhookTrailer) end end ) function unhookTrailer(thePlayer, commandName) if isPedInVehicle(thePlayer) then local theVehicle = getPedOccupiedVehicle(thePlayer) local success = detachTrailerFromVehicle(theVehicle) local x, y, z = getElementPosition(theVehicle) if (success) then if getElementType("trailer") then setElementPosition(trailer, x+2, y, z) end outputChatBox("Trailer detached!", thePlayer) else outputChatBox("Trailer not attatched.", thePlayer) end end end addCommandHandler("unhook", unhookTrailer) Link to comment
Mr.Solo Posted February 12, 2016 Author Share Posted February 12, 2016 addEventHandler("onPlayerLogin", root, function() bindKey(source, "o", "up", unhookTrailer) end ) addEventHandler("onResourceStart", resourceRoot, function() for _, v in ipairs(getElementsByType("player")) do bindKey(v, "o", "up", unhookTrailer) end end ) function unhookTrailer(thePlayer, commandName) if isPedInVehicle(thePlayer) then local theVehicle = getPedOccupiedVehicle(thePlayer) local success = detachTrailerFromVehicle(theVehicle) local x, y, z = getElementPosition(theVehicle) if (success) then if getElementType("trailer") then setElementPosition(trailer, x+2, y, z) end outputChatBox("Trailer detached!", thePlayer) else outputChatBox("Trailer not attatched.", thePlayer) end end end addCommandHandler("unhook", unhookTrailer) ur legend thanks man , btw i do setelementPos x , y - 2 ,z or what?? Link to comment
Dimos7 Posted February 12, 2016 Share Posted February 12, 2016 y is the high so no x maybe change Link to comment
Chris!i! Posted February 14, 2016 Share Posted February 14, 2016 Use getElementPosition Then Add + 5 to x and y. Link to comment
Bonsai Posted February 14, 2016 Share Posted February 14, 2016 If you throw scripts at people instead of advices, they should better be working. if getElementType("trailer") then setElementPosition(trailer, x+2, y, z) ??? 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