Hi first of all. Sorry, I tried creating a topic in another category but I wasnt allowed to do so :(.
I am making a copchase server where you can start a event called copchase and people can join. Everything works just fine. There are shops that can be robbed etc.
At first I made a /rob command for the robber to rob a store. But I wanted to make it better by spawning in NPCs on the server side like so (which works):
local shopKeeperLocations = {{loc = vector3(26.49102, -1345.805, 29.49702), name = "South LS Convenient store", isRobbed = false, maxCash = 5000, ped = nil, model = "mp_m_shopkeep_01", heading = 0.0}, {loc = vector3(146.6646, -1044.801, 29.37783), name = "Bank", isRobbed = false, maxCash = 10000, ped = nil, model = "s_f_y_airhostess_0", heading = 0.0},
{loc = vector3(22.53048, -1106.929, 29.79703), name = "Central LS Ammunation", isRobbed = false, maxCash = 7500, ped= nil, model = "s_m_y_ammucity_01", heading = 0.0}, {loc = vector3(130.2697, -1285.411, 29.27999), name = "Stripclub", isRobbed = false, maxCash = 35000, ped = nil, model = "s_f_y_bartender_01", heading = 0.0},
{loc = vector3(-48.60311, -1756.754, 29.42101), name = "Davis Gas station", isRobbed = false, maxCash = 5000, ped = nil, model = "mp_m_shopkeep_01", heading = 0.0}, {loc = vector3(841.8622, -1033.938, 28.19485), name = "East LS Gun shop", isRobbed = false, maxCash = 5000, ped = nil, model ="s_m_y_ammucity_01", heading = 0.0},
for index, value in ipairs(shopKeeperLocations) do
local ped = CreatePed(1, value.model, value.loc.x, value.loc.y, value.loc.z, value.heading, true, true)
value.ped = ped
FreezeEntityPosition(ped, true)
end
RegisterNetEvent("CallForShopkeepers")
AddEventHandler("CallForShopkeepers", function ()
TriggerClientEvent("GetShopKeepers", source, shopKeeperLocations)
end)
The CallForShopkeepers event will be called by clients once they join the server so they have access to the NPCs that are spawned in on the server side.
Two things dont work, or work halfway:
-
The native FreezeEntityPosition(ped, true) seems to work sometimes. Sometimes the npcs run in place when you aim a gun on them (which is fine) but, the other time they just run away while they should have been frozen.
-
I tried to make these npcs invincible using the native: SetEntityInvincible(value.ped, true)
This native is called once on the client for all the spawned npcs in the array shopKeeperLocations once the players spawn into the server. However when the client shoots at the npcs they still die.
Client side script:
RegisterNetEvent('GetShopKeepers')
AddEventHandler('GetShopKeepers', function(shopKeepers)
print("Setting up shopkeepers")
robberyLocations = shopKeepers
end)
AddEventHandler('MakeNPCInvincible', function()
print("MakingPedsInvincible")
for index, value in ipairs(robberyLocations) do
SetEntityInvincible(value.ped, true)
end
end
end)
MakeNPCInvincible event is called once, when the players spawn in for the first time. Also the prints are being printed so I can safely say they reach that block of code and when I tried printing the peds in the array they also seem to be there and not nil or something ^^.
Anyone have an idea why it wont work? Also sorry if it may be a bit confusing, first time trying to get help .
Thanks in advance!