Jump to content

Adding new action


Recommended Posts

What do you mean? Custom animation? Custom item? There's been a few mods that deal with changing how an item works, such as rezeceib's spear throwing, or making a new item like J192's snowball mod. What in particular are you looking for? 

 

I just want to port my WallGates mod to DST but the actions seems to not work and I have no idea what i need to change for them to work. Game code changed and there is no tutorials yet.

 

Actions in modmain:

local OPEN = Action(3)OPEN.str = "Close"OPEN.id = "OPEN"OPEN.fn = function(act)	local tar = act.target    if tar and tar.components.wallgates and not tar.components.wallgates:IsOpen() then		tar.components.wallgates:OpenWall(tar)		return true    endendAddAction(OPEN)AddStategraphActionHandler("wilson", ActionHandler(OPEN, "give"))local CLOSE = Action(3)CLOSE.str = "Open"CLOSE.id = "CLOSE"CLOSE.fn = function(act)	local tar = act.target    if tar and tar.components.wallgates and tar.components.wallgates:IsOpen() then        tar.components.wallgates:CloseWall(tar)        return true    endendAddAction(CLOSE)AddStategraphActionHandler("wilson", ActionHandler(CLOSE, "give"))

Custom component for the actions:

local WallGates = Class(function(self, inst)	self.inst = inst	self.openwallfn = nil	self.closewallfn = nil	self.isopen = false	self.caninteractfn = nilend)function WallGates:OnSave()	local data = {}		data.isopen = self.isopen	return dataendfunction WallGates:OnLoad(data)	if data then		self.isopen = data.isopen		if self:IsOpen() then self:OpenWall() else self:CloseWall() end	endendfunction WallGates:OpenWall()	if self.openwallfn then		self.openwallfn(self.inst)	end	self.isopen = trueendfunction WallGates:CanInteract()	--if self.caninteractfn then		--return self.caninteractfn(self.inst)	--else		return true	--endendfunction WallGates:CloseWall()	if self.closewallfn then		self.closewallfn(self.inst)	end	self.isopen = falseendfunction WallGates:IsOpen()	return self.isopenendfunction WallGates:CollectSceneActions(doer, actions, right)	if right and self:CanInteract() then		if self:IsOpen() then			table.insert(actions, ACTIONS.CLOSE)		else			table.insert(actions, ACTIONS.OPEN)		end		endendreturn WallGates
Edited by _Q_
Link to comment
Share on other sites

@_Q_

It's just the component part for the action collection that changed. Remove the WallGates:CollectSceneActions definition and add the following to modmain.lua:

AddComponentAction("SCENE", "wallgates", function(inst, doer, actions, right)    if right and SOMETHING then        if SOMETHING then            table.insert(actions, GLOBAL.ACTIONS.CLOSE)        else            table.insert(actions, GLOBAL.ACTIONS.OPEN)        end    endend)
Note that now the component object is no longer passed as the first (the "self") parameter, what gets passed is the inst. Also mind the SOMETHING's. Components shouldn't be added on clients, just on servers, so you won't be able to access "inst.components.wallgates" and must use another way of checking those conditions. Tags are transmitted to clients, so adding tags to the inst inside the component and checking them is the simplest way to achieve that.
Link to comment
Share on other sites

@_Q_

It's just the component part for the action collection that changed. Remove the WallGates:CollectSceneActions definition and add the following to modmain.lua:

AddComponentAction("SCENE", "wallgates", function(inst, doer, actions, right)    if right and SOMETHING then        if SOMETHING then            table.insert(actions, GLOBAL.ACTIONS.CLOSE)        else            table.insert(actions, GLOBAL.ACTIONS.OPEN)        end    endend)
Note that now the component object is no longer passed as the first (the "self") parameter, what gets passed is the inst. Also mind the SOMETHING's. Components shouldn't be added on clients, just on servers, so you won't be able to access "inst.components.wallgates" and must use another way of checking those conditions. Tags are transmitted to clients, so adding tags to the inst inside the component and checking them is the simplest way to achieve that.

 

Thanks. And what with those replicas things, I need them or not in this case?

Link to comment
Share on other sites

Thanks. And what with those replicas things, I need them or not in this case?

Well, mods can't add custom replica components yet (without resorting to hackery), so it's not really worth considering at this point.

inst.replica just stores replica components, which are component "stubs" that exist in clients as well, while regular components only exist in the host. Usually a replica will only have some networking logic to synchronize with the actual component existing on the host, and provide a few helper methods. You could use replicas instead of tags in your case, but since it's a simple scenario they're not necessary.

Link to comment
Share on other sites

Well, mods can't add custom replica components yet (without resorting to hackery), so it's not really worth considering at this point.

inst.replica just stores replica components, which are component "stubs" that exist in clients as well, while regular components only exist in the host. Usually a replica will only have some networking logic to synchronize with the actual component existing on the host, and provide a few helper methods. You could use replicas instead of tags in your case, but since it's a simple scenario they're not necessary.

 

Functions that get the player are returning just player prefab without any reference to the user?

I mean if I could save the user name in the prefab somehow so just that user can open/close it?

 

Link to comment
Share on other sites

Functions that get the player are returning just player prefab without any reference to the user?

I mean if I could save the user name in the prefab somehow so just that user can open/close it?

ThePlayer and the deprecated GetPlayer() are the local player, though you should rarely need those. The table AllPlayers has all the players, and there are some utility functions for searching players in simutil.lua.

Using the entity's GUID (inst.GUID) should be enough as an identifier. There must be a way to associate a player entity with a Steam ID and vice versa, but I haven't come across it.

EDIT:

@_Q_, You can get it at ThePlayer.name. But I would use userid (ThePlayer.userid) instead, since players can change names.

Thanks, I guess I just came across it. Though checking for mentions of userid I also found this in components/playerrespawnpenalty.lua:

local id = player.Network:GetClientName() --V2C HACK: MARK NEEDED ICECREAM (should be userid but it doesn't work yet)
Did someone get Mark his icecream already or is userid still not completely functional? Edited by simplex
Link to comment
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
 Share

×
×
  • Create New...