Uchu icon indicating copy to clipboard operation
Uchu copied to clipboard

Python scripting: OnHealth player becomes a GameObject after Stromling attack

Open enteryournamehere opened this issue 3 years ago • 2 comments

The referenced source-game-object in the listener function passed to OnHealth and OnDeath in a python script is a GameObject rather than a Player when the last negative health update was caused by damage from a Stromling. This results in the inability to get player info like their name, and to send a chat message to them. On subsequent health updates, such as by healing from a consumable, respawning or picking up a heart, the referenced object stays a GameObject. After being damaged by a Mech or Spider Queen, it once again becomes a Player, and stays like this for all updates until a Stromling attacks again.

Python script

# (b) means the message was broadcasted
def handleHealth(health, delta, player):
    Broadcast("[py] (b) Health update for " + type(player).__name__ + " " + player.Name)
    Broadcast("[py] (b) Delta:" + str(delta) + ", health: " + str(health))
    Chat(player, "[py] Your health just got updated")

def handleChat(player, message):
    Chat(player, "[py] Received chat: " + message)

def handleDeath(player):
    Broadcast("[py] (b) A " + type(player).__name__ + " was smashed")
    Chat(player, "[py] You were smashed")

def load():
    OnChat(handleChat)
    for player in Zone.Players:
        ref_health = OnHealth(player, handleHealth)
        Chat(player, "[py] Loaded!")
        OnDeath(player, handleDeath)

LU chat output

Getting attacked and killed by a stromling (note the absence of non-broadcast messages, as sending a chat message to a GameObject is impossible):

[py] (b) Health update for GameObject 
[py] (b) Delta: -1, health: 0
[py] (b) A GameObject was smashed

When respawning:

[py] (b) Health update for GameObject
[py] (b) Delta: 4, health: 4

Getting attacked and killed by a Mech or by the Spider Queen:

[py] (b) Health update for Player MusicalMarbleMachine
[py] (b) Delta: -1, health: 0
[py] Your health just got updated
[py] (b) A Player was smashed
[py] You were smashed

When respawning:

[py] (b) Health update for Player MusicalMarbleMachine
[py] (b) Delta: 4, health: 4
[py] Your health just got updated

I'm running Uchu built from the latest source.

enteryournamehere avatar Sep 28 '20 22:09 enteryournamehere

This is correct as regular game objects still have the stats component (I think at least), there ideally should be a way to convert between the player and game object using a function. I will look into this later.

Jettford avatar Sep 30 '20 08:09 Jettford

As you have pointed out, this only occurs with Stromlings specifically.

If I recall correctly, Python is the secondary scripting language, meant for things like custom minigames (example being something like Prop Hunt).

This will definitely be something that will get looked at, but it probably won't be a very high priority.

elenawinters avatar Sep 30 '20 11:09 elenawinters