Monster and interaction events

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search

Monster and interaction events

These server-side Lua events expose authoritative monster state changes and normalized player interactions. They are observations of server state; clients do not decide monster health, damage, death, targets, or item rewards.

Monster events

onMonsterSpawn

Triggered after a server-owned monster has been created.

onMonsterSpawn(string monsterId, string monsterType, number x, number y, number z, string sourceResource)
addEventHandler("onMonsterSpawn", root, function(monsterId, monsterType, x, y, z)
    outputDebugString(monsterType .. " spawned as " .. monsterId)
end)

onMonsterDestroy

onMonsterDestroy(string monsterId, string sourceResource)

onMonsterDamage

Triggered after authoritative damage has been accepted.

onMonsterDamage(string monsterId, number damage, number healthAfter, int sourcePlayerId, string damageKind, string sourceResource)
addEventHandler("onMonsterDamage", root, function(monsterId, damage, healthAfter, playerId)
    outputDebugString(monsterId .. " has " .. healthAfter .. " HP remaining")
end)

onMonsterDeath

onMonsterDeath(string monsterId, int killerPlayerId, string sourceResource)

onMonsterTargetChange

onMonsterTargetChange(string monsterId, int oldPlayerId, int newPlayerId, string sourceResource)

onMonsterAttack

Triggered when the server-owned AI resolves a validated attack against a player. The normal player damage and life-state events are emitted separately.

onMonsterAttack(string monsterId, int targetPlayerId, number damage, int actionId)

Interaction events

The common interaction events cover every supported kind. Current specialized kinds are mining and sitting.

onPlayerInteractionState(int playerId, string kind, bool active, string phase, int actionId, int serverStartTimeMs)
onPlayerInteractionStart(int playerId, string kind, int actionId, int serverStartTimeMs)
onPlayerInteractionStop(int playerId, string kind, int actionId, int serverStartTimeMs)

Mining and sitting also emit specialized equivalents:

onPlayerMiningState(int playerId, string kind, bool active, string phase, int actionId, int serverStartTimeMs)
onPlayerMiningStart(int playerId, string kind, int actionId, int serverStartTimeMs)
onPlayerMiningStop(int playerId, string kind, int actionId, int serverStartTimeMs)

onPlayerSittingState(int playerId, string kind, bool active, string phase, int actionId, int serverStartTimeMs)
onPlayerSittingStart(int playerId, string kind, int actionId, int serverStartTimeMs)
onPlayerSittingStop(int playerId, string kind, int actionId, int serverStartTimeMs)

Use start/stop events for edge-triggered rules such as mining rewards. Use GetPlayerInteraction, IsPlayerInteracting, IsPlayerMining, and IsPlayerSitting for current-state queries.

addEventHandler("onPlayerMiningStop", root, function(playerId)
    givePlayerItem(playerId, "ore", 1)
    outputChatBox("You mined one ore nugget.", playerId)
end)