-- Allows the player to pick-up the item (visibly), carry it and then drop -- Note - entity with this script must have Physics > No & Static Mode > No local i_state = {} local itemdist = 100 local yangle = 0 local tCheckTime = {} function carryvisibleitem_init(e) i_state[e] = "start" end function carryvisibleitem_main(e) if i_state[e] == "start" then tCheckTime[e] = GetTimer(e) i_state[e] = "initial" end PlayerDX = g_Entity[e]['x'] - g_PlayerPosX; PlayerDY = g_Entity[e]['y'] - g_PlayerPosY; PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ; PlayerDist = math.sqrt(math.abs(PlayerDX^2)+math.abs(PlayerDY^2)+math.abs(PlayerDZ^2)); if PlayerDist < 150 then if i_state[e] == "initial" and GetTimer(e) > tCheckTime[e] + 500 then Prompt ("Press E To Pick Up Item") if g_KeyPressE == 1 then GravityOff(e) CollisionOff(e) Show (e) yangle=g_PlayerAngY i_state[e] = "carried" PlaySound(e,0) ActivateIfUsed(e) tCheckTime[e] = GetTimer(e) end end end -- end if player dist if i_state[e] == "carried" then --calculate and then hold the item 'itemdist' in front of player itemx=g_PlayerPosX itemz=g_PlayerPosZ itemy=g_PlayerPosY itemx = itemx+math.sin(math.rad(g_PlayerAngY))*itemdist itemz = itemz+math.cos(math.rad(g_PlayerAngY))*itemdist itemy = itemy-math.sin(math.rad(g_PlayerAngX))*itemdist -- hide if view angle drops underground or too high - adjust as needed if g_PlayerAngX > -50 and g_PlayerAngX < 25 then Show(e) else Hide(e) end SetPosition(e,itemx,itemy-15,itemz) -- mirror precisely the player Y angle for the items rotation to player yangle = g_PlayerAngY if g_PlayerAngY >= 360 then yangle = g_PlayerAngY - (360 * (math.floor(g_PlayerAngY / 360))) elseif g_PlayerAngY < 0 and g_PlayerAngY > -360 then yangle = g_PlayerAngY + 360 elseif g_PlayerAngY <= -360 then yangle = g_PlayerAngY + (360 * ( -1 * (math.floor(g_PlayerAngY / 360)))) end FaceAngle = yangle + 180 if FaceAngle > 360 then FaceAngle = FaceAngle - 360 end --adjust the '-20' to tilt the item further away/towards the player whilst being carried (set to 0 for flat) SetRotation(e,(g_PlayerAngX-20 * -1),FaceAngle,0) --SetRotation(e,0,FaceAngle,0) --check if player wants to drop item and if so drop Prompt ("Press E To Drop Item") if g_KeyPressE == 1 and GetTimer(e) > tCheckTime[e] + 500 then SetRotation(e,0,FaceAngle,0) GravityOn(e) CollisionOn(e) ResetPosition(e,itemx,itemy,itemz) i_state[e] = "start" PlaySound(e,1) end end end -- of main function function carryvisibleitem_exit(e) end