Page 4 of 4

Re: Weapon Problems.

Posted: 14 Aug 2011, 12:11
by knorke
Is there a better way for me to be figuring out these problems than to be posting on the forums? Maybe a guide of some sort that could tell me why things don't work/crash?
wiki has some stuff, though the guides mostly only cover getting the first unit ingame, which you have already managed. The rest is more bits&pieces.
Every spring game's source is viewable by just unpacking it, possible to learn from that.
Type /join #moddev in lobby chat.

If you want others to help make it as simple as possible for them.
Like I wanted to look at the factory, but the factory from the SVN does not even have "scout" as buildoption:
http://sourceforge.net/p/openmachines/c ... force=True
only a "tank" (but no unit of such name exists)
Also does not have the stuff done I wrote earlier, like setting workerTime
Same with the download from that file hosting site.

Makes no sense to look at stuff when your local copy is something different, its just a waste of time this way.

Re: Weapon Problems.

Posted: 16 Aug 2011, 20:22
by Machinesrocks
Is there a way to make a flying unit stay in the air at all times?

Couldn't find a unitdef to make him not land.

Re: Weapon Problems.

Posted: 16 Aug 2011, 20:30
by FLOZi
Easy to do with a gadget:

Code: Select all

function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
	        local ud = UnitDefs[unitDefID]

	        if ud.canFly then
	                Spring.GiveOrderToUnit(unitID, CMD.IDLEMODE, {0}, {})
	                local toRemove = {CMD.IDLEMODE, CMD.AUTOREPAIRLEVEL}
	                for _, cmdID in pairs(toRemove) do
	                        local cmdDescID = Spring.FindUnitCmdDesc(unitID, cmdID)
	                        Spring.RemoveUnitCmdDesc(unitID, cmdDescID)
	                end
	        end
end
That sets the unit to fly and removes the 'fly/land' button and 'land at x' button.

There is a unitdef tag but it only works for aircraft with gunship movetype. See 'airHoverFactor' at http://springrts.com/wiki/Units-UnitDefs#Aircraft

Re: Weapon Problems.

Posted: 16 Aug 2011, 20:31
by Machinesrocks
Thanks, can I just name it "anything.lua" or does it need a specific name?

EDIT: Oh, well he is a gunship I think. hoverAttack = true Makes him a gunship, right?

Re: Weapon Problems.

Posted: 16 Aug 2011, 20:33
by FLOZi
Just give it a sensible name, can be anything. It'll also need the usual GetInfo block and synced check.

Yes hoverAttack = true makes him a gunship.

I'd still use the gadget in addition though, to remove the buttons form the UI.

Re: Weapon Problems.

Posted: 16 Aug 2011, 23:07
by Machinesrocks
Yup, I'm lost. I'm supposed to edit it in with my information, right? I can't seem to get it working. The lua file is "wasp.lua", and the name is "wasp1". So should I change it like:

Code: Select all

function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
           local ud = UnitDefs[wasp.lua]

           if ud.canFly then
                   Spring.GiveOrderToUnit(wasp1, CMD.IDLEMODE, {0}, {})
                   local toRemove = {CMD.IDLEMODE, CMD.AUTOREPAIRLEVEL}
                   for _, cmdID in pairs(toRemove) do
                           local cmdDescID = Spring.FindUnitCmdDesc(wasp1, cmdID)
                           Spring.RemoveUnitCmdDesc(wasp1, cmdDescID)
                   end
           end
end


So the "wasp.lua" is the unitdefID, and the "wasp1" is unitID, or am I just completely wrong? If I'm doing it correctly, what is the command it's supposed to be blocking called? "land"?

Re: Weapon Problems.

Posted: 16 Aug 2011, 23:46
by FLOZi
You're completely wrong.

This is a gadget, it goes in LuaRules/gadgets/MyAwesomeGadget.lua

It is not part of the unit definition or animation script.

UnitCreated is called by the engine whenever a new unit is created, you don't need to alter the code in my post at all, only stick it into the rudiments of a gadget (GetInfo and synced check).

I guess we need to go back to the very start here. :P Doesn't help that the wiki doesn't have a clear article on what everything is and where it goes.

Have a look at the game structure here:
http://mwspring.svn.sourceforge.net/

Re: Weapon Problems.

Posted: 16 Aug 2011, 23:54
by knorke
or am I just completely wrong?
this ;)
Basically, forgett about it for now and start with simple scripts like the famous "hello world" and then work from that.
Just remember that aircraft that always fly are possible.
The code for it is not even that complicated but it requires some background knowledge how some things in Spring works.
That aircraft thing is pretty specific but not that much can be learned from it.
only stick it into the rudiments of a gadget (GetInfo and synced check).
where would a new guy find these things :?
really needs some basic Lua guide.

Re: Weapon Problems.

Posted: 16 Aug 2011, 23:56
by Machinesrocks
I understand where gadgets go, and how it's separate, but I guess I didn't do "synced check", whatever that is. Can you tell me what that is? I already have the get info block in there.

EDIT: mmk, I'll try to get some more knowledge in this spring scripting stuff.

Re: Weapon Problems.

Posted: 16 Aug 2011, 23:59
by knorke

Re: Weapon Problems.

Posted: 18 Aug 2011, 18:44
by Machinesrocks
Is there any reason my game spawns two units? Is it something included within my code, or an options thing? Because I don't remember adding that.

Re: Weapon Problems.

Posted: 18 Aug 2011, 20:29
by knorke
2 players? One being you, other being an AI.
Use springlobby instead of spring.exe for more controll when setting up games.

Re: Weapon Problems.

Posted: 20 Aug 2011, 00:57
by Machinesrocks
Can anyone give me an example script for a builder? When I tell my builder to build, he just moves around. I think it's because he's trying to push out something that doesn't exist. I can't seem to find one that doesn't use a crane or push out a building thing.

Re: Weapon Problems.

Posted: 20 Aug 2011, 14:24
by knorke
I think it's because he's trying to push out something that doesn't exist.
I dont even know what that means.
Image
If you do not post the script/unitdef file in any form it is impossible to guess what is wrong.
If the script has references to pieces that do not exist in your model (like the arm of a crane) then just remove those lines, it is just animation stuff.

red = animation stuff

function script.StopBuilding()
Turn (crane1, y_axis, 0, math.rad(100))
StopSpin (nano, z_axis)
Turn (nano, z_axis, 0, math.rad(200))
moveCrane (0)
SetUnitValue(COB.INBUILDSTANCE, 0)
end

function script.StartBuilding(heading, pitch)
Turn (crane1, y_axis, heading+math.rad(180), math.rad(100))
moveCrane (75)
waitForCrane ()
Spin (nano, z_axis, math.rad (200))
SetUnitValue(COB.INBUILDSTANCE, 1)
end

function script.QueryNanoPiece()
return nano
end

Re: Weapon Problems.

Posted: 20 Aug 2011, 14:45
by PicassoCT
you need a piece named inside the script that builds- (get put into buildstance)

looks like this:

Code: Select all

function script.QueryNanoPiece()
return nano
end
then you need something to retract that buildpiece:

Code: Select all

function script.StopBuilding()
Turn (crane1, y_axis, 0, math.rad(100))
StopSpin (nano, z_axis)
Turn (nano, z_axis, 0, math.rad(200))
moveCrane (0)
SetUnitValue(COB.INBUILDSTANCE, 0)
end
then you need something to press the buildpiece out (you had that one right, just nobody here who would admit that- ever):

Code: Select all

function script.StartBuilding(heading, pitch)
Turn (crane1, y_axis, heading+math.rad(180), math.rad(100))
moveCrane (75)
waitForCrane ()
Spin (nano, z_axis, math.rad (200))
SetUnitValue(COB.INBUILDSTANCE, 1)
end

Re: Weapon Problems.

Posted: 20 Aug 2011, 20:43
by Machinesrocks
Well I'm totally trying to avoid using retraction or pushing anything out. He's going to move his arms around, but I want to be able to get him to build instead of running around. I've been trying several things out, so what is wrong with this one?

Code: Select all

local ritehand = piece "ritehand"
local lefthand = piece "lefthand"


function script.StopBuilding()

SetUnitValue(COB.INBUILDSTANCE, 0)
end

function script.StartBuilding(heading, pitch)

SetUnitValue(COB.INBUILDSTANCE, 1)
end

function script.QueryNanoPiece()
return ritehand
end
EDIT: Nevermind, it works now. :roll: