altv-issues icon indicating copy to clipboard operation
altv-issues copied to clipboard

Event when remote player is respawned clientside

Open Hardy535 opened this issue 3 years ago • 1 comments

Description of the problem

When a remote player is respawned while streamed in for the local player, there is no event to catch that.

This results in a problem that when we need to do something clientsided with the player after he respawned, we have no way to even know that he respawned.

gameEntityCreate, gameEntityDestroy and removeEntity are not triggering which could be used to work around this problem.

Desired solution for the problem

Add a "spawned" clientside event for remote players (like we already have for the local player).

Alternatives you considered

No response

Additional context

No response

Version

build #12.11, branch release

Hardy535 avatar Oct 07 '22 00:10 Hardy535

I guess you are trying to sync something, that is not synced by default. You can use steamSyncedMeta and just set it to true. Even if the same value is set, as it was before, the streamSyncedMetaChange event gets called

TheGodlyLuzer avatar Oct 07 '22 08:10 TheGodlyLuzer

~~An alternative clientside solution could be checking scriptID of remote players in some interval~~ scriptID only updates on player model changes, thats why it seems to be impossible to know when player is respawned now from clientside

const prevScriptIDs = new Map()

alt.setInterval(() => {
  for (const [player, prevScriptID] of prevScriptIDs) {
    const currentScriptID = player.scriptID
    if (prevScriptID === currentScriptID) return
    
    prevScriptIDs.set(player, currentScriptID)
    alt.emit('remotePlayerScriptIDChange', player)
  }
}, 500)

// remote player enters stream range
alt.on('gameEntityCreate', (player) => {
  if (!(player instanceof alt.Player)) return
  prevScriptIDs.set(player, player.scriptID)
})

// if remote player is no longer in stream we dont need their scriptID
alt.on('gameEntityDestroy', (player) => {
  if (!(player instanceof alt.Player)) return
  prevScriptIDs.delete(player)
})

Usage:

alt.on('remotePlayerScriptIDChange', (player) => {
  // set some ped flags again or other shit
})

xxshady avatar Oct 31 '22 07:10 xxshady

An alternative clientside solution could be checking scriptID of remote players in some interval (contact me if this code doesn't work, didn't tested it yet)

const prevScriptIDs = new Map()

alt.setInterval(() => {
  for (const [player, prevScriptID] of prevScriptIDs) {
    const currentScriptID = player.scriptID
    if (prevScriptID === currentScriptID) return
    
    prevScriptIDs.set(player, currentScriptID)
    alt.emit('remotePlayerScriptIDChange', player)
  }
}, 500)

// remote player enters stream range
alt.on('gameEntityCreate', (player) => {
  if (!(player instanceof alt.Player)) return
  prevScriptIDs.set(player, player.scriptID)
})

// if remote player is no longer in stream we dont need their scriptID
alt.on('gameEntityDestroy', (player) => {
  if (!(player instanceof alt.Player)) return
  prevScriptIDs.delete(player)
})

Usage:

alt.on('remotePlayerScriptIDChange', (player) => {
  // set some ped flags again or other shit
})

I think I've already tried this and sadly the scriptID is not changing when the player is respawning for remote players as he is not streaming out/in.

Hardy535 avatar Nov 01 '22 04:11 Hardy535

@Hardy535 just tested, scriptID only changes on player model change, so no clientside-only solution

xxshady avatar Nov 01 '22 16:11 xxshady