Mod Question Repository... Questions come in, answers go out - Page 44

Mod Question Repository... Questions come in, answers go out

Resources to get you going on your new project, or to help you over some emergent problems during your development cycle.

Moderator: Moderators

Locked
User avatar
PTSnoop
Posts: 97
Joined: 09 Sep 2009, 19:05

Re: Mod Question Repository... Questions come in, answers go out

Post by PTSnoop »

Thanks a lot.

To turn the script into a builder script, would I just have to replace QueryWeapon and FireWeapon with QueryNanoPiece, StartBuilding and add a StopBuilding (and change the pieces and speeds and so on to fit the model, obviously)? Or is there more to it with that?

And for buildings, how would I go about setting up inbuildstance and bugger_off ?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

That sounds about right. Tbh, in the past 8 years or so of TA and Spring modding, I've never written a builder/factory script from scratch, and as such the associated functions aren't seared into my memory quite so much. I might suggest PMing Tobi.

I guess I should work through those example BOS scripts converting them to lua.
User avatar
PTSnoop
Posts: 97
Joined: 09 Sep 2009, 19:05

Re: Mod Question Repository... Questions come in, answers go out

Post by PTSnoop »

Hmm. This is strange. When I try my mod with the cubesmall.lua unit script in place, I get

Code: Select all

Could not load COB script from: scripts/cubesmall.cob
The infolog was picking up syntax errors in the file before; I thought that was the problem, but fixing the errors still gives the same "could not load COB" message, and there's no unit animation in game.

Uninstalling Spring and installing the most recent version (0.80.4.2; I think I was on something older before) doesn't seem to help. The LuaRules/Gadgets/unit_script.lua file looks the same as the one at http://springrts.com/wiki/Animation-LuaScripting; the system.lua was taken from the SVN version of Spring 1944. Can anyone help?

cubesmall.lua:

Code: Select all

local cube = piece "cube"
local centre = piece "centre"
local flare = piece "flare"

local SIG_AIM = 2

function script.Create(unitID)
	StartThread(GG>UnitScript.SmokeUnit)
end

function script.AimWeapon(weaponID, heading, pitch)
	Signal(SIG_AIM)
	SetSignalMask(SIG_AIM)
	Turn(centre, y-axis, heading)
	Turn(centre, x-axis, -pitch)
	return true
end

function script.FireWeapon(weaponID)
	EmitSfx(flare, 0)
end

function script.AimFromWeapon() return centre end

function script.QueryWeapon() return flare end

function script.Killed(recentDamage, maxHealth)
	return 0
end
infolog.txt:

Code: Select all

LogOutput initialized.
Spring 0.80.4.1 (0.80.4.2-0-g2f09034{@}-cmake-mingw32)
Available log subsystems: mapinfo, CollisionVolume, unit, VFS-detail, VFS, ArchiveScanner, Sound
Enabled log subsystems: Sound
Enable or disable log subsystems using the LogSubsystems configuration key
  or the SPRING_LOG_SUBSYSTEMS environment variable (both comma separated).
using configuration source "C:\Users\Andrew\AppData\Local\springsettings.cfg"
[CMyMath::Init] CPU SSE mask: 126, flags:
	SSE 1.0:  1,  SSE 2.0:  1
	SSE 3.0:  1, SSSE 3.0:  1
	SSE 4.1:  1,  SSE 4.2:  0
	SSE 4.0A: 0,  SSE 5.0A: 0
	using streflop SSE FP-math mode, CPU supports SSE instructions
OS: Microsoft Windows
Microsoft Windows Vista Home Premium Edition, 32-bit Service Pack 1 (build 6001)
Intel(R) Core(TM)2 Duo CPU     T8300  @ 2.40GHz; 3069MB RAM, 6338MB pagefile
OS: 32bit native mode
Using read-only  data directory: C:\Program Files\Spring\
Using read-write data directory: C:\Users\Andrew\Documents\My Games\Spring\
Scanning: C:\Users\Andrew\Documents\My Games\Spring\maps
Scanning: C:\Users\Andrew\Documents\My Games\Spring\base
Scanning: C:\Users\Andrew\Documents\My Games\Spring\mods
Scanning: C:\Users\Andrew\Documents\My Games\Spring\packages
Scanning: C:\Program Files\Spring\maps
Scanning: C:\Program Files\Spring\base
Scanning: C:\Program Files\Spring\mods
Scanning: C:\Program Files\Spring\packages
Video mode set to  1280 x 800 / 32 bit
SpringApp::InitWindow(): 4290546146 ms
[      0] SDL:  1.2.10
[      0] GL:   2.0.6747 Release
[      0] GL:   ATI Technologies Inc.
[      0] GL:   ATI Mobility Radeon HD 2400
[      0] GLEW: 1.4.0
[      0] ATI hacks enabled
[      0] Connecting to local server
[      0] Sound: OpenAL info:
[      0] Sound:   Vendor:     Creative Labs Inc.
[      0] Sound:   Version:    1.1
[      0] Sound:   Renderer:   Software
[      0] Sound:   AL Extensions: EAX EAX2.0 EAX3.0 EAX4.0 EAX5.0 EAX3.0EMULATED EAX4.0EMULATED AL_EXT_OFFSET AL_EXT_LINEAR_DISTANCE AL_EXT_EXPONENT_DISTANCE
[      0] Sound:   ALC Extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_EFX
[      0] Sound:   Device:     Generic Software
[      0] Sound:   Available Devices:  
[      0] Sound:                       Generic Software
[      0] CPreGame(): 265 ms
[      0] Starting demo recording
[      0] Skirmish AI (NullAI) for team 0 is no Lua AI
[      0] Using map Mini_Chess.smf
[      0] Recording demo demos/local_20091017_143140_Mini_Chess_0.80.4.sdf
[      0] Using script Commanders
[      0] Using mod Static Friction Eek 0.1.2 Testing
[      0] Using mod archive TestingEEK.sdd
[      0] Became player 0 (team 1, allyteam 0)
[      0] Loading console: 0 ms
[      0] Sound: CSound(): Successfully parsed 4 SoundItems from gamedata/sounds.lua
[      0] Sound: WAV file sounds/beep4.wav has data length 291939 greater than actual data length 14
[      0] Loading sounds: 2 ms
[      0] Sound: WAV file sounds/button9.wav has data length 291939 greater than actual data length 14
[      0] Camera and mouse: 606 ms
[      0] Parsing unit icons
[      0] Parsing definitions
[      0] could not load buildOption data: missing file
[      0] Loading all definitions:  0.047000
[      0] Loading defs: 57 ms
[      0] Loading map informations
[      0] Opening map file
[      0] Loading Map
[      0] Loading detail textures
[      0] Creating overhead texture
[      0] Creating ground shading
[      0] Loading tile file
[      0] Reading tiles
[      0] Reading tile map
[      0] Creating projectile texture
[      0] Number of damage types: 5
[      0] Loading weapon definitions
[      0] Loading unit definitions
[      0] Sound: WAV file sounds/beep6.wav has data length 291939 greater than actual data length 14
[      0] Loading feature definitions
[      0] Generating trees
[      0] Creating unit textures
[      0] Initializing map features
[      0] Unknown map feature type 
[      0] Reading estimate path costs
[      0] Pathing data checksum: 29a6b1be
[      0] Creating sky
[      0] Loading LuaRules
[      0] gf1 = LuaRules/Gadgets/unit_script.lua
[      0] gf2 = LuaRules/Gadgets/unit_script.lua
[      0] Loading unitscript scripts/cubesmall.lua
[      0] Loaded gadget:  Lua unitscript framework  <unit_script.lua>
[      0] gf1 = LuaRules/Gadgets/unit_script.lua
[      0] gf2 = LuaRules/Gadgets/unit_script.lua
[      0] Loading LuaGaia
[      0] Loading LuaUI
[      0] Using LUAUI_DIRNAME = LuaUI/
[      0] Reloaded ctrlpanel with: LuaUI/ctrlpanel.txt
[      0] LuaUI: bound F11 to the widget selector
[      0] LuaUI: bound CTRL+F11 to tweak mode
[      0] Loaded widget from mod:   Auto LOS            <cmd_autolos.lua>
[      0] Loaded widget from mod:   Select n Center!    <gui_center_n_select.lua>
[      0] LuaUI v0.3
[      0] Finalizing...
[      0] Spring 0.80.4.1 (0.80.4.2-0-g2f09034{@}-cmake-mingw32)
[      0] Build date/time: Sep 18 2009 17:02:16
[      0]  -> connection established (given id 0)
[      0] Player Player finished loading and is now ingame
[      0] GameID: 43c7d94aa8cb629df25d52d4f270f133
[      0] Player Player (auto)-paused the game for letting Skirmish AI NullAI initialize for controlling team 0. The game is auto-unpaused as soon as the AI is ready.
[      0] Could not load COB script from: scripts/cubesmall.cob
[      0] Could not load COB script from: scripts/cubesmall.cob
[      1] Player paused the game
[      1] Player unpaused the game
[    492] User exited
[    492] Path cache hits 0 0%
[    492] Path cache hits 0 0%
[    492] Statistics for local connection:
Received: 1476 bytes
Sent: 4724 bytes
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: Mod Question Repository... Questions come in, answers go out

Post by KingRaptor »

Place the tag in the unitdef:

Code: Select all

script=cubesmall.lua,
In Git engine builds the .lua script takes priority if the tag is absent.

Speaking of luabos scripts, in current engine version include doesn't seem to work in a script:

Code: Select all

LuaRules::RunCallIn: error = 2, UnitCreated, [string "scripts/torpedo.lua"]:15: attempt to call global 'include' (a nil value)
Works in Git version though.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Mod Question Repository... Questions come in, answers go out

Post by KDR_11k »

VFS.Include.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Mod Question Repository... Questions come in, answers go out

Post by Tobi »

For Lua unit scripts, I'm working on a tutorial, but it goes a bit slowly as until sometime end of next week I've quite some uni stuff to do.

Also, use a development build, I did lots of compatibility breaking changes since the version that is in the release. (e.g. removed unitID argument passing, etc.)

When you got a development build set up I may give you a pre-pre-pre alpha of this tutorial if you drop me a PM in lobby.

KDR_11k: VFS.Include has the disadvantage that it needs to decompress and compile the .lua everytime it is executed (once per unit generally). I set up 'include' in the next version as a memoized VFS.Include. (Plus, 'include' also auto-localizes common functions like Turn, Move, etc.)
User avatar
PTSnoop
Posts: 97
Joined: 09 Sep 2009, 19:05

Re: Mod Question Repository... Questions come in, answers go out

Post by PTSnoop »

I've now got the Github version of the Spring engine, and the Lua script's working (with a bit of tweaking).

But now I have a huge yellow "Start 1" above my starting point which I could do without. How do I get rid of it?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Mod Question Repository... Questions come in, answers go out

Post by Argh »

It's the default start-points, which is apparently working again. There's a Widget called Start Point Remover which was developed to address that.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Mod Question Repository... Questions come in, answers go out

Post by smoth »

How do I detect when a unit is turning/changing facing?
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Mod Question Repository... Questions come in, answers go out

Post by yuritch »

You can do like this:

Code: Select all

static-var hasTurned, oldHeading;

#define MINIMUM_DIFFERENCE   <1>

TurnCheck()
{
   var newHeading;
   while(TRUE)
   {
      newHeading = get HEADING;
      if(get ABS(oldHeading - newHeading) > MINIMUM_DIFFERENCE)
      {
         hasTurned = TRUE;
      } else {
         hasTurned = FALSE;
      }
      oldHeading = newHeading;
      sleep 30;
   }
}

...

Create()
{
   oldHeading = get HEADING;
   ...
   start-script TurnCheck();
   ...
}
...
This will set the var to TRUE if unit has turned more than 1 degree since last frame. It's not tested (I've never had a need of such script), but I don't see why it wouldn't work (if only MINIMUM_DIFFERENCE might need tweaking according to real unit's turn performance).

Can probably be done lua-side just as well.
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

I've got sort of the same problem as PTSnoop - the game was looking for a .cob when I wanted to use a .lua. Now I've sort of fixed it, only not because the unit is still static. In other words, there's no warning but still no script...
I'm using FLOZi's empty mod as the base - I copied and altered the cube's definitions and such to correspond to my fugly tank instead:

Code: Select all

local unitName = "fugly"

local unitDef = {
  name               = "Fugly Tank",
  objectName         = "fugly.s3o",
  script             = "fugly.lua",
}

return lowerkeys({ [unitName] = unitDef })
If I don't put the quotes around "fugly.lua" it crashes ("could not find unit"), if I don't put the line at all I get a "could not find fugly.cob" warning, and with the quotes there's no warnings or errors but the tank still can't do anything.
I'm using an edited version of stumpy.lua for the script, called fugly.lua.

I'd pastebin things left right and centre but the trouble is I'm really not sure where the error is coming from so what to post (what's this about SVN?) :? So here's the whole mod file so far - it's tiny so shouldn't be a problem Will host for food! 36kb
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Mod Question Repository... Questions come in, answers go out

Post by yuritch »

Are you sure this unit CAN do at least something? It has no movement defs, it has no weapons, it has no on/off ability, no cloaking, no LoS, no nothing. So it's static of course.
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

yuritch wrote:Are you sure this unit CAN do at least something? It has no movement defs, it has no weapons, it has no on/off ability, no cloaking, no LoS, no nothing. So it's static of course.
Ah... well that would explain the problem...

Are these things defined in the script or in the files in /units? Actually, one important question - are there any example of lua...

Wait, don't answer that - I have like 7 mods in my spring directory: one of the them bound to use lua for its unit definition :-)
Let's see - yep, the Cursed does :mrgreen:

Hurray! I'm like totally a genius!

Actually... am I allowed to look at this stuff for educational purposes? I'm not going to use any of it, just have a look see what the definition/script files are supposed to look like...
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

My empty mod was supposed to be part 1 of a series with part 1 just being the absolute minimum of files needed to run spring without throwing any errors for more experienced modders to start from scratch with, sadly i never got around to parts 2 and 3 which would have had examples of all the important gamedata and unit files
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

I wouldn't worry too much about it FLOZi - I can just crack open one of the open-source mods like CA and have a look at what's written there. Also (re)discovered this - which works for lua if lua syntax is used (',' rather than ';' for example):
http://springrts.com/wiki/Units:FBI

Course, the difference in complexity between CA and your MDK is a little... alarming :shock:
I for one would really appreciate a smoother difficulty curve (eg: 3 part build-up) - still, I can understand if you have better things to do.

At any rate, I think I'm getting the hang of this: my tank can drive around the place, has line of sight, radar, generates and stores energy and metal, and can be told to repair and reclaim although it won't do any of that as it hasn't been scripted.
One strange this though - it seems to be able to move over all terrain with being impeded - up cliffs and so on (haven't tried water...) despite my setting maxSlope to 0 :|

Anyway, thanks for the suggestion, I'll be back for soon with more problems, don't you worry :P
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

CA isn't always the best example to learn from as it implements its own versions of things that most mods will just use the engine for (unit sounds f/ex), though on the other hand, if you want an example of a particular thing, it probably will be in CA somewhere.

Feel free to use S44 to learn from too:

http://spring1944.svn.sourceforge.net/v ... lease.sdd/

Nanoblobs is probably worth getting as well.

I am going to try and do some work on my example mods though. I was thinking of calling them A(bsolute Minimum), B(asic Examples) & C(omplete Examples).
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

FLOZi wrote:CA isn't always the best example to learn from as it implements its own versions of things that most mods will just use the engine for (unit sounds f/ex), though on the other hand, if you want an example of a particular thing, it probably will be in CA somewhere.

Feel free to use S44 to learn from too:

http://spring1944.svn.sourceforge.net/v ... lease.sdd/

Nanoblobs is probably worth getting as well.
I'd like to get hold of Nanoblobs, but I can't find the files anywhere - most of the mods that aren't supported any more just seem to disappear...

But 1944's a good example you think? I've got practically all the mods now - any other suggestions as to which I should be looking at: one without too many hacks, exploits, engine rewrites and so on. 44 does some really interesting stuff - very profound changes to the way the game works: I wonder how it was done...

FLOZi wrote:I am going to try and do some work on my example mods though. I was thinking of calling them A(bsolute Minimum), B(asic Examples) & C(omplete Examples).
Sound good to me :-)

Speaking as a noob, what I'd really like to see is an empty mod with all the files already there but empty (like your MDK), except that each one of these files contains an explanation (in comment form) of what it's used for, some example flags, functions and so on. It's all text so it would take too much memory.

For example, so far I've gathered:
- unit definition = define stats like speed, hit points and line of sight
- unit scripting = define animations and behaviour
- sidedata = names and starting units of each side
- others = um.... :shock:

Just write a few lines about each section would be unbelievably helpful :o

Nanoblobs looks interesting - I want :cry:

edit: ah cool - I found it :o
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

well, here's an explnation of what i hope to do
  • A(bsolute Minimum)
    the absolute minimum files (using all-lua defs and unit scripts, using old files would be slightly different) to run spring without it crashing (previously it was without any errors, but I changed my mind, because the error messages point to what you are missing, which is more helpful than having blank files that do nothing other than return an empty lua table
  • B(asic Structure)
    all the folders in there with a .txt in each explaining what goes in it, possibly also all the basic gamedata files and {mod/lobby/engine}options.lua
  • C(omplete Example)
    has examples of all files and multiple examples of lua unit/weapon/feature defs and hopefully some simple gadgets/widgets
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

Perfect :P

For the C: examples of various archetypes of animation (building loop, walker, tank), movement (land units, gunship, bomber, fighter) and weapons (laser, ballistics projectile, homing missile) would be handy - you could always borrow them from other mods: I'm sure the devs would be honoured to have their unit used as an example (ask first though :wink: )

I found Nanoblobs by the way - it's great in that it's very simple, with only limited units and resources, and yet there's a rather large amount of code behind it :?
Also you can tell that it's quite old: the scripts are .cob and the unit definitions are .fbi - the translation is fairly simple though I think...
User avatar
wilbefast
Posts: 255
Joined: 14 Oct 2009, 18:04

Re: Mod Question Repository... Questions come in, answers go out

Post by wilbefast »

I've got a few questions about scripting using lua. First of all I need (a lot) more examples, especially builders, if there actually are any examples of lua unit scripts lying around :?

My problems so far are:
1. Unit can drive up vertical cliffs, no matter what MaxSlope is set to, even 0 (no movement defs have been done yet - could this be why?)
2. Unit won't turn head in direction it's supposed to be firing
3. Unit can be given order to- but won't -build, reclaim or repair (obviously: I haven't written the scripts yet :P )
Here is the script:
http://pastebin.com/mb2e9c02

At the moment I'm working from the arm "stumpy" script converted to lua:
http://pastebin.com/f7fc0a0dc

Code: Select all

function script.AimWeapon(weaponID, heading, pitch)
	Signal(SIG_AIM)
	SetSignalMask(SIG_AIM)
	Turn(turret, y_axis, heading, math.rad(90))
	Turn(barrel, x_axis, -pitch, math.rad(50))
	WaitForTurn(turret, y_axis)
	WaitForTurn(barrel, x_axis)
	StartThread(RestoreAfterDelay)
	return true
end
I'm using AimWeapon1(heading, pitch) for simplicity sake. SIG_AIM is a constant = 2. I'm guessing it could be anything, it's just more readable to write "Signal(SIG_AIM)" than "Signal(2)", especially when you're using scores of different signals.
Anyway, I understand this piece of code as follows, but I know that I'm wrong somewhere because I can't get it to work for my own tank :shock:
  • If the unit acquires a target the game will tell the script which weapon, which heading and which pitch this target can be found at.
  • The script tells the unit to stop and start over if a new target acquisition order comes to interrupt it (eg -track or change targets).
  • Turn the turret in the direction of the target at a speed of pi/2 radians per frame (?)
  • Raise or lower the barrel so as to point it directly at the target.
  • Wait for these "Turn" operations to be complete (NB: aiming can be interrupted during this time as stated above).
  • Return back to default position:

Code: Select all

local function RestoreAfterDelay(unitID)
	Sleep(RESTORE_DELAY)
	Turn(turret, y_axis, 0, math.rad(90))
	Turn(barrel, x_axis, 0, math.rad(50))
end
RESTORE_DELAY is another constant - again this is in frames or milliseconds or something... not sure. This is a game so I'm gunna to say frames :-)

Anyway, I'm quite unsure of why the darn thing won't turn its turret for me - the wheel work, I've got recoil and lasers coming from the appropriate place - it can even explode! But no turn-y turret :cry:

Please help!


edit: this is really weird - all of the above has stopped working now that I've added the "restore after delay" bit, but goes back to normal when it's removed... there must be a problem there...

edit: "maxAngleDif = 90"... oops... maybe that's the problem. Nope. Apparently not - is there any documentation for defining weapons? Might have made a mistake somewhere in the fbi lua (I defined the weapon inside the unit def)... For the moment I can only find the main one.
Locked

Return to “Game Development Tutorials & Resources”