local nearest = nil local nearest_dist = 180 local init_prop_dist = 170 local prop_dist = {} local init_nearest_dist = nearest_dist local cmode = 0 local new_y = 0 local prop_x = {} local prop_z = {} local ymod = {} local initpx = {} local new_nearest_dist = 0 local init_mwheel = 0 local block_size = 48 local placed_block = {} local blockx = {} local blocky = {} local blockz = {} local near_block = {} local new_selection_block_dist = init_prop_dist*2 function carry_object_init(e) cmode = 0 prop_dist[e] = init_prop_dist initpx[e] = 0 ymod[e] = 0 placed_block[e] = 0 near_block[e] = 0 end function carry_object_main(e) if selection_block == nil then selection_block = e ymod[selection_block] = g_PlayerPosY-30 return end CollisionOff(selection_block) new_y = math.rad(g_PlayerAngY) prop_x[selection_block] = g_PlayerPosX + (math.sin(new_y) * prop_dist[selection_block]) prop_z[selection_block] = g_PlayerPosZ + (math.cos(new_y) * prop_dist[selection_block]) if g_PlayerAngX < initpx[selection_block] and GetPlayerDistance(selection_block) < new_selection_block_dist*0.9 then ymod[selection_block] = ymod[selection_block] + (GetPlayerDistance(selection_block)/200) prop_dist[selection_block] = prop_dist[selection_block] + (GetPlayerDistance(selection_block)/300) new_selection_block_dist = new_selection_block_dist + (GetPlayerDistance(selection_block)/80) elseif g_PlayerAngX > initpx[selection_block] and g_Entity[selection_block]['y'] > g_PlayerPosY-30 then ymod[selection_block] = ymod[selection_block]-(GetPlayerDistance(selection_block)/200) prop_dist[selection_block] = prop_dist[selection_block] - (GetPlayerDistance(selection_block)/300) new_selection_block_dist = new_selection_block_dist - (GetPlayerDistance(selection_block)/80) else --ymod[selection_block] = 0 end RotateToCamera(selection_block) initpx[selection_block] = g_PlayerAngX SetPosition(selection_block,prop_x[selection_block],ymod[selection_block],prop_z[selection_block]) --Text(50,80,3,ymod[selection_block]) if cmode == 0 then if nearest == nil then nearest_dist = init_nearest_dist elseif GetPlayerDistance(nearest) > nearest_dist then nearest_dist = init_nearest_dist end if GetPlayerDistance(e) < nearest_dist and PlayerLooking(e,nearest_dist,10) == 1 then nearest_dist = GetPlayerDistance(e) nearest = e end if GetDistance(e,selection_block) <= block_size*1.5 and PlayerLooking(e,new_selection_block_dist,10) == 1 and e ~= selection_block then Prompt("Press E to carry") if g_KeyPressE == 1 then cmode = 1 initpx[e] = g_PlayerAngX prop_dist[e] = GetPlayerDistance(e)*0.95 ymod[e] = g_Entity[e]['y'] nearest = e init_mwheel = g_MouseWheel placed_block[e] = 0 new_nearest_dist = init_nearest_dist*1.5 return end end elseif cmode == 1 then new_y = math.rad(g_PlayerAngY) prop_x[nearest] = g_PlayerPosX + (math.sin(new_y) * prop_dist[nearest]) prop_z[nearest] = g_PlayerPosZ + (math.cos(new_y) * prop_dist[nearest]) if g_PlayerAngX < initpx[nearest] and GetPlayerDistance(nearest) < new_nearest_dist*0.9 then ymod[nearest] = ymod[nearest] + (GetPlayerDistance(nearest)/200) prop_dist[nearest] = prop_dist[nearest] + (GetPlayerDistance(nearest)/300) new_nearest_dist = new_nearest_dist + (GetPlayerDistance(nearest)/80) elseif g_PlayerAngX > initpx[nearest] and g_Entity[nearest]['y'] > g_PlayerPosY-30 then ymod[nearest] = ymod[nearest]-(GetPlayerDistance(nearest)/200) prop_dist[nearest] = prop_dist[nearest] - (GetPlayerDistance(nearest)/300) new_nearest_dist = new_nearest_dist - (GetPlayerDistance(nearest)/80) else --ymod[nearest] = 0 end initpx[nearest] = g_PlayerAngX CollisionOff(nearest) if g_MouseWheel < init_mwheel then SetRotation(nearest,g_Entity[nearest]['anglex'],g_Entity[nearest]['angley']-3,g_Entity[nearest]['anglez']) elseif g_MouseWheel > init_mwheel then SetRotation(nearest,g_Entity[nearest]['anglex'],g_Entity[nearest]['angley']+3,g_Entity[nearest]['anglez']) end init_mwheel = g_MouseWheel SetPosition(nearest , prop_x[nearest], ymod[nearest], prop_z[nearest]) --RotateToCamera(nearest) CollisionOn(nearest) --Text(50,85,3,ymod[nearest]) --Text(50,70,3,GetPlayerDistance(nearest)) --Text(50,75,3,new_nearest_dist*0.9) Prompt("Release E to drop") if g_KeyPressE == 0 or GetPlayerDistance(nearest) > new_nearest_dist then cmode = 0 CollisionOff(nearest) nearest_dist = init_nearest_dist blockx[nearest] = nil blocky[nearest] = nil blockz[nearest] = nil near_block[nearest] = 0 for a = 1, 9999 do if g_Entity[a] ~= nil then if a ~= nearest and a ~= selection_block then if placed_block[a] ~= nil then if placed_block[a] == 1 then if GetDistance(nearest,a) < block_size*1.5 then near_block[e] = 1 if blocky[nearest] == nil then if g_Entity[nearest]['y'] > g_Entity[a]['y']+(block_size/2) then blocky[nearest] = g_Entity[a]['y']+block_size else blocky[nearest] = g_Entity[a]['y'] end end if blockx[nearest] == nil then if g_Entity[nearest]['x'] > g_Entity[a]['x']+(block_size/2) then blockx[nearest] = g_Entity[a]['x']+block_size elseif g_Entity[nearest]['x'] < g_Entity[a]['x']-(block_size/2) then blockx[nearest] = g_Entity[a]['x']-block_size else blockx[nearest] = g_Entity[a]['x'] end end if blockz[nearest] == nil then if g_Entity[nearest]['z'] > g_Entity[a]['z']+(block_size/2) then blockz[nearest] = g_Entity[a]['z']+block_size elseif g_Entity[nearest]['z'] < g_Entity[a]['z']-(block_size/2) then blockz[nearest] = g_Entity[a]['z']-block_size else blockz[nearest] = g_Entity[a]['z'] end end end end end end end end if blockx[nearest] == nil then blockx[nearest] = prop_x[nearest] --CollisionOn(nearest) end if blocky[nearest] == nil then blocky[nearest] = ymod[nearest] --CollisionOn(nearest) end if blockz[nearest] == nil then blockz[nearest] = prop_z[nearest] --CollisionOn(nearest) end SetPosition(nearest , blockx[nearest] , blocky[nearest] , blockz[nearest]) if near_block[nearest] == 0 then CollisionOn(nearest) end placed_block[nearest] = 1 nearest = nil end end if placed_block[e] == 1 and near_block[e] == 1 then CollisionOff(e) SetPosition(e , blockx[e] , blocky[e] , blockz[e]) CollisionOn(e) end --Text(50,80,3,g_PlayerAngX) end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end function GetDistance(e,v) if g_Entity[e] ~= nil and g_Entity[e] ~= 0 and g_Entity[v] ~= nil and g_Entity[v] ~= 0 then local disx = g_Entity[e]['x'] - g_Entity[v]['x'] local disz = g_Entity[e]['z'] - g_Entity[v]['z'] local disy = g_Entity[e]['y'] - g_Entity[v]['y'] return math.sqrt(disx^2 + disz^2 + disy^2) end end