Page 1 of 1

Revealing unit when unit is attacking

Posted: 01 Oct 2010, 05:27
by GamerSg
Im modifying Spring 1944 atm and am trying to make artillery units which have very very long firing range, to be revealed when they fire even if the opponent does not have any unit in range of the artillery. This behaviour is similar to starcraft1 where siege tanks on high ground or far range would be revealed when they fired.

Where should i look to script this behaviour in?

Re: Revealing unit when unit is attacking

Posted: 01 Oct 2010, 06:32
by aegis
you can call Spring.SetUnitAlwaysVisible from a gadget to reveal the unit when it fires, then use a timer to call it again to hide the unit after a bit

http://springrts.com/wiki/Lua_SyncedCtrl#Unit_LOS

Re: Revealing unit when unit is attacking

Posted: 01 Oct 2010, 07:32
by KDR_11k
Alternatively you can manually override the LOS state with some call-ins. Still, I think it would be a better idea to instead show artillery warnings on the location of the artillery without revealing the specific unit (kinda like Micro Modules' artillery warning, except focused on the launcher instead of the target).

Re: Revealing unit when unit is attacking

Posted: 01 Oct 2010, 07:40
by GamerSg
Thanks for the help guys, ill look into your recommendations.

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 08:36
by GamerSg
Just another question,

I do not seem to be able to locate a callin which is related to a unit firing.

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 08:50
by Argh
Call it from the Unit's script, or you can use projectileCreated()

(caution, you will need to filter it very carefully or it will eat a lot of CPU)

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 10:49
by GamerSg
I agree, using the unit script should be far more efficient instead of using a callin and checking everytime any unit fires.

However i believe that the unit scripts are not coded in Lua but rather a C like language. I have been unable to locate any documentation/tutorials on unit scripting. Anyway, i opened up my unit's script and tried adding the visibility which (expected) could not compile.

Code: Select all

FireWeapon1()
{
	emit-sfx PAK40_Muzzleflash from flare;
	emit-sfx PAK40_MuzzleDust from flare;
	move barrel to z-axis RECOIL now;
	//Fire teh weap0n!!!11
	CREW_FIRING;
	get DO_SEISMIC_PING(15);
	sleep 100;
	move barrel to z-axis [0] speed RETURN_SPEED;
	//Now reload...
	CREW_RELOADING
	set STEALTH to 0;
	set VISIBLE to 1;  //I added this line
	sleep VISIBLE_PERIOD;
	set VISIBLE to 0; //I added this line
	set STEALTH to 1;
}
Mainly the line set VISIBLE to 1;
Scriptor complains that there is no variable VISIBLE defined.

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 11:17
by Argh
They're (mainly) still using BOS. You need to make changes and compile the script with Scriptor.

Calling Lua (to set AlwaysVisible until a gameframe timer expires) is straightforward:

Code: Select all

lua_MakeMeVisible(arg) {return 0;}//This empty script hooks into Spring's Lua system

FireWeapon1()
{
   emit-sfx PAK40_Muzzleflash from flare;
   emit-sfx PAK40_MuzzleDust from flare;
   move barrel to z-axis RECOIL now;
   //Fire teh weap0n!!!11
   CREW_FIRING;
   get DO_SEISMIC_PING(15);
   sleep 100;
   move barrel to z-axis [0] speed RETURN_SPEED;
   //Now reload...
   CREW_RELOADING
   set STEALTH to 0;
   sleep VISIBLE_PERIOD;
   set STEALTH to 1;
   call-script lua_MakeMeVisible(time);//This calls a Lua function MakeMeVisible() with the argument "time", the amount of time to stay visible after firing
}
In Lua, to deal with calls from COB, you just need to set up the function MakeMeVisible in a Gadget function, and this:

Code: Select all

function MakeMeVisible(unitID,unitDef,team,time)
--do Lua logic here that passes to something dealt with in gameFrame
end
gadgetHandler:RegisterGlobal("MakeMeVisible", MakeMeVisible)
...makes Spring able to handle COB-->Lua callout behavior correctly.

Now you just need to write a Gadget timing loop for this, which (if you're not familiar with Lua yet) will be a bit of an adventure, as it will involve dealing with a table. Good luck :-)

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 15:00
by Google_Frog
If you want to do it the easy way convert the script to lua. Unit scripts are in Cob because they were written before lua unit scripts were available.

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 15:10
by FLOZi
If you want to do it the easy way in s44, modify game_ammo.lua to set the unit always visible when it detects it has fired (Up to a 3 second delay with this method though :P )

Re: Revealing unit when unit is attacking

Posted: 04 Oct 2010, 17:51
by KDR_11k
IMO just use the explosion of the shot as the trigger so there's no early warning, only a position to counter-battery fire at.