renamed hooks (with compatibility), added new hook: character.giveJobItems (because of how often its used) and updated hook docs

This commit is contained in:
Evil Factory
2022-05-17 12:24:52 -03:00
parent fd6b833c98
commit cf500081d1
6 changed files with 51 additions and 16 deletions

View File

@@ -25,7 +25,7 @@ namespace Barotrauma
GameServer.Log(GameServer.CharacterLogName(this) + " has died (Cause of death: " + causeOfDeath + ")", ServerLog.MessageType.Attack);
}
}
GameMain.LuaCs.Hook.Call("characterDeath", this,causeOfDeathAffliction);
GameMain.LuaCs.Hook.Call("character.death", this,causeOfDeathAffliction);
if (HasAbilityFlag(AbilityFlags.RetainExperienceForNewCharacter))
{

View File

@@ -293,7 +293,7 @@ namespace Barotrauma.Networking
SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
}
GameMain.LuaCs.Hook.Call("clientConnected", newClient);
GameMain.LuaCs.Hook.Call("client.connected", newClient);
SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null, changeType: PlayerConnectionChangeType.Joined);
@@ -2899,7 +2899,7 @@ namespace Barotrauma.Networking
{
if (client == null) return;
GameMain.LuaCs.Hook.Call("clientDisconnected", client);
GameMain.LuaCs.Hook.Call("client.disconnected", client);
if (gameStarted && client.Character != null)
{

View File

@@ -76,4 +76,20 @@ end
compatibilityLib["Player"] = luaPlayer
Hook.Add("character.created", "compatibility.character.created", function (character)
Hook.Call("characterCreated", character)
end)
Hook.Add("character.death", "compatibility.character.death", function (character, causeOfDeathAffliction)
Hook.Call("characterDeath", character, causeOfDeathAffliction)
end)
Hook.Add("client.connected", "compatibility.client.connected", function (client)
Hook.Call("clientConnected", client)
end)
Hook.Add("client.disconnected", "compatibility.client.disconnected", function (client)
Hook.Call("clientDisconnected", client)
end)
return compatibilityLib

View File

@@ -80,7 +80,7 @@ namespace Barotrauma
public void AddObjective<T>(T objective) where T : AIObjective
{
var result = GameMain.LuaCs.Hook.Call<bool?>("AI.AddObjective", this, objective);
var result = GameMain.LuaCs.Hook.Call<bool?>("AI.addObjective", this, objective);
if (result != null && result.Value) return;

View File

@@ -1043,7 +1043,7 @@ namespace Barotrauma
}
#endif
GameMain.LuaCs.Hook.Call("characterCreated", new object[] { newCharacter });
GameMain.LuaCs.Hook.Call("character.created", new object[] { newCharacter });
return newCharacter;
}
@@ -1441,6 +1441,8 @@ namespace Barotrauma
{
if (info?.Job == null) { return; }
info.Job.GiveJobItems(this, spawnPoint);
GameMain.LuaCs.Hook.Call("character.giveJobItems", this, spawnPoint);
}
public void GiveIdCardTags(WayPoint spawnPoint, bool createNetworkEvent = false)

View File

@@ -25,7 +25,7 @@ function Hook.Add(eventName, hookName, func) end
-- @tparam string hookname hook name
-- @realm shared
-- @usage
-- Hook.Remove("characterDeath", "characterDeathExample")
-- Hook.Remove("character.death", "characterDeathExample")
function Hook.Remove(eventName, hookName) end
--- Calls a hook.
@@ -34,7 +34,7 @@ function Hook.Remove(eventName, hookName) end
-- @realm shared
-- @usage
-- Hook.Add("think", "happyDebuggingSuckers", function()
-- Hook.Call("characterDead", {}) -- ruin someone's day
-- Hook.Call("character.death", {}) -- ruin someone's day
-- end)
function Hook.Call(eventName, parameters) end
@@ -62,12 +62,13 @@ function chatMessage(message, sender) end
--- Called when a client connects
-- @tparam client connectedClient
-- @realm shared
function clientConnected(connectedClient) end
function client.connected(connectedClient) end
--- Called when a client disconnects
-- @tparam client disconnectedClient
-- @realm shared
function clientDisconnected(disconnectedClient) end
function client.disconnected(disconnectedClient) end
--- Called on round start
-- @realm shared
@@ -77,23 +78,35 @@ function roundStart() end
-- @realm shared
function roundEnd() end
--- Gets callled everytime a character is created.
--- Gets called everytime a character is created.
-- @tparam character createdCharacter
-- @realm shared
function characterCreated(createdCharacter) end
function character.created(createdCharacter) end
--- Gets called after the character is given the job items, useful if your script only wants to check for newly created characters in campaign gamemode.
-- @tparam character character
-- @tparam WayPoint waypoint
-- @realm shared
function character.giveJobItems(character, waypoint) end
--- Gets called everytime a Character dies.
-- @tparam Character character A dead Character.
-- @realm shared
-- @usage
-- Hook.Add("characterDeath", "characterDeathExample", function(character)
-- Hook.Add("character.death", "characterDeathExample", function(character)
-- print(character)
-- end)
function characterDeath(character) end
function character.death(character) end
--- Gets called every time an affliction is applied.
--- Gets called every time an affliction is applied to a character.
-- @realm shared
function afflictionApplied(affliction, characterHealth, limb) end
function character.applyAffliction(character, limbHealth, newAffliction, allowStacking) end
--- Gets gets called every time an attack damage.
-- @realm shared
function character.applyDamage(character, attackResult, hitLimb, allowStacking) end
--- Gets called every time an affliction updates.
-- @realm shared
function afflictionUpdate(affliction, characterHealth, limb) end
@@ -125,7 +138,11 @@ function item.interact(item, characterPicker, ignoreRequiredItemsBool, forceSele
--- Gets called every time two items are combined, eg: drag an half empty magazine to another half empty magazine to combine
-- @realm shared
function item.combine(item, otherItem, userCharacter) end
function item.combine(item, deconstructor, characterUser, allowRemove) end
--- Gets called every time an item is deconstructed. Return true to prevent item from being removed.
-- @realm shared
function item.deconstructed(item, otherItem, userCharacter) end
--- Gets called every time an item is moved from one inventory slot to another, return true to cancel
-- @realm shared