forked from FakeFishGames/Barotrauma
-
Notifications
You must be signed in to change notification settings - Fork 38
Lua Examples
Evil Factory edited this page Sep 3, 2021
·
11 revisions
Hook.Add('chatMessage', 'suicide_mod', function(msg, client)
if msg == '!suicide' and client.Character ~= nil then
client.Character.Kill(CauseOfDeathType.Unknown)
Game.SendMessage(client.name .. ' killed himself!', ChatMessageType.Server)
return true -- hide message
end
end)local characters = Player.GetAllCharacters()
local biteWoundsPrefab
for k, v in pairs(AfflictionPrefab.ListArray) do
if v.name == "Bite wounds" then
biteWoundsPrefab = v
break
end
end
for k, v in pairs(characters) do
v.CharacterHealth.ApplyAffliction(v.AnimController.MainLimb, biteWoundsPrefab.Instantiate(100));
endHook.Add("itemApplyTreatment", "testItemApplyTreatment", function (item, user, character, targetlimb)
if item.name == "Bandage" then
local pos = character.WorldPosition
Game.Explode(pos, 1, 500, 5000, 5000, 5000)
Game.RemoveItem(item)
end
end)-- for example: create an item in xml named RandomComponent and add the wiring inputs/outputs trigger_random and random_out
Hook.Add("signalReceived", "signalReceivedTest", function (signal, connection)
if connection.Item.name == "RandomComponent" and connection.Name == "trigger_random" then
connection.Item.SendSignal(tostring(Random.Range(0, 100)), "random_out")
end
end)local discordWebHook = "your discord webhook here"
local function escapeQuotes(str)
return str:gsub("\"", "\\\"")
end
Hook.Add("chatMessage", "discordIntegration", function (msg, client)
local escapedName = escapeQuotes(client.name)
local escapedMessage = escapeQuotes(msg)
Networking.RequestPostHTTP(discordWebHook, '{\"content\": \"'..escapedMessage..'\", \"username\": \"'..escapedName..'\"}')
end)local enabledPackages = Game.GetEnabledContentPackages()
local shouldRun = false
for key, value in pairs(enabledPackages) do
if value.Name == "MyContentPackage" then
shouldRun = true
end
end
if not shouldRun then
-- make your code stop
end