CrescentMage Posted November 14, 2017 Share Posted November 14, 2017 (edited) I'm working on a character mod for Don't Starve Together. The command that I need help with is a code that will allow the character -If they are dead- to respawn at the start of the next day. I think I have the right idea with the code, just not the proper set up. Please assist! (Code highlighted in image) Edited November 14, 2017 by CrescentMage Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/ Share on other sites More sharing options...
Serpens Posted November 14, 2017 Share Posted November 14, 2017 (edited) the whole highlighted code is simply completely wrong placed and form. When you want to use something that is already used by the game, you first search the game files and see how it is done there. Then at least the form will be correct. So I suggest that you study game files first.. So use notepad++ to search eg for ListenForEvent("death" and see how it is used. (you will never see it with "local function inst:Listen.." eg). And you will notice that when you open a "function()" you need at least "inst" in those brackets, or sometimes even more. And you need to close the function somewhere, so some "end" are missing in your code. And of course the place in modmain looks very strange. Usually you put it in your masterposinit function. Edited November 14, 2017 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974325 Share on other sites More sharing options...
CrescentMage Posted November 14, 2017 Author Share Posted November 14, 2017 26 minutes ago, Serpens said: the whole highlighted code is simply completely wrong placed and form. When you want to use something that is already used by the game, you first search the game files and see how it is done there. Then at least the form will be correct. So I suggest that you study game files first.. So use notepad++ to search eg for ListenForEvent("death" and see how it is used. (you will never see it with "local function inst:Listen.." eg). And you will notice that when you open a "function()" you need at least "inst" in those brackets, or sometimes even more. And you need to close the function somewhere, so some "end" are missing in your code. And of course the place in modmain looks very strange. Usually you put it in your masterposinit function. I couldn't find a masterposinit function anywhere in the script. Where might that be located? Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974331 Share on other sites More sharing options...
Serpens Posted November 14, 2017 Share Posted November 14, 2017 2 minutes ago, CrescentMage said: I couldn't find a masterposinit function anywhere in the script. Where might that be located? I meant the "master_postinit" that is also shown in your screenshot. Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974332 Share on other sites More sharing options...
CrescentMage Posted November 14, 2017 Author Share Posted November 14, 2017 Just now, Serpens said: I meant the "master_postinit" that is also shown in your screenshot. Ooooh ok, I see it now. Can you explain how to insert it properly there? Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974334 Share on other sites More sharing options...
Serpens Posted November 14, 2017 Share Posted November 14, 2017 24 minutes ago, CrescentMage said: Ooooh ok, I see it now. Can you explain how to insert it properly there? no, I already wrote what is wrong with yours. And you have hundreds of examples in game code Just search the game files for ListenForEvent. You have to learn how to find out such things on your own Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974338 Share on other sites More sharing options...
CrescentMage Posted November 14, 2017 Author Share Posted November 14, 2017 14 minutes ago, Serpens said: no, I already wrote what is wrong with yours. And you have hundreds of examples in game code Just search the game files for ListenForEvent. You have to learn how to find out such things on your own Aw darn. Well the script here doesn't have any ListenForEvent ("death" anywhere. It does, however, have ListenForEvent ("ms_becameghost", onbecameghost) followed by an If-Then-Else. That's about all I'm finding for ListenForEvent commands. Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974343 Share on other sites More sharing options...
Serpens Posted November 14, 2017 Share Posted November 14, 2017 yes you can use this example, or find hundred more (when only searching for ListenForEvent, not mandatory "death") by using the search of notepad++ over all .lua files, see here how to do it:https://forums.kleientertainment.com/topic/73989-tutorial-basics-what-to-use-to-open-lua-files-and-why/#comment-865955 But you can also use this on ms_becameghost example I think. When searching for it I found it eg in wolfgang.lua. There you will also see alot of other ListenForEvent examples. So lets take a look at those which are located in wolfgang.lua in the master_postinit (but all work very similar). There is only one line: inst:ListenForEvent("mounted", OnMounted) So you do the same with your ListenForEvent death, put it at the end of your master_postinit. Instead of "OnMounted" you can call it eg "OnDeath", or you can directly start writing the function with "function(...", but I would suggest to do it with "OnDeath", this is easier to read and easier to understand for beginners. So now you have the line: inst:ListenForEvent("death",OnDeath) in your masterpostinit. Finally you have to define the function "OnDeath", what should happen on death? So outside of any exisiting function, you create a new local function with the name OnDeath(inst). Don't forget the "end" on the end of the function, just like all other functions. In that function you put your PushEvent. You use DoTaskInTime incorrect. Simply use notepad++ file-search to see examples how to use this. You will notice that you only can tell the function to do something in x seconds. So it expects a number of seconds. So the question is now: After dieing, when should the the player respawn? After few seconds? Or when? If you want to use "ms_nextcycle" you have to take a look in clock.lua, to see how to use it. You do not call it with DoTaskIntime, it is also a ListenForEvent thing. So if you want any dead players to respawn at new cycle, then you don't need your ListenForEvent("death", because it would be enough to only listen to the cycle, loop through all players and respawn them if they are dead. Link to comment https://forums.kleientertainment.com/forums/topic/84191-need-assistance-with-pushevent-command/#findComment-974384 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now