

Moderator: Moderators
Err, one of those calls comes first. If the other doesn't get the real damage number that's been changed it sounds like a bug.Tobi wrote:An example of a clash: you can now override engine damage using the UnitPreDamaged gadget call-in, or using the HitByWeaponId unit script call-in. (And if you use both the new damage of one of them will override the new damage of the other of course.)
lua unit script: added GetPieceTranslation, GetPieceRotation, GetPiecePosDir
edit1: Does that mean it's still useable in exactly the same way, just the implementation has moved from the engine to the framework?unit script: removed Create (framework handles it)
Yeah, the framework already handled it before, and framework explicitly nilled the Create function before passing script to engine, because there was a bit of an order of initialization problem. (When engine calls Create it runs too early for framework to be able to properly handle calls to e.g. Sleep or WaitForTurn from inside Create..) Indeed for the scripts nothing changes.FLOZi wrote:Triple post:
edit1: Does that mean it's still useable in exactly the same way, just the implementation has moved from the engine to the framework?unit script: removed Create (framework handles it)
edit2: yeah, having actually bothered to examine the code, that's what the change was.![]()
Also I think FX might be a better name for the table than SFX, but maybe that's just me. Not terribly important.
Code: Select all
function script.QueryWeapon(u, w)
if (w == 3) then return coaxflare end
return coaxflare
end
Code: Select all
local queryWeaponPieces = { flare, flare, coaxflare }
function script.QueryWeapon(u, w)
return queryWeaponPieces[w]
end
Code: Select all
function script.QueryWeapon1() return flare end
function script.QueryWeapon2() return flare end
function script.QueryWeapon3() return coaxflare end
Code: Select all
function script.FireWeapon(u, w)
if (w <= 2) then
-- main gun code
else
-- machine gun code
end
end
Code: Select all
function script.FireWeaponMainGun(u)
--stuff
end
function script.FireWeaponMachineGun(u)
-stuff
end
function script.FireWeapon(u, w)
if (w <= 2) then
return FireWeaponMainGun(u)
else
return FireWeaponMachineGun(u)
end
end
Code: Select all
-- WEAPON 1
function script.FireWeapon1(u) --FireWeaponMainGun
--stuff for main gun
end
-- WEAPON 2
script.FireWeapon2 = script.FireWeapon1
-- WEAPON 3
function script.FireWeapon3(u) --FireWeaponMachineGun
--stuff for machine gun
end
There is currently a limit of 32 weapons per unit. (MAX_WEAPONS_PER_UNIT in code)SpliFF wrote:My only concern is will (does) the engine arbitrary enforce a limit on number of weapons due to this convention (or other legacy COB issues)? Will unit scripts provide AimFromWeapon50? I have a particular interest in building some very large and complex units.
Just added some compatibility 'dispatching' code to framework alreadySpliFF wrote: Other than that I concede the old way is probably cleaner and faster for the common case (a unit of 1-5 weapons with different properties)
Yes, BUT, VFS.Include will load (that means decompress), parse and compile the Lua file each time it's run. That means each time a unit is created, double work is done.SpliFF wrote:Another question. Does VFS.Include work with unit scripts? It seems there would be many cases where units share common code.
Code: Select all
include ( filename ) -> ...
Code: Select all
COB : 5130000 calls in 10016 ms -> 513000 calls/second
LUA : 21450000 calls in 10001 ms -> 2145000 calls/second
none : 2430290000 calls in 10000 ms -> 243029000 calls/second
Code: Select all
COB: 90000*1k calls in 10147 ms -> 8870000 calls/second
Lua: 40000*1k calls in 11754 ms -> 3403000 calls/second
did you localized those functions in lua?Tobi wrote:(This isn't really surprising since Move/Turn in Lua are yet another call-out, while in COB move and turn have special opcodes and are implemented directly in the virtual machine.)