Jump to content
RAGE Multiplayer Community

Changing ped properties after spawning


pan7nikt
 Share

Recommended Posts

Hi,

I was trying to spawn a ped using a command and then make it invincible. The ped spawns normally, but using the setInvincible method returns an error:

"TypeError: dynamicPed.setInvincible is not a function"

Here is my code:

mp.events.addCommand("ped", (player) => {
    let dynamicPed = mp.peds.new(mp.joaat('mp_m_freemode_01'), player.position, {dynamic:true});
    dynamicPed.controller = player;
    dynamicPed.RelationshipGroupHash = 0x84DCFAAD;
    dynamicPed.setInvincible(true);
})

I know that adding 

invincible:true

to the 2nd line works, but i wanted to do it using the setInvincible() function.

Perhaps it is not possible to use this method on server side?
I have also tried other functions and none of them are working.

I also tried to do it like that:

dynamicPed.invincible = true

and it doesn't give me an error but it also doesn't work.

Does anyone know what is wrong here and how to fix it?

 

Thanks in advance!

Edited by pan7nikt
Link to comment
Share on other sites

  • pan7nikt changed the title to Changing ped properties after spawning

It seems that the method exists only on Clientside. I ended up passing it from the server through an event like this:

Serverside:

mp.events.addCommand("ped", (player) => {
    let dynamicPed = mp.peds.new(mp.joaat('s_m_y_swat_01'), player.position, {dynamic:true});
    dynamicPed.controller = player;
    dynamicPed.RelationshipGroupHash = 0x84DCFAAD;
  
    player.call(`setPedBehavior`, [dynamicPed]);
})

Clientside:
 

mp.events.add('setPedBehavior',(ped) => {
    ped.setInvincible(false);
})

Although I don't think it will synchronize for other players, so it still might not be the proper way to do it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...