-- Allows the player to pick-up the item (visibly), carry it and then drop (and interact e.g stack) -- Note - entity with this script must have Physics > YES & Static Mode > No local i_state = {} local itemdist = 100 local yangle = 0 local tCheckTime = {} carrying_now = 0 function carryvisibleitem2_init(e) i_state[e] = "start" end function carryvisibleitem2_main(e) if i_state[e] == "start" then tCheckTime[e] = GetTimer(e) i_state[e] = "initial" end PlayerDist = GetPlayerDistance(e) if PlayerDist < 150 then SourceAngle = g_PlayerAngY while SourceAngle < 0.0 do SourceAngle = SourceAngle + 360.0 end while SourceAngle > 340.0 do SourceAngle = SourceAngle - 360.0 end PlayerDX = (g_Entity[e]['x'] - g_PlayerPosX) PlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ) DestAngle = math.atan2( PlayerDZ , PlayerDX ) -- Convert to degrees DestAngle = (DestAngle * 57.2957795) - 90.0 Result = math.abs(math.abs(SourceAngle)-math.abs(DestAngle)) if Result > 180 then Result = 0 end if Result < 20.0 then if i_state[e] == "initial" and GetTimer(e) > tCheckTime[e] + 500 and carrying_now == 0 then Prompt ("Press E To Pick Up Item") if g_KeyPressE == 1 then GravityOff(e) CollisionOff(e) Show (e) yangle=g_PlayerAngY carrying_now = 1 i_state[e] = "carried" PlaySound(e,0) ActivateIfUsed(e) tCheckTime[e] = GetTimer(e) end end end end 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) i_state[e] = "wait" tCheckTime[e] = GetTimer(e) PlaySound(e,1) end end if i_state[e] == "wait" and GetTimer(e) > tCheckTime[e] + 500 then carrying_now = 0 i_state[e] = "start" end end -- of main function function carryvisibleitem2_exit(e) end