Jump to content

Recommended Posts

I have no idea how to create such a mod but I would like a simple mod that kills you when you rejoin a multiplayer game. This would obviously be a server side only mod. Does anyone have any idea how to start such a mod or can someone make this real quick?

Thanks a lot! This is exactly what I needed! Very helpful!

 

I am new to modding this game, hopefully I can learn more from reading your responses, I modified your awesome code to make it so it checks for a telltale heart when the player joins... (maybe you can tell me if this code looks correct / or if there is a better way, it seems to be working for me which is really exciting, hardest part was finding out telltale heart was called reviver... in fact I am not even sure how I just figured that out)

 

elseif inst.components.inventory:Has("reviver",1) then   inst.components.inventory:ConsumeByName("reviver",1)inst:DoTaskInTime(2.5, function() inst.components.talker:Say("Quitting breaks my heart.") end)elseinst:DoTaskInTime(2.5, function() inst.components.talker:Say("I feel like I shouldn't have quitted.") end)   inst:DoTaskInTime(5, function() inst.components.health:Kill() end)end

Is there anyway to drop the players inventory when he quits / quitted the game so that he can't escape with the items in a server sided way? Also how can I send a /sad emote when I try to modify your code it just says /sad instead of doing the emote. Thanks again for your assistance.

@NoQuitting:

local emotes = GLOBAL.require("emotes")local str, sad = emotes.translate("/sad")AddPlayerPostInit(function(inst)	local _OnNewSpawn = inst.OnNewSpawn	local function OnNewSpawn(inst)		if _OnNewSpawn then			_OnNewSpawn(inst)		end		inst.saveme = true	end	inst.OnNewSpawn = OnNewSpawn	local _OnLoad = inst.OnLoad	local function OnLoad(inst, data)		if _OnLoad then			_OnLoad(inst, data)		end		if not inst.saveme then			if inst:HasTag("playerghost") then				inst:DoTaskInTime(2.5, function() inst.components.talker:Say("I feel nothing at this point.") end)			elseif inst.components.inventory:Has("reviver", 1) then				inst.components.inventory:ConsumeByName("reviver", 1)				inst:DoTaskInTime(2.5, function() inst.components.talker:Say("Quitting breaks my heart.") end)				else				inst:DoTaskInTime(2.5, function()					inst.components.talker:Say("I feel like I shouldn't have quitted.")					inst.sg:GoToState("emote", sad)				end)				inst:DoTaskInTime(5, function() inst.components.health:Kill() end)			end		end	end	inst.OnLoad = OnLoad	local _OnDespawn = inst.OnDespawn	local function OnDespawn(inst)		if _OnDespawn then			_OnDespawn(inst)		end		if inst.components.inventory then			inst.components.inventory:DropEverything(false, false)		end	end	inst.OnDespawn = OnDespawnend)

 

Your addition is fine. If you find a heart, you consume it. :-)

@NoQuitting:

 

Your addition is fine. If you find a heart, you consume it. :-)

 

  local _OnDespawn = inst.OnDespawn

    local function OnDespawn(inst)

        if _OnDespawn then

            _OnDespawn(inst)

        end

 

I tried searching the scripts folder and I can't begin to figure out how I would have figured this out on my own without your help. Perhaps you can teach me how to fish. Maybe comment your code so I can better understand the basics. Are you overriding the OnDespawn code and then causing it to run the rest of the OnDespawn code? Also how did you know about int.OnDespawn. Oh and I just figured out a problem... when we drop all the inventory now when we rejoin we are guaranteed not to have a telltale heart :( so I am trying to figure out how to have the player keep 1 telltale heart if he has it or keep all of his telltale hearts whichever is easier...

@NoQuitting, for why do I know about OnDespawn, it's mostly gameplay experience.

 

For example, I saw a Wendy leaving the server and with that, Abigail despawned. So I went to the wendy.lua to see if I could find anything despawn related. I found the inst.OnDespawn attribute. Quite evident its use. You can use OnDespawn as a parameter in something like Find in Files in Notepad++ to find stuff related and track down where its called and with the complete list of parameters.

	-- We are inside an AddPrefabPostInit	-- Prefab was initialized	-- So maybe there exists a current OnDespawn function	-- Example: wendy.lua	-- If I do	-- inst.OnDespawn = function() print("Hello") end	-- I would be leaving the old function out of my reach, ready to be garbage collected	-- Therefore, I save it in a local reference, OldFunc	local OldFunc = inst.OnDespawn	-- With that out of the way, we make our function	-- This function will be the new inst.OnDespawn	local function MyFunction(inst)		-- If there was an old function, then type(inst.OnDespawn) would return "function"		-- There would be a function value in the variable		-- Everything besides nil and false is evaluated to true		-- So if OldFunc is not nil, this is, there's a value there (which I know it's a function)		-- (Because I assume nobody would put inst.OnDespawn = 120, just to break the code)		if OldFunc then			-- There's a function, lets call it			OldFunc(inst)		end		-- Here we write other stuff we want to do	end	-- With our new function running old and new behaviour, we set it up so the game uses it	inst.OnDespawn = OnDespawn

And you are right about the revivers dropping.

 

Use this:

    local function OnDespawn(inst)        if _OnDespawn then            _OnDespawn(inst)        end        if inst.components.inventory then			if self.activeitem ~= nil then				self:DropItem(self.activeitem)				self:SetActiveItem(nil)			end			for k, v in pairs(self.equipslots) do				self:DropItem(v, true, true)			end			for k = 1, self.maxslots do				local v = self.itemslots[k]				if v ~= nil and v.prefab ~= "reviver" then					self:DropItem(v, true, true)				end			end        end    end

I copy pasted the DropEverything function of the inventory component and modified it to ignore revivers.

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
×
  • Create New...