Sign in to follow this  
KZtyler

Logging events into server_log or server_chat_log [Solved]

Recommended Posts

KZtyler    11

Good night to everyone, i'm working on a cool project to make an open source discord bot for dedicated dst servers, my initial goal was to be able to read in-game chat and send it to discord, and also read discord chat and send it to the game using announcements, wich i managed to do successfully.
Now i would like to take it one step further and be able to send certain game events to discord, in order to do that, i need to log those events into some kind of file, wich i will be watching for changes.
Since the game already logs deaths, resurrections, players joining and leaving into server_chat_log.txt, i could use that file.
So basically what i need to do with a server mod is add some events into server_chat_log.txt. For example the game right now logs:

[00:01:23]: [Join Announcement] KZtyler
[00:07:14]: [Leave Announcement] KZtyler

I wish to add

[00:01:23]: [Deerclops Spawned]
[00:07:14]: [Deerclops Killed] by KZtyler

Is adding "custom" events to the log possible, can you point me in some direction?
In advance, thank you very much!

Im sharing with you the github of the discord bot project
https://github.com/ezequielzacca/dont-starve-together-discord-bot
 

Share this post


Link to post
Share on other sites
CarlZalph    3,140

As far as I know anything that uses the print function will print to the logs by default.

Hook prefab spawns by a prefab post init, and check for death by listening for the ondeath event fired from your prefab post init.

Share this post


Link to post
Share on other sites
KZtyler    11
12 hours ago, CarlZalph said:

As far as I know anything that uses the print function will print to the logs by default.

Hook prefab spawns by a prefab post init, and check for death by listening for the ondeath event fired from your prefab post init.

Thank you, its working now:

 

   
local require = GLOBAL.require
  --Bosses that spawn and are aggresive towards players
  local Bosses = {"deerclops", "bearger", "toadstool", "klaus", "stalker_atrium"}
   
  --Bosses that passively roam around the world
  local PassiveBosses = {"dragonfly", "moose", "minotaur", "antlion"}
   
   
  for i,v in ipairs(Bosses) do
  AddPrefabPostInit(v, function(inst)
  print("[Boss Spawned] ", inst)
  inst:ListenForEvent("death", function(inst)
  print("[Boss Killed] ", inst)
  end)
  end)
  end
   
  for i,v in ipairs(PassiveBosses) do
  AddPrefabPostInit(v, function(inst)
  inst:ListenForEvent("death", function(inst)
  print("[Boss Killed] ")
  end)
  end)
  end
   
  AddPrefabPostInit("world", function()
  GLOBAL.TheWorld:ListenForEvent("resetruins", function()
  print("[World Event] Ruins Reset")
  end)
  end)
   
   
   
Do you know if there is a way i can track who killed them? Or even who's been hitting them before they die
Edited by KZtyler

Share this post


Link to post
Share on other sites
Serpens    516

simply search the game code for the specific event. So in case of death, search for - PushEvent("death - with notepas++ in all files. Then you will will see that usually a table of information, like "cause" and other info is provided with all events. This means you ListenForEvent("death",function(inst)... should look like ListenForEvent("death",function(inst,data)... and this data will include the said information

Edited by Serpens

Share this post


Link to post
Share on other sites
KZtyler    11
1 hour ago, Serpens said:

simply search the game code for the specific event. So in case of death, search for - PushEvent("death - with notepas++ in all files. Then you will will see that usually a table of information, like "cause" and other info is provided with all events. This means you ListenForEvent("death",function(inst)... should look like ListenForEvent("death",function(inst,data)... and this data will include the said information

I've looked into the code and it seems that i can easily get who gave the final blow, i guess if i want to get everyone involved in the battle i would have to set a radious and set for all player tagged entities near the dead prefab

EDIT: 
I think i can use FindPlayersInRange to get the list of players near the dead prefab

Edited by KZtyler

Share this post


Link to post
Share on other sites
Serpens    516
55 minutes ago, KZtyler said:

I've looked into the code and it seems that i can easily get who gave the final blow, i guess if i want to get everyone involved in the battle i would have to set a radious and set for all player tagged entities near the dead prefab

EDIT: 
I think i can use FindPlayersInRange to get the list of players near the dead prefab

There are plenty of options. You can also listen for "attacked" and print or remeber this instead. Just search for "PushEvent and you will get al list of all currently existing events. And you can even push your own events. So you can nearly get every info that you can imagine. Although I dont think "print" is what you are looking for. Many mods and other stuff is using print for debugging.

Edited by Serpens

Share this post


Link to post
Share on other sites
KZtyler    11
5 hours ago, Serpens said:

There are plenty of options. You can also listen for "attacked" and print or remeber this instead. Just search for "PushEvent and you will get al list of all currently existing events. And you can even push your own events. So you can nearly get every info that you can imagine. Although I dont think "print" is what you are looking for. Many mods and other stuff is using print for debugging.

Print is good enough for me since i will be filtering what i need from the log, to make it more clear, my bot only reads chat and server logs looking for new entries, then for each entry (line in the file) it filters only the ones that are interesting, then for each one parses them to get some data (for example who died, or who resurrected, or who killed certain boss) and then with that data it sends certain message to discord.
Im actually quite happy with the results :).

I will let you guys know how i implemented it and share here for future references.

Thank you!

Edited by KZtyler

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this