OTA-> Spring lua capabilities

OTA-> Spring lua capabilities

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
Ba-
Posts: 16
Joined: 09 Jan 2008, 23:16

OTA-> Spring lua capabilities

Post by Ba- »

Hi, I'm new to the Spring forums, and have only looked around them so far. I made a TA mod, based primarily on unit upgrades and other fancy techniques like that, and have now decided that the Spring engine has far more possibilities and less limits than ota in the upgrading world. Most of my questions with lua have been answered already by helpful users, the wiki, and these forums, but I still have a few questions...

In ota, I used detect scripts that would tell a script whether or not a certain unit was built or not. With this, I made an upgrade system where you build an upgrade, the lab loads this unit, and units built check to see if the upgrade has been built, and either upgrade or don't upgrade based on this. First off, i'm not sure if this detect system is supported by spring (it was fairly new in TA, and required Xon Dlls to work properly), or if there is simply an easier way by using lua. If it is, I need to basically learn how to use this effectively.

Additionally, I am wondering if by using lua I can customize build menus ingame. I think every way a workaround could be used, since lua apparently can take a unit and then make it into a different unit, the second unit having a different build menu. However, this would be a huge pain for factories with more than one upgrade, since a multitude of units would have to be created for the different combinations of researched upgrades. Anyway, the main use of this would allow me to use enhanced build pics when a unit is upgraded, or allow for new units to be built under certain circumstances, as well as making sure that some silly gamers do not research the same upgrade twice ;).

I'm also wondering how lua can 'upgrade' a unit. Does this upgrading require that I make an entirely different unit that has different stats, including a new script, unit.fbi file... , or does upgrading work so that it can be the same unit, but there is i.e. MaxDamage2=XXXX;. The latter would be much easier, but could lead to some confusing fbi files for units that change dramatically (perhaps both ways can be used?).

Lastly, I am wondering if there is somewhere i can take lua codes from and use as examples, because I don't exactly know where to start with lua.

Thanks!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: OTA-> Spring lua capabilities

Post by KDR_11k »

Some things (e.g. health, some weapon attributes) can be adjusted dynamically but for most you'll have to spawn a new unit. Build menus can be adjusted dynamically, yes.

A popular source of Lua is Complete Annihilation.

As for the research upgrade, I know I've used something like that in pure COB in Spring already but it probably worked different in detail (the mod is CvC version 0.4). Of course research is pretty easy to implement in Lua, you'd make a lua variable remember which upgrades you made and units just check what the variable says instead of doing any complicated detections.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: OTA-> Spring lua capabilities

Post by lurker »

Don't forget about the cob variables now. You can do research extremely easily in cob with simple gets and sets to a team variable.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: OTA-> Spring lua capabilities

Post by zwzsg »

Hi Ba-!

Xon's dll new get/set are the same in Spring! (Beside the one about which computer owns the unit, because Spring doesn't use the same networking system, only orders are sent and all computers compute for all units).

You can do upgrades the TA ways, by unlocking weapons, showing model parts, activating damage modifier, etc... (and even more, such set MAX_SPEED) withing the COB/BOS.

Or you can use the LUA way. I don't know exactly what properties can LUA change, but I guess even more than the script. And also LUA can be used to morph into another (in which case you have two FBI, two scripts, two models, etc..)
Ba-
Posts: 16
Joined: 09 Jan 2008, 23:16

Re: OTA-> Spring lua capabilities

Post by Ba- »

yay! The all-powerful zwzsg is here! Active in both TAU and spring forums... impressive :).

Any chance i can find exactly where a list of these new get/set commands are, like set MAX_SPEED;? This could be very helpful...

And i guess i'll have to decide, if lua is best or if ota detect scripts are the best... Lua sounds like it'd be easier if I can figure out how to use it correctly. Plus, if i wanted to do something like upgrades that affect units already built, rather than eating up CPU with detect scripts looping, I could use a simple lua variable that is switched when a specific unit is built, and check to see the status of that variable with every unit.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: OTA-> Spring lua capabilities

Post by zwzsg »

Any chance i can find exactly where a list of these new get/set commands are.
The changelog and the source code are the best documentation you'll ever find.

I made myself that:
//==============================================================================
//
// Constants and macros for Spring /units/*.BOS
//
// Made by merging the exptype.h and sfxtype.h that are tradionally shipped with Scriptor
// Which are themselves edited from the ones inside Cavedog's Totala1.hpi
// And the #define from https://spring.clan-sy.com/svn/spring/t ... stance.cpp
//
//==============================================================================

#ifndef SPRING_SCRIPTS_H
#define SPRING_SCRIPTS_H


// To use with the "emit-sfx" command:

// Vector-based special effects
#define SFXTYPE_VTOL 0
#define SFXTYPE_THRUST 1
#define SFXTYPE_WAKE1 2
#define SFXTYPE_WAKE2 3
#define SFXTYPE_REVERSEWAKE1 4
#define SFXTYPE_REVERSEWAKE2 5

// Point-based (piece origin) special effects
#define SFXTYPE_POINTBASED 256
#define SFXTYPE_WHITESMOKE (SFXTYPE_POINTBASED | 1)
#define SFXTYPE_BLACKSMOKE (SFXTYPE_POINTBASED | 2)
#define SFXTYPE_SUBBUBBLES (SFXTYPE_POINTBASED | 3)
// TA:K sfx, maybe not implemented in Spring
#define SFXTYPE_SMALLDAMAGEFLAME (SFXTYPE_POINTBASED | 4)
#define SFXTYPE_MEDIUMDAMAGEFLAME (SFXTYPE_POINTBASED | 5)
#define SFXTYPE_LARGEDAMAGEFLAME (SFXTYPE_POINTBASED | 6)

// Probably not implemented in Spring, TA:K stuff
#define PLAYSOUND_PRIORITY_BATTLE 4

// Probably not implemented in Spring, probably TA:K stuff
#define SFXOCCUPY_AIR 5 // SFX Occupy States

// To use with the "explode" command:
#define SHATTER 1 // The piece will shatter instead of remaining whole
#define EXPLODE_ON_HIT 2 // The piece will explode when it hits the ground
#define FALL 4 // The piece will fall due to gravity instead of just flying off
#define SMOKE 8 // A smoke trail will follow the piece through the air
#define FIRE 16 // A fire trail will follow the piece through the air
#define BITMAPONLY 32 // The piece will not fly off or shatter or anything. Only a bitmap explosion will be rendered.
#define BITMAP1 256
#define BITMAP2 512
#define BITMAP3 1024
#define BITMAP4 2048
#define BITMAP5 4096
#define BITMAPNUKE 8192
#define BITMAPMASK 16128 // Mask of the possible bitmap bits

// Probably not implemented in Spring, TA:K stuff
#define EXPTYPE_SMALLEXPLOSION 256
#define EXPTYPE_MEDIUMEXPLOSION 512
#define EXPTYPE_LARGEEXPLOSION 1024
#define EXPTYPE_XLARGEEXPLOSION 2048
#define EXPTYPE_BLOODEXPLOSION 4096
#define EXPTYPE_SMALLSMOKE 8192
#define EXPTYPE_MEDIUMSMOKE 16384
#define EXPTYPE_XLARGESMOKE 65536

// Probably not implemented in Spring, TA:K stuff (DT stands for Damage Type)
#define DT_FIRE 2
#define DT_EXPLOSION 3
#define DT_PARALYZER 4

// Indices for set/get value
#define ACTIVATION 1 // set or get
#define STANDINGMOVEORDERS 2 // set or get
#define STANDINGFIREORDERS 3 // set or get
#define HEALTH 4 // get (0-100%)
#define INBUILDSTANCE 5 // set or get
#define BUSY 6 // set or get (used by misc. special case missions like transport ships)
#define PIECE_XZ 7 // get
#define PIECE_Y 8 // get
#define UNIT_XZ 9 // get
#define UNIT_Y 10 // get
#define UNIT_HEIGHT 11 // get
#define XZ_ATAN 12 // get atan of packed x,z coords
#define XZ_HYPOT 13 // get hypot of packed x,z coords
#define ATAN 14 // get ordinary two-parameter atan
#define HYPOT 15 // get ordinary two-parameter hypot
#define GROUND_HEIGHT 16 // get land height, 0 if below water
#define BUILD_PERCENT_LEFT 17 // get 0 = unit is built and ready, 1-100 = How much is left to build
#define YARD_OPEN 18 // set or get (change which plots we occupy when building opens and closes)
#define BUGGER_OFF 19 // set or get (ask other units to clear the area)
#define ARMORED 20 // set or get

#define WEAPON_AIM_ABORTED 21 // Not implemented in Spring, TAK stuff
#define WEAPON_READY 22 // Not implemented in Spring, TAK stuff
#define WEAPON_LAUNCH_NOW 23 // Not implemented in Spring, TAK stuff
#define FINISHED_DYING 26 // Not implemented in Spring, TAK stuff
#define ORIENTATION 27 // Not implemented in Spring, TAK stuff
#define IN_WATER 28
#define CURRENT_SPEED 29
#define MAGIC_DEATH 31 // Not implemented in Spring, TAK stuff
#define VETERAN_LEVEL 32
#define ON_ROAD 34

#define MAX_ID 70
#define MY_ID 71
#define UNIT_TEAM 72
#define UNIT_BUILD_PERCENT_LEFT 73
#define UNIT_ALLIED 74
#define MAX_SPEED 75
#define CLOAKED 76
#define WANT_CLOAK 77
#define GROUND_WATER_HEIGHT 78 // get land height, negative if below water
#define UPRIGHT 79 // set or get
#define POW 80 // get
#define PRINT 81 // get, so multiple args can be passed
#define HEADING 82 // get
#define TARGET_ID 83 // get
#define LAST_ATTACKER_ID 84 // get
#define LOS_RADIUS 85 // set or get
#define AIR_LOS_RADIUS 86 // set or get
#define RADAR_RADIUS 87 // set or get
#define JAMMER_RADIUS 88 // set or get
#define SONAR_RADIUS 89 // set or get
#define SONAR_JAM_RADIUS 90 // set or get
#define SEISMIC_RADIUS 91 // set or get
#define DO_SEISMIC_PING 92 // get
#define CURRENT_FUEL 93 // set or get
#define TRANSPORT_ID 94 // get
#define SHIELD_POWER 95 // set or get
#define STEALTH 96 // set or get
#define CRASHING 97 // set or get, returns whether aircraft isCrashing state
#define CHANGE_TARGET 98 // set, the value it's set to determines the affected weapon
#define CEG_DAMAGE 99 // set
#define COB_ID 100 // get
#define PLAY_SOUND 101 // get, so multiple args can be passed
#define KILL_UNIT 102 // get KILL_UNIT(unitId, SelfDestruct=true, Reclaimed=false)
#define ALPHA_THRESHOLD 103 // set or get
#define SET_WEAPON_UNIT_TARGET 106 // get (fake set)
#define SET_WEAPON_GROUND_TARGET 107 // get (fake set)
#define LUA0 110
#define LUA1 111
#define LUA2 112
#define LUA3 113
#define LUA4 114
#define LUA5 115
#define LUA6 116
#define LUA7 117
#define LUA8 118
#define LUA9 119
#define FLANK_B_MODE 120 // set or get
#define FLANK_B_DIR 121 // set or get, set is through get for multiple args
#define FLANK_B_MOBILITY_ADD 122 // set or get
#define FLANK_B_MAX_DAMAGE 123 // set or get
#define FLANK_B_MIN_DAMAGE 124 // set or get
#define WEAPON_RELOADSTATE 125 // get (with fake set)
#define WEAPON_RELOADTIME 126 // get (with fake set)
#define WEAPON_ACCURACY 127 // get (with fake set)
#define WEAPON_SPRAY 128 // get (with fake set)
#define WEAPON_RANGE 129 // get (with fake set)
#define WEAPON_PROJECTILE_SPEED 130 // get (with fake set)

// NOTE: shared variables use codes [1024 - 5119]

#endif // SPRING_SCRIPTS_H
Because no one wants to recode Scriptor, the "set" that needs two or more parameters use "get". Even though they are outputs and not inputs. Like "get PRINT(1,2,3)" to output 1,2,3 on the console.

But BOS/COB is out of style, all the cool guy do LUA now.
Plus, if i wanted to do something like upgrades that affect units already built, rather than eating up CPU with detect scripts looping, I could use a simple lua variable that is switched when a specific unit is built, and check to see the status of that variable with every unit.
You can do that in Cob/Bos, with the shared variables:
changelog wrote:- Added global, team, and ally GET/SET variables to COB scripts
1024 - 2047: 1024 global variables
2048 - 2175: 128 variables per team (the COB script unit's team)
2176 - 2303: 128 variables per allyteam (the COB script unit's allyteam)
- Added 8 shared per-unit variables (example: GET UNIT_VAR_START -unitID value)
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Re: OTA-> Spring lua capabilities

Post by Peet »

zwzsg wrote:Because no one wants to recode Scriptor
Lurker is, slowly.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: OTA-> Spring lua capabilities

Post by lurker »

Peet wrote:
zwzsg wrote:Because no one wants to recode Scriptor
Lurker is, slowly.
Unless imbaczek finishes his code. Or I work on his code.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: OTA-> Spring lua capabilities

Post by trepan »

If someone is planning to (re)write a BOS->COB compiler, it
might not be a bad idea to write the compiler and assembler
code sections as C/C++ libraries. Might make mod dev'ing
easier if you could simply reload a BOS script using .reloadcob.
Plus, having a decent BOS compiler working in linux would be
nice (I currently use boscompiler082 in Wine).
Ba-
Posts: 16
Joined: 09 Jan 2008, 23:16

Re: OTA-> Spring lua capabilities

Post by Ba- »

I don't quite get how you really use lua for a particular unit script. Do you like have ARMCOM.lua instead of ARMCOM.cob?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: OTA-> Spring lua capabilities

Post by Forboding Angel »

Ba- wrote:I don't quite get how you really use lua for a particular unit script. Do you like have ARMCOM.lua instead of ARMCOM.cob?
Yessir
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: OTA-> Spring lua capabilities

Post by KDR_11k »

AFAIK no, you can only replace the FBI with lua, not the COB.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: OTA-> Spring lua capabilities

Post by Forboding Angel »

OH CRAP! I'm sorry, I misread and thought you said unit.fbi instead of unit.cob

KDR is correct. Sorry, totally misread that one.
Ba-
Posts: 16
Joined: 09 Jan 2008, 23:16

Re: OTA-> Spring lua capabilities

Post by Ba- »

I see. Does this allow for manipulation of fbi traits? Or morphing from one unit to the next?

Wondering what program I should use for .lua files because notepad does not organize it in an eye-pleasing way.
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: OTA-> Spring lua capabilities

Post by Gnomre »

Morphing's been around for quite some time, and AF made a prerequisite gadget which is probably several pages back in this forum by now.

Those files look garbled due to the different line return methods various OSes/programs use. Long story short, open them once in Wordpad, hit ctrl+s, and then they'll look fine in notepad. Of course, it'd be easier to just find some other notepad replacement program which handles all methods correctly to begin with. Lots of people like Notepad++ but there are plenty of others out there.
Post Reply

Return to “Lua Scripts”