Skip to content

Soil system #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions client/cl_planting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ local RayCastCamera = function(dist)
local dir = RotationToDirection(camRot)
local dest = camPos + (dir * dist)
local ray = StartShapeTestRay(camPos, dest, 17, -1, 0)
local _, hit, endPos, surfaceNormal, entityHit = GetShapeTestResult(ray)
local _, hit, endPos, surfaceNormal, materialHash, entityHit = GetShapeTestResultIncludingMaterial(ray)
if hit == 0 then endPos = dest end
return hit, endPos, entityHit, surfaceNormal
return hit, endPos, entityHit, surfaceNormal, materialHash
end

--- Player load, unload and update handlers
Expand Down Expand Up @@ -51,21 +51,40 @@ RegisterNetEvent('ps-weedplanting:client:UseWeedSeed', function()
local ModelHash = Shared.WeedProps[1]
RequestModel(ModelHash)
while not HasModelLoaded(ModelHash) do Wait(0) end
exports['qb-core']:DrawText(_U('place_or_cancel'), 'left')
local hit, dest, _, _ = RayCastCamera(Shared.rayCastingDistance)
local hit, dest, _, _, material = RayCastCamera(Shared.rayCastingDistance)
local plant = CreateObject(ModelHash, dest.x, dest.y, dest.z + Shared.ObjectZOffset, false, false, false)
SetEntityCollision(plant, false, false)
SetEntityAlpha(plant, 150, true)

-- exports['qb-core']:DrawText(_U('place_or_cancel'), 'left')

local canPlant = false
local planted = false
while not planted do
Wait(0)
hit, dest, _, _ = RayCastCamera(Shared.rayCastingDistance)

if hit == 1 then
local materialFound = false

for _, value in ipairs(Shared.Soil) do
if material == value then
materialFound = true
end
end

if materialFound then
exports['qb-core']:DrawText(_U('place_or_cancel'), 'left')
canPlant = true
else
canPlant = false
end

SetEntityCoords(plant, dest.x, dest.y, dest.z + Shared.ObjectZOffset)

-- [E] To spawn plant
if IsControlJustPressed(0, 38) then
if IsControlJustPressed(0, 38) and canPlant then
canPlant = false
planted = true
exports['qb-core']:KeyPressed(38)
DeleteObject(plant)
Expand Down
12 changes: 12 additions & 0 deletions shared/sh_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ Shared.DropOffPeds = { -- Drop-off ped models
'a_m_y_epsilon_02',
'a_m_y_mexthug_01'
}

Shared.Soil = {
"1109728704",
"-1942898710",
"-1286696947",
"-1885547121",
"312396330",
"1288448767",
"-1595148316",
"510490462",
"1333033863",
}