Last active
August 11, 2019 04:15
-
-
Save throwarray/ff81081e9857055c7158b4422f2339e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function LoadModel (model) | |
if not IsModelInCdimage(model) then return end | |
RequestModel(model) | |
while not HasModelLoaded(model) do Citizen.Wait(0) end | |
return model | |
end | |
function CreateObj (model, coords, ang, networked) | |
LoadModel(model) | |
local entity = CreateObject(model, coords.x, coords.y, coords.z, networked == true, true, true) | |
SetEntityHeading(entity, ang or 0.0) | |
SetModelAsNoLongerNeeded(model) | |
return entity | |
end | |
function headsUp(text) | |
SetTextComponentFormat('STRING') | |
AddTextComponentString(text) | |
DisplayHelpTextFromStringLabel(0, 0, 1, -1) | |
end | |
DecorRegister('tr_container', 3) | |
RegisterCommand('pin', function (source, arg, rawInput) | |
local playerPed = PlayerPedId() | |
local vehicle = GetVehiclePedIsIn(PlayerPedId(), 0) | |
if GetPedInVehicleSeat(vehicle, -1) == playerPed --[[Driver]] then | |
if IsVehicleAttachedToTrailer(vehicle) then | |
local IsVehicleAttachedToTrailer, trailer = GetVehicleTrailerVehicle(vehicle, 0) | |
if GetEntityModel(trailer) == GetHashKey('trflat') then | |
if DecorExistOn(trailer, 'tr_container') then | |
local box = NetToObj(DecorGetInt(trailer, 'tr_container')) | |
if DoesEntityExist(box) then | |
headsUp('Container detached from trailer') | |
DetachEntity(box, trailer, false) | |
DecorRemove(trailer, 'tr_container') | |
end | |
else | |
local bone = GetEntityBoneIndexByName(trailer, "chassis") | |
local coords = GetEntityCoords(trailer) + GetWorldPositionOfEntityBone(trailer, bone) | |
local box = GetClosestObjectOfType(coords, 1.5, GetHashKey('prop_contr_03b_ld'), 0, 0, 1); | |
if DoesEntityExist(box) then | |
DecorSetInt(trailer, 'tr_container', ObjToNet(box)) | |
AttachEntityToEntity(box, trailer, bone, 4103, | |
-0.0, 0.35, -0.0, -- position | |
0.0, 0.0, 0.0, -- rotation | |
false, false, false, false, 2, true | |
) | |
headsUp('Attached container to trailer') | |
print('Attached container to trailer', IsEntityUpright(box, 10.0)) | |
end | |
end | |
end | |
end | |
end | |
end) | |
Citizen.CreateThread(function () | |
local vehicle | |
local veh = -1 | |
local wasPinned | |
local boxModel = GetHashKey('prop_contr_03b_ld') -- THRIFTEX | |
local boxHealth | |
---- DEBUG Create a box infront of player | |
box = CreateObj(boxModel, GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 15.0, 0.0), 0.0, true) | |
FreezeEntityPosition(box, 0) | |
ActivatePhysics(box) | |
-- | |
-- phantom | |
-- trflat | |
-- handler | |
local nearestBox | |
while true do | |
-- Check player vehicle | |
veh = GetVehiclePedIsIn(PlayerPedId(), 0) | |
if vehicle ~= veh then | |
if not IsEntityDead(PlayerPedId()) and GetEntityModel(veh) == GetHashKey('handler') then | |
vehicle = veh | |
print('Enter vehicle ' .. vehicle) | |
else | |
vehicle = nil | |
veh = nil | |
end | |
end | |
-- In 'handler vehicle | |
if vehicle then | |
local box = GetClosestObjectOfType(GetEntityCoords(vehicle, 1), 15.0, boxModel, 0, 0, 1); | |
local boxCoords = GetEntityCoords(box) | |
local wasPressed = IsControlJustPressed(0, 51) | |
SetInputExclusive(0, 51) -- no horn | |
-- FIXME How to get nearest trailer for container placement | |
rayHandle, targeted, targetedCoords, surfaceNormal, targetedEntity = GetShapeTestResult(StartShapeTestCapsule( | |
boxCoords.x, boxCoords.y, boxCoords.z - 1.0, | |
boxCoords.x, boxCoords.y, boxCoords.z - 1.0, | |
2.0, | |
10, box, 7 | |
)) | |
if DoesEntityExist(targetedEntity) and GetEntityModel(targetedEntity) == GetHashKey('trflat') then | |
targetedCoords = GetEntityCoords(targetedEntity) | |
if GetDistanceBetweenCoords(boxCoords, targetedCoords) <= 1.5 then | |
DrawMarker( | |
1, targetedCoords.x, targetedCoords.y, targetedCoords.z + 0.5, 0.0, 0.0, 0.0, 0, 0.0, 0.0, | |
1.5, 1.5, 5.0, | |
0, 255, 0, 100, false, false, 2, false, false, false, false | |
) | |
end | |
end | |
----- | |
if wasPressed then | |
wasPinned = N_0x89d630cf5ea96d23(vehicle, box) | |
RequestScriptAudioBank("Container_Lifter", false, -1) | |
if wasPinned then -- Unpin attached entity | |
if N_0x62ca17b74c435651(vehicle) ~= 1 then | |
PlaySoundFromEntity(-1, "Container_Release", vehicle, "CONTAINER_LIFTER_SOUNDS", 0, 0); | |
headsUp('CONTAINER WAS RELEASED.') | |
print('CONTAINER WAS RELEASED.' ) | |
end | |
else | |
-- Pin entity to vehicle | |
if GetDistanceBetweenCoords( | |
GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "frame_2")), GetEntityCoords(box), true) < 5.0 then | |
N_0x6a98c2ecf57fa5d4(vehicle, box) | |
if N_0x62ca17b74c435651(vehicle) == 1 then | |
PlaySoundFromEntity(-1, "Container_Attach", vehicle, "CONTAINER_LIFTER_SOUNDS", 0, 0) | |
headsUp('CONTAINER WAS ATTACHED.') | |
print('CONTAINER WAS ATTACHED.') | |
end | |
boxHealth = GetEntityHealth(box) -- track health changes | |
else | |
headsUp('NO CONTAINER NEARBY') | |
end | |
end | |
elseif N_0x62ca17b74c435651(vehicle) == 1 then | |
-- Entity being damaged | |
if HasEntityCollidedWithAnything(box) then | |
PlaySoundFromEntity(-1, "Container_Land", vehicle, "CONTAINER_LIFTER_SOUNDS", 0, 0) | |
Wait(100) -- magic | |
if N_0x62ca17b74c435651(vehicle) ~= 1 or N_0x89d630cf5ea96d23(vehicle, box) == 1 then | |
headsUp('CONTAINER DAMAGED AND FELL.') | |
print('CONAINER DAMAGED AND FELL') | |
end | |
else | |
headsUp('CONTAINER HEALTH: ' .. GetEntityHealth(box) ) | |
end | |
boxHealth = GetEntityHealth(box) | |
-- Entity is being released | |
elseif wasPinned then | |
wasPinned = false | |
--headsUp('Container falling.') | |
end | |
end | |
Wait(0) | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment