Players not taking damage with weapons

I’m having a bit of trouble trying to figure out how to get players to be able to damage each other.

I am using a stock fivem server install with only a single resource to give myself a weapon.

I am using the:

Citizen.CreateThread(function()
-- Enable PVP

  NetworkSetFriendlyFireOption(true)

  SetCanAttackFriendly(playerPed, true, false)

end)

thread to enable PVP. I can aim and shoot other players players, but when I hit them it does no damage no matter what weapon I use. Blood spatters, they do impact movements, but their health never depletes.

Is there another native somewhere I need to invoke so that players can damage each other?

I’ve had this issue once and then it was the server artifact have you tried the latest recommended artifact?

Thats one thing I didnt try, although I used the cfx profiler about a week ago to setup the server so I shouldn’t be too out of date from recommended. Ill try to update either way.

Updating the artifact did not help any. I feel there may be a native I missed somewhere.

Can you post the code for this resource, too?

Either there’s some damage routing issue somewhere, or you’ve inadvertently hit some invulnerability scenario in script. :stuck_out_tongue:

It’s a simple resource with just a couple of lines of code:

RegisterCommand('giveweapon',function(args, rawComand) 
   GiveWeaponToPed(PlayerPedId(), GetHashKey(args[1]), 25, false, false)
  _, equippedWeapon = GetCurrentPedWeapon(PlayerPedId())
end)

Then in client console (or chat) I use

/equip weapon_combatpistol

That’s all it is. I get the weapon in the weapon wheel, and I can select it and equip it, but can’t do any damage with it.

Hi,
If you do not specify a playerPed, replace it:

SetCanAttackFriendly(playerPed, true, false)

to

SetCanAttackFriendly(PlayerPedId(), true, false)

Sorry, I inadvertently left that part of the code out. I use this to specify the player ped:

local playerPed = GetPlayerPedId()

Change GetPlayerPedId() to PlayerPedId()

There are no such native:
GetPlayerPedId()

What is still possible (although rather the first):
GetPlayerPed(-1)

Right. Any particular non-default options in your server launch configuration that aren’t usually present in the example in the docs? (game build, different OneSync mode, etc.)

I just tried this usual setup and it seemed to work fine :confused:

I used the profiler with the default cfx profile, if that is what you mean. Other than that, no. There is another custom resource that I am working (where the code originally came from), but it’s disabled for now and I have the code in just a basic resource

Hmm, interesting. Not sure what I did other than look at the code, but it seems to be working now?

BAHAHAHA IM STUPID! I had a random SetEntityInvincible() in a thread it’s not supposed to be in. Everything seems to be working now.

1 Like

where did you find this