autoharvest gadget - Page 2

autoharvest gadget

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

Now the gadget seems to do nothing. When the "initialize code" was on unsync side the gadget printed at least the Spring.Echo things to the console. Have I somehow to tell Spring that I made a new command? Like adding the name of my caommand somewhere?
here is the new code:

Code: Select all

function gadget:GetInfo()

	return {
		name = "bla",
		desc = "blabla",
		author = "blablabla",
		date = "bla",
		license = "bla",
		layer = 0,
		enabled = true
	}

end


local CMD_MOVETO=30002


if (gadgetHandler:IsSyncedCode()) then


--SYNCED


local metalplat={}

local movetoCmd={

	name="moveto",
	tooltip="movesunitto",
	action="move",
	id=CMD_MOVETO,
	type=CMDTYPE.ICON , --CMDTYPE.ICON_MAP,
	cursor="Move",

}


function gadget:AllowCommand(u, ud, team, cmd, param, opt)

	if cmd == CMD_MOVETO then
		Spring.GiveOrderToUnit(u,CMD.MOVE,metalplat[1].pos,0);

		--return false

	end

	return true

end


function gadget:UnitCreated(u, ud, team)

	if UnitDefs[ud].customParams.canharvest=="1" then
	   Spring.Echo("harvestunit created");
	   Spring.GiveOrderToUnit(u,CMD.INSERT,{-1,CMD_MOVETO},{"alt"});

	   --Spring.GiveOrderToUnit(u,ud,team,CMD_MOVETO,0);

	end

end



function gadget:UnitFinished(u,ud,team)

	if ud == RUSK31 then
	Spring.Echo("harvestunit finished");
	Spring.GiveOrderToUnit(u,CMD.MOVETO);

	end

end


function gadget.Initialize()
	
	local i = 1

	for _,a in ipairs(Spring.GetAllFeatures()) do

		if Spring.GetFeatureDefID(a) == metal then
			local x,y,z=Spring.GetFeaturePosition(a)
			metalplat[i]={pos={x,y,z}}
			i=i+1
		end

	end

	if i==1 then
		Spring.Echo("removed")
		gadgetHandler:RemoveGadget()

	end

end	



else


--UNSYNCED


end

Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: autoharvest gadget

Post by Google_Frog »

Code: Select all

function gadget:UnitCreated(unitID, unitDefID)
	local ud = UnitDefs[unitDefID]
	if ud should have command then
     spInsertUnitCmdDesc(unitID, CmdDesc)
   end
end
This will make the command accessible to players on the console.

Code: Select all

function gadget:Initialize()
	gadgetHandler:RegisterCMDID(CMD_ID)
end
You may have to register the command if it is not going to be attached to a unit.

It seems a bit strange that you've got your own moveto command. Couldn't you just use the move command directly?
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

It seems a bit strange that you've got your own moveto command. Couldn't you just use the move command directly?
It's like the "step 0" of the gadget I'd like to make. I think one could use it directly it's more a placeholder than a real command. When I manage to give this command to units I can try to give them other commands. (Just an attempt to implement a new command which works :-) )
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

Is it not allowed to use existing commands in other commands?
Is it possible to give a command to a unit and when the unit reaches that place/unit it triggers an event (like telling "hey I reached the target")?
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

No video but code :wink: .
It is a long way to beeing perfect and has not all elements I'd like to have but I think this is the best I could do. It was very hard for me to code this but it seems to work. It may have bugs. It should work on maps with metal and geos. Don't build units too far from resourcepoints cause they will only search for resource nearby (you can edit the distance in the code).
Attachments
Resource.sdd.7z
(1.48 MiB) Downloaded 17 times
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

version 2 (just replace the old one with this)
Attachments
autoharvest.lua
(14.82 KiB) Downloaded 23 times
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

Does this work for someone cause when I uploaded the old one it did not have all textures so Spring just removed the models (with missing textures) from the game :?:
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: autoharvest gadget

Post by BrainDamage »

thedude wrote:Does this work for someone cause when I uploaded the old one it did not have all textures so Spring just removed the models (with missing textures) from the game :?:
when I start it, I get a crane unit, and it's able to acquire the resources from the barrel-resources but no place is present where to deploy them, do have I to build it first? if yes, what is it's name?
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: autoharvest gadget

Post by thedude »

When you look at the description of the crane there you should see something like ... for sweets that meens that this unit can only harvest the resource "sweets". You have to build "Barracks" so the crane can deploy it there (the description of Barracks should also contain something with sweets) hope this helps.
Post Reply

Return to “Game Development”