Advertisement
Noneatme

Untitled

Dec 27th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.63 KB | None | 0 0
  1. --[[
  2.     ##########################################################################
  3.     ##                                                                      ##
  4.     ## Project: 'MT-RPG' - Gamemode for MTA: San Andreas PROJECT X          ##
  5.     ##                      Developer: Noneatme                             ##
  6.     ##           License: See LICENSE in the top level directory            ##
  7.     ##                                                                      ##
  8.     ##########################################################################
  9. ]]
  10.  
  11.  
  12. local cFunc = {}
  13. local cSetting = {}
  14.  
  15. objectmover = {}
  16.  
  17. cSetting["attached_info"] = {}
  18.  
  19. addEvent("onObjectmoverGroundpositionGetBack", true)
  20.  
  21. -- FUNCTIONS --
  22.  
  23. objectmover.attachObjectToPlayer = function(thePlayer, object)
  24.     assert((isElement(object) and getElementType(object) == "object"), "Bad Argument @ attachObjectToPlayer (Object not an object)")
  25.     assert((isElement(thePlayer) and getElementType(thePlayer) == "player"), "Bad Argument @ attachObjectToPlayer (Player not a player)")
  26.     if not(cSetting["attached_info"][thePlayer]) then
  27.         cSetting["attached_info"][thePlayer] = {}
  28.     end
  29.     if(cSetting["attached_info"][thePlayer]["status"] ~= true) and not(isTimer(cSetting["attached_info"][thePlayer]["attachTimer"])) then
  30.         cSetting["attached_info"][thePlayer]["status"] = true
  31.         cSetting["attached_info"][thePlayer]["attachedObject"] = object
  32.        
  33.         local rotx, roty, rotz = getElementRotation(thePlayer)
  34.         local ang = getPedRotation(thePlayer)
  35.         local x, y, z = getElementPosition(thePlayer)
  36.         local x2, y2, z2 = getElementPosition(object)
  37.         local sx, sy, sz = x+math.sin(math.rad(-ang))*2, y+math.cos(math.rad(-ang))*2, z
  38.        
  39.         moveObject(object, 300, sx, sy, sz, rotx, roty, rotz-180)
  40.         cSetting["attached_info"][thePlayer]["attachTimer"] = setTimer(function()
  41.             attachElements(object, thePlayer, 0, 2, 0)
  42.             setElementAlpha(object, 200)
  43.             toggleControl(thePlayer, "jump", false)
  44.             toggleControl(thePlayer, "enter_exit", false)
  45.             setElementCollisionsEnabled(object, false)
  46.         end, 300, 1)
  47.     else
  48.         outputInfobox(thePlayer, "You are currently moving a object!", 255, 0, 0)
  49.     end
  50. end
  51.  
  52.  
  53. objectmover.detachObjectFromPlayer = function(thePlayer, z, state)
  54. --  assert((isElement(thePlayer) and getElementType(thePlayer) == "player"), "Bad Argument @ attachObjectToPlayer (Player not a player)")
  55.     if(state ~= true) then
  56.         if(cSetting["attached_info"][thePlayer]["status"] == true) then
  57.             triggerClientEvent(thePlayer, "onObjectmoverGroundpositionGet", thePlayer, cSetting["attached_info"][thePlayer]["attachedObject"])
  58.         end
  59.     else
  60.         local theObject = thePlayer
  61.         thePlayer = source
  62.         setElementAlpha(theObject, 255)
  63.         detachElements(theObject)
  64.         local rotx, roty, rotz = getElementRotation(thePlayer)
  65.        
  66.         local ang = getPedRotation( thePlayer )
  67.         local x, y, z2 = getElementPosition( thePlayer )
  68.         local sx, sy, sz = x+math.sin(math.rad(-ang))*2, y+math.cos(math.rad(-ang))*2, z
  69.         setElementCollisionsEnabled(theObject, true)
  70.         setElementPosition( theObject, sx, sy, z2)
  71.         setElementRotation( theObject, rotx, roty, rotz)
  72.         moveObject( theObject, 300, sx, sy, z)
  73.         setTimer(setElementPosition, 300, 1, theObject, sx, sy, sz)
  74.         toggleControl(thePlayer, "jump", true)
  75.         toggleControl(thePlayer, "enter_exit", true)
  76.         setTimer(function()
  77.             cSetting["attached_info"][thePlayer]["status"] = false
  78.             cSetting["attached_info"][thePlayer]["attachedObject"] = nil
  79.         end, 300, 1)
  80.     end
  81. end
  82.  
  83. objectmover.getPlayerAttachedObject = function(thePlayer)
  84.     assert((isElement(thePlayer) and getElementType(thePlayer) == "player"), "Bad Argument @ getPlayerAttachedObject (Player not a player)")
  85.     if not(cSetting["attached_info"][thePlayer]) then
  86.         cSetting["attached_info"][thePlayer] = {}
  87.     end
  88.     return (cSetting["attached_info"][thePlayer]["attachedObject"] or false)
  89. end
  90.  
  91. cFunc["check_objectmov"] = function()
  92.     local thePlayer = source
  93.     if(objectmover.getPlayerAttachedObject(thePlayer) ~= false) then
  94.         local object = objectmover.getPlayerAttachedObject(thePlayer)
  95.         local x, y, z = getElementPosition(object)
  96.         detachElements(object)
  97.         setElementPosition(object, x, y, z)
  98.         setElementAlpha(object, 255)
  99.         setElementCollisionsEnabled(object, true)
  100.         cSetting["attached_info"][thePlayer] = {}
  101.     end
  102. end
  103.  
  104. -- EVENT HANDLERS --
  105.  
  106. addEventHandler("onObjectmoverGroundpositionGetBack", getRootElement(), objectmover.detachObjectFromPlayer)
  107. addEventHandler("onPlayerQuit", getRootElement(), cFunc["check_objectmov"])
  108.  
  109. addCommandHandler("spawnele", function(thePlayer)
  110.     local x, y, z = getElementPosition(thePlayer)
  111.     local object = createObject(1439, x, y, z-1)
  112.     setElementData(object, "pickupable", true)
  113. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement