Selection_FilerInclude / Selection_FilterExclude

Does anyone know the possible values for the third argument of the Selection_FilerInclude / Selection_FilterExclude functions?

In tai_defensefighter.lua it is:

Selection_FilterExclude("IncomingMissiles", "AllMissiles", "PlayerOwner", ""..playerID, "")
Selection_FilterInclude("IncomingMissiles", "IncomingMissiles", "NearPoint", defensePointString, ""..4500)

In kasutil.lua it is:

filter = ATTRIBUTES_VelToMothership + ATTRIBUTES_DontApplyFriction
Selection_Create("KillerAsteroids")
count = Selection_FilterInclude("KillerAsteroids", "AllAsteroids", "ScriptFlagsSetAll", ""..filter.."", "") 

But are there any other possibilities, and what exactly is the filter doing in the kasutil.lua example?

@pdeupree @EatThePath @shadowwinterknig

EDIT: found this in specialflags.lua:

-- Special flags.  These are stored in the m_scriptingFlags member of Sob.
-- They are mostly queried/manipulated on a per-squad level.
ATTRIBUTES_VelToMothership         = 2 ^ 2  --0x0004
ATTRIBUTES_DontApplyFriction       = 2 ^ 3  --0x0008
	SobGroup_FilterInclude(<sSobGroupNameOut>, <sSobGroupNameIn>, <sFilterTypeString>,     <sFilterParam>)
	FilterType              FilterParam
	========================================
	"Ability"
	                        "SalCapCommand"
	                        "RepairCommand"
	                        "CustomCommand"
	                        "MoveCommand"
	                        "CloakAbility"
	                        "CanDock"
	                        "HyperSpaceCommand"
	                        "ParadeCommand"
	                        "CanBuildShips"
	                        
	"CurrentCommand"        
	                        "COMMAND_Attack"
	                        "COMMAND_SalCap"
	                        "COMMAND_Hyperspace"
	                        "COMMAND_Dock"
	                        "COMMAND_Launch"
	                        
	"CurrentCommandState"
	                        "SALCAPSTATE_ReturningToBaseWithTech"
	                        "LAUNCHSTATE_Queue"
	                        
	"NoFilter"
	                        ""

	"attackFamily"
	                        (attackFamily)
	                        
	"displayFamily"
	                        (displayFamily)
	                        
	"ShipType"              
	                        (ShipType)
	                        
	"PlayerOwner"
	                        (""..iPlayerIndex)
	                        
	"Docked"
	                        ""

Above is all the possible values that I found which have been used in Gearbox’s scripts.
Texts extracted from Homworldrm.exe indicates that the values below may also be used as <sFilterTypeString>, but I haven’t tested them myself so they might work or not:

ShipClass
AutoformationFamily
UnitCapsFamily
ScriptFlagsSetAll
ScriptFlagsSetAny
Health
Awake
ScriptFlagsUnset
NearPoint
SquadronList

Thanks, but I’m trying to use selections, not sob groups. I want to select all asteroids of a certain type, or by location…

Oh sorry, I misread your post and thought you were asking about sobgroup. Anyway it seems that selections work very similar to sobgroups, so you may still try those filters and see if it will work.
And as for asteroids, I can confirm that “NearPoint” filter works, so you can use it to select asteroids by their location.

And below is a demo code to make a RU tractor I wrote some time ago:

Ben_RuCarrier_Speed = 150
salvagerNum = 0
detection_radius = "200"

function Start_Ben_RuCarrier(CustomGroup, playerIndex, shipID)
	local salvagerGroup = CustomGroup..shipID.."salvager"
	SobGroup_CreateIfNotExist(salvagerGroup)
	SobGroup_Clear(salvagerGroup)  
	SobGroup_FillShipsByType(salvagerGroup, "Player_Ships"..playerIndex, "ben_salvager")
	salvagerNum = SobGroup_Count(salvagerGroup)
	for i = 0, salvagerNum - 1 do
		SobGroup_CreateIfNotExist(salvagerGroup..i)
		SobGroup_Clear(salvagerGroup..i)  
		SobGroup_FillShipsByIndexRange(salvagerGroup..i, salvagerGroup, i, 1)		
	end
	
	Volume_AddSphere(salvagerGroup.."VCar", SobGroup_GetPosition(CustomGroup), 0)
end

function Do_Ben_RuCarrier(CustomGroup, playerIndex, shipID)
	local salvagerGroup = CustomGroup..shipID.."salvager"
	salvagerEffectsList = salvagerEffectsList or {}

	local carrierPoint = SobGroup_GetPosition(CustomGroup)
	Volume_Delete(salvagerGroup.."VCar")
	Volume_AddSphere(salvagerGroup.."VCar", carrierPoint, 0)
	
	for i = 0, salvagerNum - 1 do
		if salvagerEffectsList[i+1] then
			FX_StopEffect(salvagerEffectsList[i+1])
			salvagerEffectsList[i+1] = nil
			Volume_Delete(salvagerGroup.."VSal"..i)
		end
		if SobGroup_IsDoingAbility(salvagerGroup..i, AB_Harvest) == 1 then
			Selection_Create("tmpAsteroids")
			if Selection_GetResources("tmpAsteroids", "Asteroid") > 0 then
				local salvagerPoint = SobGroup_GetPosition(salvagerGroup..i)
				local salvagerPointString = salvagerPoint[1]..","..salvagerPoint[2]..","..salvagerPoint[3]
				local numberOfNearbyRu = Selection_FilterInclude(
		    	"tmpAsteroids", 
		    	"tmpAsteroids", 
		    	"NearPoint", 
		    	salvagerPointString,
		    	detection_radius
	    	)
	    	if numberOfNearbyRu > 0 then	    		
		    	local heading = 
		    	{
		    		carrierPoint[1] - salvagerPoint[1],
		    		carrierPoint[2] - salvagerPoint[2],
		    		carrierPoint[3] - salvagerPoint[3],
		    	}
		    	local headingLen = sqrt(heading[1]^2 + heading[2]^2 + heading[3]^2)
		    	heading = 
		    	{
		    		heading[1] * Ben_RuCarrier_Speed / headingLen,
		    		heading[2] * Ben_RuCarrier_Speed / headingLen,
		    		heading[3] * Ben_RuCarrier_Speed / headingLen,
		    	}
		    	Selection_SetVelocity("tmpAsteroids", heading)
		    	
		    	Volume_AddSphere(salvagerGroup.."VSal"..i, salvagerPoint, 0)
		    	salvagerEffectsList[i+1] = FX_PlayEffectBetweenPoints("pro_tech_beam_combo", salvagerGroup.."VCar", salvagerGroup.."VSal"..i, 0.5)
	    	else
	    		_ALERT("No Nearby Asteroid: "..i)
	    	end
			else
				_ALERT("No Asteroid: "..i)
			end
		end
	end
end

function Finish_Ben_RuCarrier(CustomGroup, playerIndex, shipID)	
	local salvagerGroup = CustomGroup..shipID.."salvager"
	Volume_Delete(salvagerGroup.."VCar")
	for i = 0, salvagerNum - 1 do
		if salvagerEffectsList[i+1] then
			FX_StopEffect(salvagerEffectsList[i+1])
			salvagerEffectsList[i+1] = nil
			Volume_Delete(salvagerGroup.."VSal"..i)
		end
	end
end
5 Likes

Wow that’s awesome! Thanks for sharing that. I had wondered if something like that might be possible…

@506933395 please could you share the code associated with the UI button in that example? I never worked how to link custom code to a new button before…

In Ben_RuCarrier.ship:

addAbility(NewShipType,"CustomCommand",1,"Missile",1,0,600, 0, 1, 20,100,"data:ship/Ben_RuCarrier/Ben_RuCarrier.lua","Start_Ben_RuCarrier","Do_Ben_RuCarrier","Finish_Ben_RuCarrier","Ben_RuCarrier",0.2,1,1,0)

The format is:

addAbility(NewShipType,"CustomCommand",<bIsActive>,<sName>,<numUnknown1>,<numUnknown2>,<fCapacity>,<fEnergyCutoff>,<fEnergyCost>,<fEnergyRegen>,<fEnergyMinimum>,<sCustomCodePath>,<sFunctionStart>,<sFunctionDo>,<sFunctionFinish>,<sCustomGroup>,<fRefreshTime>,<iCmdIndex>,<?bLatent?bExplode?>)

Arguments

<bIsActive>: is the ability active by default? (0 = inactive, 1 = active)
<sName>: Seems like the name of the custom ability?
<numUnknown1>: Unknown, usually is 1.
<numUnknown2>: Unknown, usually is 0.
<fCapacity>: Total energy.
<fEnergyCutoff>: if the remaining energy is this much or lower, player can stop the ability manually.
<fEnergyCost>: Energy cost per 0.1 seconds
<fEnergyRegen>: amount of energy recharged per 0.1 seconds.
<fEnergyMinimum>: minimum amount of energy required to activate the ability.
<sCustomCodePath>: path to the script file.
<sFunctionStart>: name of the "start" function.
<sFunctionDo>: name of the "do" function.
<sFunctionFinish>: name of the "finish" function
<sCustomGroup>: the name of a Sobgroup which will contain the ship.
<fRefreshTime>: The "do" function will be excuted every <fRefreshTime> seconds.
<iCmdIndex>: The ability icon(defined in ui\newui\taskbar\tb_commandpanel.lua)
<bLatent>: custom command flag to make it run as latent - If true, this custom command can run while another command is active (used to allow commands to keep running while you move ships, attack, etc).
<bExplode>: custom command flag to destroy ship when depleted - When usage energy runs out, ship will explode.

Note: it is unknown if the last parameter is <bLatent> or <bExplode>, in fact, if we look at Gearbox’s code:

addAbility(NewShipType,"CustomCommand",1,"Drones",1,0,1000,200,0.35,2.8,0,"data:Ship/Kus_DroneFrigate/Kus_DroneFrigate.lua","Start_DroneFrigate","Do_DroneFrigate","Finish_DroneFrigate","Kus_DroneFrigate",1.15,2,1)
addAbility(NewShipType,"CustomCommand",1,"$3191",1,0,300,1,0.65,0.0,300,"data:Ship/Kus_GravWellGenerator/Kus_GravWellGenerator.lua","Start_Kus_GravWellGenerator","Do_Kus_GravWellGenerator","Finish_Kus_GravWellGenerator","Kus_GravWellGenerator",1.9,1,1,1,1)

You will see that sometimes they use a single “1” after <iCmdIndex>, while sometimes they use 3 "1"s.

3 Likes

Thanks, that’s really helpful! :rocket:

Did you manage to define a custom command icon that worked? I tried adding index commandID = INFO_CustomStart + 4 to commanduidefines.lua and added my button to tb_commandpanel.lua - my new icon shows up but when I click on it nothing happens…


EDIT: I discovered that you can use “0” without having to modify commanduidefines.lua and tb_commandpanel.lua. It is an unused index that works (perhaps it was put there for modders…)

How did you write in commanduidefines.lua and tb_commandpanel.lua?

I tried putting this in commanduidefines.lua:

    {
        commandID = INFO_CustomStart + 4,
        activateButtonName = "btnAsteroidActivate",
        rightClickDisplayName = "Asteroid Mover...",
    },

and this in tb_commandpanel.lua:

BTN_CMD_ASTMOVE			= GetCommandButton(	"btnAsteroidActivate",	"Asteroid Mover!!!", 168,	"DATA:UI\\NewUI\\Taskbar\\CommandIcons\\cmd_ico_dronefrigate.dds",		"MainUI_UserEventData( eCustomActivate, 1 );" , "MainUI_UserEventData( eCustomDeActivate, 1 );")

and this in newtaskbar.lua:

BTN_CMD_ASTMOVE,

But it didn’t work (as I said above, it shows the button but nothing happens on click)…

Change it to “MainUI_UserEventData( eCustomActivate, 4 )” because that’s the ID you gave to it.
Also, the ID in AddCustomAbility should also be 4.

1 Like

Thanks! That did it. So, to summarise, to add a new custom command button with id=4, you need to:

  1. In your .ship file <iCmdIndex> = 4
addAbility(NewShipType,"CustomCommand",<bIsActive>,<sName>,<numUnknown1>,<numUnknown2>,<fCapacity>,<fEnergyCutoff>,<fEnergyCost>,<fEnergyRegen>,<fEnergyMinimum>,<sCustomCodePath>,<sFunctionStart>,<sFunctionDo>,<sFunctionFinish>,<sCustomGroup>,<fRefreshTime>,<iCmdIndex>,<?bLatent?bExplode?>)
  1. In commanduidefines.lua add this:
    {
        commandID = INFO_CustomStart + 4,
        activateButtonName = "btnNameOfYourButton",
        rightClickDisplayName = "this text is not used",
    },
  1. In tb_commandpanel.lua add this line at the bottom:
BTN_CMD_YOURBUTTON			= GetCommandButton(	"btnNameOfYourButton",	"MouseOver Text (or local string)", 168,	"DATA:UI\\NewUI\\Taskbar\\CommandIcons\\cmd_ico_dronefrigate.dds",		"MainUI_UserEventData( eCustomActivate, 4 );" , "MainUI_UserEventData( eCustomDeActivate, 4 );")

NB: you can replace cmd_ico_dronefrigate.dds with your icon image file and 168 with your own hotkey index (but you cannot add new key combinations to keybindings.lua :frowning:

  1. In newtaskbar.lua add this somewhere near line 1170:
BTN_CMD_YOURBUTTON,