I figure this is the forum for BOS script questions since it seems to be the closest one.
I had this idea to make units have shields that are disabled if specific other units walk into their range. Since shields can be disabled in the script (although I don't know how) I want to try implementing it through that before asking for a shield jammer feature. So is there a way to check if a unit of a given type (not just any random unit) is closer than a given distance? Preferrably if the check could tell friend from foe?
Also, How the hell do you make hovercrafts stay above water? The floater tag doesn't do that. I asked that in the CvC thread twice and still don't know.
Detecting nearby units in script?
Moderators: MR.D, Moderators
Move the root piece up on the y
Also make sure the hover's movementclass name is "TANKHOVER2" or "TANKHOVER3", spring is stupidly hardcoded to only accept hover move classes by those names (it might actually just be "TANKHOVERX", I don't recall).
As for detecting nearby units, well, here:
This was done by zwzsg for OTA, but in theory it'll work with Spring. It basically scans around for units matching a certain height, then calculates the distance to them. Here's unit_height_list.h:
The catch is that the heights as read by TA are different than Spring, so you'll need to go manually measure each one using the BriDoDon or zwzsg's hacked sensor tower. There's no way to calculate the numbers outside of a game engine right now.
Hope that helps.

As for detecting nearby units, well, here:
Code: Select all
/*============================================================
Leader Bonus
This script is used for applying bonuses to SWTA Rebel infantry
when in the presence of a Jedi Knight or Master. All units which
use this script must have a piece named "bonus" in its 3do file,
which is just some graphical way of showing the unit has a bonus
active. The unit must also have a DamageModifier in its FBI.
Anyhow, to use this script:
1) At the beginning of the script of the unit that
must run it (currently all rez producer and com) add:
#include "leader_bonus.h"
2) Then, in the Create() part of the script, add:
INIT_LEADER_BONUS
List of units using that script:
REBAVRKT
REBCMNDO
REBELITE
REBMMRB
REBRKT
REBSPY
REBTROOPER
REBWOOK
============================================================*/
#ifndef Leader_Bonus_H
#define Leader_Bonus_H
#include "unit_height_list.h"
#define MIN_NUMBER_FOR_BONUS 1 //number of units giving bonus that must be present to gain the bonus //including itself
#define DIST_MAX_FOR_BONUS [120] //radius under which to look for units giving bonus (120=300 pixels)
#define BONUS_CHECK_REFRESH 2000 //bonus update period in ms
#define INIT_LEADER_BONUS start-script BonusCheck();
BonusCheck()//Check for nearby friend giving bonus
{
var unit_ID, klc, self_ID, min_ID_of_player, max_ID_of_player, bonus_giver_around, h;
set ARMORED to FALSE;
// Start: Find ID of self and calculate ID range of player
self_ID=0-1073741823;
for(unit_ID=MAX_ID;unit_ID>=MIN_ID;--unit_ID)
{
if (get UNIT_XZ(unit_ID)==get PIECE_XZ(ground))
{
if (get UNIT_Y(unit_ID)==get PIECE_Y(ground))
{
//Note: with luck, the xz, and the y, of the plant are different from the xz and y of the unit. If so you may skip the height check, which allow to modify the model without having to re-measure the unit and update its height constant in the script. Even if the xz, and y are the same as the unit, you may skip the height check if the self_ID is only used to get the player's unit's range, since the factory and the unit belongs to same player. Or you could turn it upside down and use that part to actually measure ingame the height of the unit so as to find similar units without having to measure and report the height manually after each model change.
//if (get UNIT_HEIGHT(unit_ID)==height_of_self)// Height of itself.
//{
self_ID=unit_ID;
//}// height check disabled, i don't care if I pick up the factory instead
}
}
}
if (self_ID==0-1073741823)//if self not found
{
//We're in deep trouble!
//Fill the screen with explosion and debris, unhide a face sporting an error sign, deactivate any fancy scripting.
while(TRUE)
{
explode torso type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
sleep 100;
}
}
#if UNDER_SPRING
min_id_of_player=MIN_ID;
max_id_of_player=MAX_ID;
#else
klc=self_id - 1;
klc=klc/UNITS_PER_PLAYER;//here a trucation occurs
klc=klc*UNITS_PER_PLAYER+1;
min_id_of_player=klc;
max_id_of_player=min_id_of_player+UNITS_PER_PLAYER;
#endif
// End: Find ID of self and calculate ID range of player
// Start: the constant check for bonus givers
while(TRUE)
{
bonus_giver_around=0;
dont-cache bonus;
for(unit_ID=max_ID_of_player;unit_ID>=min_ID_of_player;--unit_ID;)
{
if (get UNIT_XZ(unit_ID))
{
h=get UNIT_HEIGHT(unit_ID);
if (IS_BONUS_GIVING_LEADER)// if unit is of correct type
{
if ((get XZ_HYPOT( get UNIT_XZ(unit_ID) - get PIECE_XZ(ground) ))< DIST_MAX_FOR_BONUS)// if unit is in range
{
++bonus_giver_around;
}
}
}
}
if (bonus_giver_around>=MIN_NUMBER_FOR_BONUS)
{
turn bonusprop to y-axis get XZ_ATAN(4) now;
move bonus to z-axis [-3] now;
show bonus;
set ARMORED to TRUE;
}
if (bonus_giver_around<MIN_NUMBER_FOR_BONUS)
{
hide bonus;
set ARMORED to FALSE;
}
sleep BONUS_CHECK_REFRESH;
}
}
#endif
Code: Select all
// List of the height of all SWTA units, both in TA and in Spring (height are measured differently in Spring)
// Also contains at the end stuff like IS_DROID_COMMAND_CENTER that list bunch of unit height for scripts to refer to
// Someone go measure the heights under Spring
// Also, someone remove all the -AI lines
// Finally, someone go rewrite the IS_INFANTRY line with their unitnames. With possibly some if# to take advantages of some troops having same heights.
// PS: off course, if someone could measure the height of everything, that would be nice
// Open with Scriptor
// Use TAB and not space between the UNITNAME and the value
#ifndef Unit_Height_List_H
#define Unit_Height_List_H
#include "unit_limit_and_spring.h"
#if UNDER_SPRING
// Here shall go the height under Spring. Because in Spring heights are different than in TA
#define IMPDROIDP 5320826// Droid Plant
#define IMPCOM 0// Yes, this is a WRONG value, this is just to define it with a numeric value so some script compiles.
#define REBCOM 0// Yes, this is a WRONG value, this is just to define it with a numeric value so some script compiles.
#else
#define IMPAAA
#define IMPAAP
#define IMPAMEX
#define IMPAP
#define IMPARTY
#define IMPATAA
#define IMPATAT
#define IMPATAV
#define IMPATGANT
#define IMPATPT
#define IMPATST
#define IMPATSTAS
#define IMPBAX
#define IMPBDROID 1903127// Basic Battle Droid
#define IMPBDROIDC 1903127// Battle Droid Captain
#define IMPBOMBARD
#define IMPBTANK
#define IMPCAP
#define IMPCAV
#define IMPCLOUD
#define IMPCLOUD-AI
#define IMPCOM 1369758// Commander
#define IMPCOND
#define IMPCOND-AI
#define IMPCONW
#define IMPCUV
#define IMPDES 2027954// Rolling Droideka
#define IMPDROIDP 5500218// Droid Plant
#define IMPEGEN 2054554// Mega Fusion: I changed the 3do because 1966080 was the same as reb_repulsor_plant and imp_veh_plant and imp_moho_mex
#define IMPESTOR
#define IMPEWEB
#define IMPEWEB-AI
#define IMPFLAME 1784218// Flamer Trooper
#define IMPFUS 2054554// Fusion: I changed the 3do because 1966080 was the same as reb_repulsor_plant and imp_veh_plant and imp_moho_mex
#define IMPFUS-AI 2054554// Fusion: I changed the 3do because 1966080 was the same as reb_repulsor_plant and imp_veh_plant and imp_moho_mex
#define IMPGEO 2739405// Geo: I changed the 3do because 2621440 was the same as reb_energy_storage
#define IMPGEO-AI 2739405// Geo: I changed the 3do because 2621440 was the same as reb_energy_storage
#define IMPGUNB
#define IMPGUNB-AI
#define IMPHAIL
#define IMPIONC
#define IMPLAAT
#define IMPLAAT-AI
#define IMPLAATC
#define IMPMARK 2130993// Walker Droid
#define IMPMEWEB 1788314// Machinegun Deployer
#define IMPMEX
#define IMPMEX-AI
#define IMPMKR
#define IMPMOBILEA
#define IMPMSLB
#define IMPMSLB-AI
#define IMPMSLT
#define IMPMSTOR
#define IMPMUAT
#define IMPPROBOT 1415040// Probe Droid
#define IMPREP 1784218// Repeater Trooper
#define IMPRKT 1784218// Missile Trooper
#define IMPSAND
#define IMPSBDROID 2214698// Super Battle Droid
#define IMPSBIKE 1409936// Biker
#define IMPSCIM
#define IMPSCIM-AI
#define IMPSENS
#define IMPSITHA
#define IMPSITHL
#define IMPSOLAR 1277952// Solar
#define IMPSOLAR-AI 1277952// Solar
#define IMPSTEMP
#define IMPSTORM 1784218// StormTrooper
#define IMPTIEA
#define IMPTIEA-AI
#define IMPTIEB
#define IMPTIEB-AI
#define IMPTIE-C
#define IMPTIED
#define IMPTIED-AI
#define IMPTIEDR
#define IMPTIEDR-AI
#define IMPTIEF
#define IMPTIEF-AI
#define IMPTIEI
#define IMPTIEI-AI
#define IMPTIEP
#define IMPTIEP-AI
#define IMPTIES
#define IMPTROOPC
#define IMPTUG
#define IMPTURBOL
#define IMPVP
#define IMPWP
#define REBAA
#define REBAAA
#define REBAAP
#define REBABAX
#define REBADVSENS
#define REBAHOVER
#define REBAMEX
#define REBAP
#define REBARTY
#define REBAT
#define REBATGAR
#define REBATPT
#define REBAVP
#define REBAVRKT 1732608// Heavy Rocket Trooper
#define REBAWING
#define REBAWING-AI
#define REBBAX
#define REBBOMB
#define REBBWING
#define REBBWING-AI
#define REBCMNDO 1585594// Commando
#define REBCOM 1960334// Commander
#define REBCOND
#define REBCOND-AI
#define REBCONH
#define REBCORC
#define REBCUV
#define REBEGEN 2219870// Mega Fusion
#define REBELITE 1732608// Elite Veteran Heavy Trooper
#define REBESPO
#define REBESTOR
#define REBEWING
#define REBEWING-AI
#define REBFREE
#define REBFUS 2265745// Fusion
#define REBFUS-AI 2265745// Fusion
#define REBGEO 1638400// Geo
#define REBGEO-AI 1638400// Geo
#define REBGOLAN
#define REBHOVER
#define REBHT
#define REBIONC
#define REBJEDI 1774747// Jedi Knight
#define REBJMAS 1760002// Jedi Master
#define REBJPAD
#define REBJTEMP
#define REBKWING
#define REBKWING-AI
#define REBLAND
#define REBMEX
#define REBMEX-AI
#define REBMKR
#define REBMMRB 1736704// Machinegun Deployer
#define REBMRB
#define REBMRB-AI
#define REBMSTOR
#define REBRKT 1732608// Missile Trooper
#define REBSABO
#define REBSAND
#define REBSCAN
#define REBSENS
#define REBSOLAR 2064384// Solar
#define REBSOLAR-AI 2064384// Solar
#define REBSPEEDER
#define REBSPEEDER-AI
#define REBSPOTTER
#define REBSPY 1732608// Bothan Spy
#define REBSTORM
#define REBSWOOP 1686974// Biker
#define REBTORP
#define REBTORP-AI
#define REBTRANS
#define REBTROOPER 1732608// Basic Trooper
#define REBTUG
#define REBTWING
#define REBTWING-AI
#define REBULAV
#define REBVP
#define REBVWING
#define REBVWING-AI
#define REBWOOK 1925120// Wookie
#define REBXWING
#define REBXWING-AI
#define REBYWING
#define REBYWING-AI
#define REBZ95HH
#define REBZ95HH-AI
#endif
#define IS_INFANTRY (h==1409936 || h==1415040 || h==1585594 || h==1686974 || h==1732608 || h==1736704 || h==1784218 || h==1788314 || h==1903127 || h==1925120 || h==2214698 || h==2027954)
#define IS_DROID (h==IMPMARK || h==IMPPROBOT || h==IMPDES || h==IMPBDROID || h==IMPBDROIDC || h==IMPSBDROID)
#define IS_DROID_COMMAND_CENTER (h==IMPDROIDP)
#define IS_BONUS_GIVING_LEADER (h==REBJEDI || h==REBJMAS)
#define IS_RUNNING_DROID_DEACTIVATION_EXTERNAL (h==IMPCOM || h==IMPSOLAR || h==IMPFUS || h==IMPGEO || h==IMPEGEN || h==REBCOM || h==REBSOLAR || h==REBFUS || h==REBGEO || h==REBEGEN)
#endif// end of #ifndef Unit_Height_List_H
/*
// Delete this grey once it has all been checked. Now all units are in unit_height_list.h. Well, at least the one I need and under TA.
// Height of some units:
#define imp_biker 1409936
#define imp_probe_droid 1415040
#define reb_commando 1585594
#define reb_biker 1686974
#define reb_bothan_spy 1732608
#define reb_heavy_trooper 1732608
#define reb_heavy_rocket_trooper 1732608
#define reb_basic_trooper 1732608
#define reb_missile_trooper 1732608
#define reb_machinegun_deployer 1736704
#define imp_stormtrooper 1784218
#define imp_repeater 1784218
#define imp_flamer 1784218
#define imp_missile trooper 1784218
#define imp_machinegun deployer 1788314
#define imp_battle_droid 1903127
#define imp_captain_droid 1903127
#define reb_wookie 1925120
#define imp_rolling_droid 2027954
#define imp_walker_droid 2130993
#define imp_super_battle_droid 2214698
#define imp_com 1369758
#define reb_com 1960334
#define imp_solar 1277952
#define reb_geo 1638400
#define imp_fusion 2054554 // I changed the 3do because 1966080 was the same as reb_repulsor_plant and imp_veh_plant and imp_moho_mex
#define imp_mega_fusion 2054554 // I changed the 3do because 1966080 was the same as reb_repulsor_plant and imp_veh_plant and imp_moho_mex
#define reb_solar 2064384
#define reb_mega_fusion 2219870
#define reb_fusion 2265745
#define imp_geo 2739405 // I changed the 3do because 2621440 was the same as reb_energy_storage
#define imp_droid_plant 5500218
// 1966080 was both reb_repulsor_plant and imp_mega_fusion and imp_fusion and imp_veh_plant and imp_moho_mexx
// 2621440 was both imp_geo and reb_energy_storage
*/
/*
// List of Height of grabbed units:
// 1409936 // imp biker
// 1415040 // imp probe droid
// 1585594 // reb commando
// 1686974 // reb biker
// 1732608 // reb bothan spy
// 1732608 // reb heavy trooper
// 1732608 // reb heavy rocket trooper
// 1732608 // reb basic trooper
// 1732608 // reb missile trooper
// 1736704 // reb machinegun deployer
// 1784218 // imp stormtrooper
// 1784218 // imp repeater
// 1784218 // imp flamer
// 1784218 // imp missile trooper
// 1788314 // imp machinegun deployer
// 1903127 // imp battle droid
// 1903127 // imp battle captain
// 1925120 // reb wookie
// 2214698 // imp super battle droid
// 2027954 // imp rolling droid
*/
/*
#define height_of_knight 1774747 //height to identify units giving bonus. jedi knight here
#define height_of_master 1760002 //height of jedi master
*/
Hope that helps.