player entity
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
player entity
I have been working on a mod that allows a player to have multiple bodies and switch between them.
The, awkward thing to work around is the difference in the way the player entity is treated on death if it is connected to a player, or isn't.
For example... If the player is connected to an entity when it dies... on_pre_player_died is called, then the entity is deleted with a "dead player chest" created in it's place, then on_player_died is called, and the player enters the ghost respawn phase.
Also when you log off, this entity disappears and is restored when they player returns.
If the player isn't connected... the entity is deleted and on_entity_died is called (Giving no opertunity to check inventories, or create a "dead player chest")
Also this entity persists in the world if the player is connected or not.
What I would like is an interface to change these rules a little.
what if I don't want to enter a respawn phase, and want to switch to one of the other entities instead? (if at least one other exists) (likely controlled by an on_player_died script)
what if I want a killed player entity that isn't currently controlled by a player to also drop a "dead player chest" (Either a flag I can set to do this automatically, or an on_pre_entity_died call along with an option to create a dead inventory chest call)
what if I want player entities that arn't currently controlled to disappear when their associated player logs off, and return when the player rejoins.
Is there any possibility you could add support for and of this in the next version?
The, awkward thing to work around is the difference in the way the player entity is treated on death if it is connected to a player, or isn't.
For example... If the player is connected to an entity when it dies... on_pre_player_died is called, then the entity is deleted with a "dead player chest" created in it's place, then on_player_died is called, and the player enters the ghost respawn phase.
Also when you log off, this entity disappears and is restored when they player returns.
If the player isn't connected... the entity is deleted and on_entity_died is called (Giving no opertunity to check inventories, or create a "dead player chest")
Also this entity persists in the world if the player is connected or not.
What I would like is an interface to change these rules a little.
what if I don't want to enter a respawn phase, and want to switch to one of the other entities instead? (if at least one other exists) (likely controlled by an on_player_died script)
what if I want a killed player entity that isn't currently controlled by a player to also drop a "dead player chest" (Either a flag I can set to do this automatically, or an on_pre_entity_died call along with an option to create a dead inventory chest call)
what if I want player entities that arn't currently controlled to disappear when their associated player logs off, and return when the player rejoins.
Is there any possibility you could add support for and of this in the next version?
Re: player entity
I've changed it in 0.16 so a character entity dying will also create the corpse.
As for the other things you mentioned: I need more detail on what exactly you think would be useful changes.
As for the other things you mentioned: I need more detail on what exactly you think would be useful changes.
If you want to get ahold of me I'm almost always on Discord.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: player entity
Taking it as I have asked for 3 things...
Point number 2 is the one you've done, thank you.
Point number 1.
I'd also like to be able to invoke the spawning screen at will.
Also a point of interest, when you set defines.controllers.ghost, the player can still "Explore", and reveal the map in the process... it probably shouldn't be revealing the map.
Point number 3.
What I would like is some way of setting a character entity, not currently controlled by a player, to offline (and therefore disappear from the map) in an on_player_left_game script of their associated player, and back to online in an on_player_joined_game script. Basically turn them into an invisible intangible ghost and back on these events. I'm not really too bothered on what the code to do this actually looks like, but something along the lines of entity.online(false) when the player logs off, to hide it from the map, then entity.online(true) to turn it back on again when the player reconnects.
It should most likely change the entity to a state where the only way you can interact with it at all is to set entity.online(true)
Point number 2 is the one you've done, thank you.
Point number 1.
Actually... I can't remember if I tried this or not, but what I would like is if on on_player_died I set player.character to an entity (which changes also player.set_controller.type to defines.controllers.character), that it dismisses the respawning screen, and just gives the player control again.I don't want to enter a respawn phase, and want to switch to one of the other entities instead? (if at least one other exists) (likely controlled by an on_player_died script)
I'd also like to be able to invoke the spawning screen at will.
Also a point of interest, when you set defines.controllers.ghost, the player can still "Explore", and reveal the map in the process... it probably shouldn't be revealing the map.
Point number 3.
Basically... you create multiple bodies and can switch between them. But the only one considered to be YOU, is the one you're currently using. So it disappears from the map when you log off, but the others remain. This might be some remote controlled body, now I can't even use a on_player_left_game script switch back to their main body, so that it disappears when they log off because it's called after they leave, rather than before (would need on_pre_player_left_game), but regardless, all other bodies remain on the map, vulnerable, and possibly in the way of other players.I want player entities that aren't currently controlled by a player to disappear when their associated player logs off, and return when the player rejoins.
What I would like is some way of setting a character entity, not currently controlled by a player, to offline (and therefore disappear from the map) in an on_player_left_game script of their associated player, and back to online in an on_player_joined_game script. Basically turn them into an invisible intangible ghost and back on these events. I'm not really too bothered on what the code to do this actually looks like, but something along the lines of entity.online(false) when the player logs off, to hide it from the map, then entity.online(true) to turn it back on again when the player reconnects.
It should most likely change the entity to a state where the only way you can interact with it at all is to set entity.online(true)
Re: player entity
Ok, how does this sound:
If during the on_pre_player_died event the character entity is destroyed or the health is set to some positive value the game will abort the death event and print nothing to the game chat. That way, you can detect the event - the character is still valid to interact with/transfer items, and you can switch the player over to some other character and destroy the old one to tell the game that a non-normal death happened.
If during the on_pre_player_died event the character entity is destroyed or the health is set to some positive value the game will abort the death event and print nothing to the game chat. That way, you can detect the event - the character is still valid to interact with/transfer items, and you can switch the player over to some other character and destroy the old one to tell the game that a non-normal death happened.
If you want to get ahold of me I'm almost always on Discord.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: player entity
So... during the on_pre_player_died event I set the new character entity.
Player switchs to new character with no death scene.
Old Character entity dies as normal, and drops a chest, but I can access the dying character before this happens.
Sounds good to me.
What about point #3?
Player switchs to new character with no death scene.
Old Character entity dies as normal, and drops a chest, but I can access the dying character before this happens.
Sounds good to me.
What about point #3?
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: player entity
For Point 1 wouldn't it be easier to have something like:Rseding91 wrote:Ok, how does this sound:
If during the on_pre_player_died event the character entity is destroyed or the health is set to some positive value the game will abort the death event and print nothing to the game chat. That way, you can detect the event - the character is still valid to interact with/transfer items, and you can switch the player over to some other character and destroy the old one to tell the game that a non-normal death happened.
LuaPlayer.respawn_time_remaining(time) [r/w]
time:: uint: The remaining amount of ticks until the player is automatically respawned. If this is set to 0 (-1?) then the the respawn popup will disappear but respawning will not happen. Set to 1 (0?) to "instantly" respawn the player the next tick. [alternatively time could be the absolute game.tick when respawn occurs and when it's set to a tick that already passed nothing happens.]
That way it allows both to arbitrarily start or stop the respawn timer like bob seems to require. (Because i think he might still want the corpse in the example you just gave.)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: player entity
I've added support for associated characters on players for 0.16:
changelog wrote:Added support for player associated characters - characters that get logged off/on with a given player but aren't directly controlled by the player.
If you want to get ahold of me I'm almost always on Discord.
Re: player entity
I also Added LuaPlayer::ticks_to_respawn read/write for 0.16.
If you want to get ahold of me I'm almost always on Discord.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: player entity
So, to summarise.
all character entities will now drop a dead body chest, regardless of if they're connected to a player or not.
death respawn timer can be modified to clear respawning timer instantly so that I can switch to an existing spare body rather than the player respawning as normal.
And character entities can have an associated player set, and if they do, will vanish and reappear on player log off/on, as the player controlled character does.
Thank you very much for your efforts.
all character entities will now drop a dead body chest, regardless of if they're connected to a player or not.
death respawn timer can be modified to clear respawning timer instantly so that I can switch to an existing spare body rather than the player respawning as normal.
And character entities can have an associated player set, and if they do, will vanish and reappear on player log off/on, as the player controlled character does.
Thank you very much for your efforts.
Re: player entity
Yep, although setting the respawn timer to nil will cause the normal respawn to happen. If you simply attach a new character to a currently respawning player it will clear it and resume normal operation with that new character. So, which ever you want to happen do that.bobingabout wrote:So, to summarise.
all character entities will now drop a dead body chest, regardless of if they're connected to a player or not.
death respawn timer can be modified to clear respawning timer instantly so that I can switch to an existing spare body rather than the player respawning as normal.
And character entities can have an associated player set, and if they do, will vanish and reappear on player log off/on, as the player controlled character does.
Thank you very much for your efforts.
If you want to get ahold of me I'm almost always on Discord.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: player entity
so, is dead, on_pre_player_died triggers, set new character entity, continue as normal. Got it.