Vorp Core Tutorial IconVorp Core Tutorial Icon

Example is for vorp_weaponsv2 – Vorp/Redm/CFX/LUA
This is a native function called FreezeEntityPosition.

client.lua

In the client.lua line around line 692 you see this line

local distance = #(coordsDist - coordsStore)
if (distance <= 3.0) then -- check distance

Add the following code between those two lines.

if distance >= 11.0 then -- check distance  
	Citizen.CreateThread(function()                                 
		SetBlockingOfNonTemporaryEvents(Config3.Stores[storeId].NPC, true)
		FreezeEntityPosition(Config3.Stores[storeId].NPC, true)  
	end)  
end 
if distance <= 10.0 and distance >= 3.0 then -- check distance  
	Citizen.CreateThread(function()                                 
		SetBlockingOfNonTemporaryEvents(Config3.Stores[storeId].NPC, false)
		FreezeEntityPosition(Config3.Stores[storeId].NPC, false)
		TaskTurnPedToFaceEntity(Config3.Stores[storeId].NPC, player, -1) 
		--print("NPC face players")
	end)  
end 

That will turn on and off the npc turning to face the player.

The first section refreezes the npc after the player walks away. This prevents the npc from running away if something triggers it’s fear response.

The second section unfreezes the npc, and then turns the npc to face the player, while the player is in close proximity. This functionality does however allow the npc to flee the area or fight if their fear response is triggered by being attacked or by gunshots in the area.

Tutorial Poll

0
Tutorial - How do I unfreeze an npc and turn them to face the player?

Was this tutorial helpful?

You will be redirected

Relevant Tutorials

By MK