Weapon Problems. - Page 4

Weapon Problems.

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

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapon Problems.

Post 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.
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Weapon Problems.

Post 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
Last edited by FLOZi on 16 Aug 2011, 20:32, edited 1 time in total.
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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?
Last edited by Machinesrocks on 16 Aug 2011, 20:33, edited 1 time in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Weapon Problems.

Post 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.
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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"?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Weapon Problems.

Post 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/
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapon Problems.

Post 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.
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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.
Last edited by Machinesrocks on 16 Aug 2011, 23:59, edited 1 time in total.
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapon Problems.

Post by knorke »

2 players? One being you, other being an AI.
Use springlobby instead of spring.exe for more controll when setting up games.
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapon Problems.

Post 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
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10454
Joined: 24 Jan 2006, 21:12

Re: Weapon Problems.

Post 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
User avatar
Machinesrocks
Posts: 37
Joined: 10 Aug 2011, 20:35

Re: Weapon Problems.

Post 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:
Post Reply

Return to “Game Development”