Hi there,
I would like to create a script where I can spawn some angry NPCs next to a Player with ServerID xy
Therefore I dir “RegisterCommand(‘spawnbadnpc’, function(source, args)” and tried to read it using “args[1]”
To get the NPCs angry I added the hash - but it seems not working at all.
I used “GetHashKey(“PLAYER”)” before. But this gets the NPC angry at any player. This is not what I want to achieve. (But this is working)
I want to get the NPC angry at this special ID i use as an argument. Thats what I did:
SetRelationshipBetweenGroups(5, relgrp, GetHashKey(GetPlayerPed(GetPlayerFromServerId(args[1]))))
Maybe someone else got this running but I did not find it yet.
Wrong video this is the right one https://youtu.be/G6QJQHXUnTc
Thank you, but this is setting relation between a whole group. I just want to assign the attack group to one single Player by the PlayerID I put in my argument
Look in the fivem natives. You can use 0xF166E48407BAC484 (TaskCombatPed). I am not sure if the ped has a red blip on the map but you could try it.
Also you can’t do that
SetRelationshipBetweenGroups(5, relgrp, GetHashKey(GetPlayerPed(GetPlayerFromServerId(args[1]))))
because GetPlayerPed(GetPlayerFromServerId(args[1]))
is not a group.
Ah okay - I assumed something like that. I tried
TaskCombatPed(badPed, GetPlayerPed(GetPlayerFromServerId(playerId)), 0, 16)
now, but all I got is that the ped is looking at me doing nothing. It’s a little strange. Maybe its not coded that peds attack single players instead of player groups.
Is the code executed in the client or in the server side?
Client. Ped (dog) is staring at me and barking. But does not move towards me
Is the ped (dog) and the player defined in the code? I am not sure if GetPlayerPed(GetPlayerFromServerId(playerId))
is working. Try using GetPlayerPed(-1)
?!
Heres the full code:
RegisterCommand("baddogs", function(source, args)
local _,relgrp = AddRelationshipGroup('DOGGYGANG')
local badpuppies = {
{name= "a", model = 1126154828},
{name= "b", model = -1788665315},
{name= "c", model = 882848737},
{name= "d", model = 1832265812},
{name= "e", model = 1125994524},
}
local pos = GetOffsetFromEntityInWorldCoords(GetPlayerPed(args[0]), 0.0, 10.0, 0.0)
local direction = GetEntityHeading(GetPlayerPed(-1))+180
local playerId = tonumber(args[1])
local amount = tonumber(args[2])
local pupId = nil
for number = 1, amount do
pupId = math.random(1, #badpuppies)
local hashkey = badpuppies[pupId].model
RequestModel(hashkey)
while not HasModelLoaded(hashkey) do Citizen.Wait(0) end
local easyPed = CreatePed(5, hashkey, pos.x, pos.y-math.random(1,10), pos.z, direction, true, false)
-- SetPedRelationshipGroupHash(easyPed, relgrp)
-- Citizen.Wait(500)
-- SetRelationshipBetweenGroups(5, relgrp, GetHashKey("PLAYER"))
-- SetRelationshipBetweenGroups(5, relgrp, GetHashKey("CIVMALE"))
-- SetRelationshipBetweenGroups(5, relgrp, GetHashKey("CIVFEMALE"))
-- SetRelationshipBetweenGroups(5, relgrp, GetHashKey("CAT"))
print("PlayerID: " .. playerId)
print("Amount: " .. amount)
ClearPedTasks(easyPed)
--TaskWanderStandard(easyPed, 1.0, 10)
TaskCombatPed(easyPed, GetPlayerPed(GetPlayerFromServerId(playerId)), 0, 16)
end
end, false)
I edited my previous post. Did you try using GetPlayerPed(-1)?
Yes, no difference. The dog is still staring at me and moving around on the spot when I walk next to him
Looks like theres something missing like “ExecuteTask” or something to get the dog running against me.
I have no way of testing it right now. My last idea is to first set the dog as enemy SetPedAsEnemy
and then make the dog attack the player.
No effect - but thank you for your patience and helping me to find out whats wrong. Maybe I get clue later. Late here, will go to bed for now.
Thank you!
Tomorrow I will be able to test some code and try to help you out.
1 Like
Hello again. I was able to solve your issue. I don’t code in lua and thats why my script is in javascript. This code is running fine and the dog is attacking the player:
RegisterCommand("test", async (source, args, rawCommand)=>{
let dogModel = 882848737
let player = GetPlayerPed(-1)
let loc = GetEntityCoords(player, true)
let [pX, pY, pZ] = loc
RequestModel(dogModel)
let wait = 0
while(!HasModelLoaded(dogModel)){
wait = wait + 100
await rpme.functions.sleep(10);
if(wait > 10000){
return
}
}
let dogPed = CreatePed(5, dogModel, pX, pY, pZ, 0, true, false)
ClearPedTasks(dogPed)
SetPedAsEnemy(dogPed, true)
TaskCombatPed(dogPed, player)
})
If you need help to translate it in lua just tell me.
PS: The only problem is when the player enters a car, the dog doesn’t follow or attack him even after he exits the car
1 Like
If you want the dog ped to appear on the map use SetPedHasAiBlip(dogPed, true)
Thank you! At last I had to change/add one line to get it running. And some dogs do not attack at all. (poodle, tug) - maybe thats also one hint why this happend.
Now its working properly. I tried out the SetPedHasAiBlip but there was still some nil exception. I will check this later. Thank you very much for your help. This is real community behavior!
Also SetPedHasAiBlip(dogPed, true)
makes some dogs look like police on the radar. I haven’t solve this yet. If you solve it please describe how to do so.