Jump to content

Recommended Posts

Hello,
I am trying to make a mod which allows users to place items in a grid by dragging while clicking. Similar to ActionQueue by simplex and xiaoXzzz, I hope to make this a client only mod and I think I am done with 90% of the framework. However, I am having an issue with RPCs and BufferedActions (Needed to do deploy, build, and drop on a dedicated sever.)

My issue is as follows:
I set on AddSuccessAction and AddFailAction functions for the BufferedActions (build, deploy, drop) generated by my mod. These are used to cancel everything and clean up on failure, or build the next queued item on success. Then, In order to get my mod to work server side, I add a preview_cb to the BufferedAction which contains a 'SendRPCToServer' corresponding to that action. However, when the BufferedAction is send to locomotor:PreviewAction it builds the first item then returns an action failure, causing the rest of the queue to be deleted.

 

I like the clean up on fail logic to ensure I am properly managing my memory, but I couldn't find any other examples which used RPCs and an AddFailAction method.

Here is my GitRepo. Attached is my mod in it's current state. Below are relevant (abridged) code snippets.

function TiledPlacer:deploy(inst, index)
  --[[ code hidden in here... ]]
  
  		-- Build BufferedAction for a deployable item.
		local action = BufferedAction(self.player, nil, 
				ACTIONS[inv_item:IsDeployable() and 'DEPLOY' or 'DROP'],
				place_item, pos_to_place, nil,
				inv_item:DeploySpacingRadius() or 3.2, nil, 
				self.player.Transform:GetRotation())		

		action:AddFailAction(function ()
			self:clean_up_all()
		end)

		action:AddSuccessAction(function ()
			print("Success Deploy")
			if self.planned then
				local temp_inst = table.remove(self.planned, index)
				temp_inst.prefab:Remove()
				self:build_next()
			end
		end)
		self:do_action(action)	
 	--[[ code hidden in here... ]]
end

function TiledPlacer:do_action(action)
  	--[[ code hidden in here... ]]
	
	if TheWorld.ismastersim then
		--self.player.components.playercontroller:DoAction(action)
    	-- This part works.
		self.player.components.locomotor:PushAction(action, true)
	else
		if action.action == ACTIONS.BUILD then
			print("Build to server.")
			action.preview_cb = function()
				SendRPCToServer(RPC.MakeRecipeAtPoint, action.recipe.rpc_id,
					action.pos.x, action.pos.z, action.rotation, action.skin)
				end
			self.player.components.locomotor:PreviewAction(action, true)
			
		elseif action.action == ACTIONS.DEPLOY then
			print("Deploy to server.")
			action.preview_cb = function()
				SendRPCToServer(RPC.ControllerActionButtonDeploy, 
					action.invobject, action.pos.x, action.pos.z,
					action.rotation, true)
				end
			self.player.components.locomotor:PreviewAction(action, true)
			
		elseif action.action == ACTIONS.DROP then
			print("Drop to server.")
			action.preview_cb = function()
				SendRPCToServer(RPC.DropItemFromInvTile, 
					action.invobject, true)
				end
			self.player.components.locomotor:PreviewAction(action, true)
			
		else
			print("Bad Action Type " .. action.action.id)
			return self:clean_up_all()
		end
	end
end

 

tiledplanting.zip

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...