-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- DESCRIPTION: smallg's animated pickup script -- DESCRIPTION: [SCRIPTNAME$="weapon"] (the script to call when player collects the item - don't put .lua) -- DESCRIPTION: (include only/any subfolders after scriptbank - i.e. "objects\\key" -- DESCRIPTION: [PROMPTTEXT$="Collect? (E)"] (the prompt to show when looking at item) -- DESCRIPTION: [HOVERHEIGHT=30] (how far up the item will hover) -- DESCRIPTION: [HOVERSPEED=60] (how quickly the item will rise and fall -- DESCRIPTION: [SPINSPEED=15] (how quickly the item will spin (set a negative value to spin in the opposite direction)) -- DESCRIPTION: [PICKUPRANGE=120] (how far away item can be collected from) -- DESCRIPTION: [PICKUPANGLE=10(1,180)] (angle the item can be picked up from) -- DESCRIPTION: (set hoverspeed or spinspeed to 0 if you don't want to hover / spin) U = U or require "scriptbank\\utillib" g_animated_pickup = {} otherscript = {} local direction = {} local startingheight = {} function animated_pickup_properties(e, scriptname, prompttext, hoverheight, hoverspeed, spinspeed, pickuprange, pickupangle) local ap = g_animated_pickup[e] ap.scriptname = scriptname ap.prompttext = prompttext ap.hoverheight = hoverheight ap.hoverspeed = hoverspeed ap.spinspeed = spinspeed ap.spinclockwise = spinclockwise ap.pickuprange = pickuprange ap.pickupangle = pickupangle if ap.spinclockwise ~= 1 then ap.spinclockwise = -1 end end function animated_pickup_init(e) g_animated_pickup[e] = {} local ap = g_animated_pickup[e] ap.scriptname = "weapon" ap.prompttext = "Collect? (E)" ap.hoverheight = 30 ap.hoverspeed = 60 ap.spinspeed = 15 ap.spinclockwise = 1 ap.pickuprange = 120 ap.pickupangle = 10 direction[e] = "up" startingheight[e] = g_Entity[e]['y'] end function animated_pickup_main(e) local ap = g_animated_pickup[e] if otherscript[e] == nil then otherscript[e] = "scriptbank\\"..ap.scriptname require(otherscript[e]) return end if U.PlayerLookingNear(e, ap.pickuprange, ap.pickupangle) == true then PromptLocal(e,ap.prompttext) if g_KeyPressE == 1 then SwitchScript(e, otherscript[e]) end end local ftime = GetElapsedTime() local thoverspeed = ap.hoverspeed*ftime if direction[e] == "up" then if g_Entity[e]['y'] < startingheight[e] + ap.hoverheight then SetPosition(e,g_Entity[e]['x'],g_Entity[e]['y']+thoverspeed,g_Entity[e]['z']) ResetPosition(e,g_Entity[e]['x'],g_Entity[e]['y']+thoverspeed,g_Entity[e]['z']) else direction[e] = "down" end else if g_Entity[e]['y'] > startingheight[e] then SetPosition(e,g_Entity[e]['x'],g_Entity[e]['y']-thoverspeed,g_Entity[e]['z']) ResetPosition(e,g_Entity[e]['x'],g_Entity[e]['y']-thoverspeed,g_Entity[e]['z']) else direction[e] = "up" end end local tspinspeed = ap.spinspeed*ftime SetRotation(e,g_Entity[e]['anglex'],g_Entity[e]['angley']+(tspinspeed*ap.spinclockwise),g_Entity[e]['anglez']) ResetRotation(e,g_Entity[e]['anglex'],g_Entity[e]['angley']+(tspinspeed*ap.spinclockwise),g_Entity[e]['anglez']) end