- Posts: 5363
- Thank you received: 0
require("PGStateMachine")
require("PGStoryMode")
--=================== Definitions ===================
function Definitions()
Define_State("State_Init", State_Init)
-- This is the Radius for triggering
Trigger_Radius = 320
end
--=================== State_Init ===================
function State_Init(message)
if message == OnEnter then
-- Registering Proximity Event: The Object calls the Function_Name as soon the "Trigger_Radius" was reached
Object.Event_Object_In_Range(Function_Name, Trigger_Radius)
end
end
--=================================== Threads ===================================
function Function_Name(Object, Nearby_Unit)
if Nearby_Unit.Get_Owner().Is_Human() then
-- do something:
Object.Highlight(true)
-- This will terminate the event so it wont trigger more then 1x
Object.Cancel_Event_Object_In_Range(Function_Name)
end
end
--================================= End of File =================================
if TestValid(Unit)
-- And it is none of the Units in the Exclusion List table
and Unit.Get_Type() ~= Find_Object_Type(Exclusion_List[1])
and Unit.Get_Type() ~= Find_Object_Type(Exclusion_List[2])
and Unit.Get_Type() ~= Find_Object_Type(Exclusion_List[3])
and Unit.Get_Type() ~= Find_Object_Type(Exclusion_List[4])
and Unit.Get_Type() ~= Find_Object_Type(Exclusion_List[5]) then
-- CAUTION: Any mistyping, nonexistent xml Names or forgotten , commas in this table will crash the script !!!
Excluded_Units = {"Unit_1", "Unit_2", "Unit_3", "Unit_4", "Unit_5"}
Stolen_Unit = false
Stolen_Unit = -- (set any unit you like to this variable of interest)
local Exclusions = {}
-- For all units in the Excluded_Units table
for each,String_Name in pairs(Excluded_Units) do
-- Find all units of this type into another table variable
local Found_Exclusions = Find_All_Objects_Of_Type(String_Name)
-- Again for all units, this time not the strings but the actual units
for each,Unit in pairs(Found_Exclusions) do
-- If exist
if TestValid(Unit) then
-- Then we will insert it into the table "Exclusions"
table.insert(Exclusions, Unit)
end
end
end
-- We're going to count the amount of blacklisted Units.
local Exclusion_Count = table.getn(Exclusions)
-- Making sure this only fires if any blacklisted Objects were found on a map
if Exclusion_Count ~= 0 then
-- Repeat this piece of code until all "Exclusions" were checked
repeat
-- CAUTION: We need to sleep abit to prevent the game from freezing
Sleep (0.2)
-- Then we check whether the highlighted object is blacklisted in the Excluded_Units table
-- Exclusions[Exclusion_Count] means we start at the highest value (count) and go down to 0
if Stolen_Unit.Get_Type() ~= Exclusions[Exclusion_Count].Get_Type() then
-- Then we count down from the unit count
Exclusion_Count = Exclusion_Count - 1
else
-- If our target Object, the Stolen_Unit was matched to any of the Found_Exclusions, we drop it
Stolen_Unit_Is_Valid = false
Exclusion_Count = Exclusion_Count - 1
end
-- We count down until 1 was reached and Found_Exclusions finally reaches 0
until Exclusion_Count == 0
end
-- Needed the additonal variable Stolen_Unit_Is_Valid because directly changing Stolen_Unit above crashes the script.
if Stolen_Unit_Is_Valid == false then
-- Deleting Stolen unit because it is not a valid target
Stolen_Unit = false
-- Resetting variable for next usage
Stolen_Unit_Is_Valid = true
else
-- As soon the unit got destroyed, trigger the function, wont work with tables, use getn instead.
Register_Death_Event(Stolen_Unit, Destroy_Docked_Units)
end
Target_Object = Find_First_Object("Unit_Name")
-- Defining the positions of Markers objects ( Example hint names 01 and 02 were added to my map using the map editor):
Marker_01 = Find_Hint("ATTACKER ENTRY POSITION", "01")
Marker_02 = Find_Hint("DEFENDING FORCES POSITION", "02")
-- Positon of the Camera (Optional, without it the Camera will start at current screen)
Set_Cinematic_Camera_Key(Marker_01, 100, 40, 0, 1, 0, 0, 0)
-- Rotation of the Camera (Optional, without it the Camera will start at current screen)
Set_Cinematic_Target_Key(Marker_02, 0, 0, 0, 0, 0, 1, 0)
-- Controls need to be locked, or any mouse movement will end the camera movement
Lock_Controls(1)
Start_Cinematic_Camera()
-- Transition_Cinematic_Camera_Key(target_position, time, x_distance, y_pitch, z_yaw, euler, pobj, use_object_rotation, cinematic_animation)
-- Rotate the Camera during parameter_2 seconds away from the current position towards parameter_1
Transition_Cinematic_Camera_Key(Object, 4, 1800, 400, 0, 0, 0, 1, 0)
-- You need to sleep for parameter_2 seconds, or the camera deactivates too early using End_Cinematic_Camera() .
Sleep(4)
-- Rotate the Camera during parameter_2 seconds towards parameter_1
Transition_Cinematic_Target_Key(Object, 4, 0, 0, 0, 0, 0, 1, 0)
Sleep(4)
-- Unlocking controls again
End_Cinematic_Camera()
Lock_Controls(0)
Lock_Controls(1)
Start_Cinematic_Camera()
-- These 2 Are optional, but if you use them, dont forget to deactivate them at the bottom!!:
-- Letter_Box_In displays the 2 black bars at the top and the bottom.
Letter_Box_In(2)
-- Disabling AI so Units wont shoot eachother
Suspend_AI(1)
-- With this activated, the camera will follow a Unit or spaceship until it was ended using Transition_Cinematic_Camera_Key()
Scroll_Camera_To(Object)
-- Need to sleep as long the camera is following!
Sleep(8)
-- This is the same code as in the box above:
-- Rotate the Camera during parameter_2 seconds away from the current position towards parameter_1
Transition_Cinematic_Camera_Key(Object, 4, 1800, 400, 0, 0, 0, 1, 0)
Sleep(4)
-- Rotate the Camera during parameter_2 seconds towards parameter_1
Transition_Cinematic_Target_Key(Object, 4, 0, 0, 0, 0, 0, 1, 0)
-- You need to sleep for parameter_2 seconds, or the camera deactivates too early using Transition_To_Tactical_Camera.
Sleep(4)
-- Optional: Scrolls the Camera during parameter_1 back to its original position
Transition_To_Tactical_Camera(4)
-- End_Cinematic_Camera is commented because Transition_To_Tactical_Camera() does this
-- End_Cinematic_Camera()
Lock_Controls(0)
-- These 2 are optional, use only if deactivated above:
Letter_Box_Out(1)
Suspend_AI(0)
Which instantly shows that Object.Point_Camera_At(Object)
Zoom_Camera(0.7, 0)
Planet_01 = Find_First_Object("Planet_Name")
Planet_02 = Find_First_Object("Planet_Name")
Add_Planet_Highlight(Planet_01, "0")
-- It blinks as long as the script sleeps
Sleep (3.0)
Remove_Planet_Highlight("0")
This Function teleports all Ships and Transporters it finds in the orbit of one Planet to a second one. Ok, I have to admit it actually kills the units and resurrects them, but fast enough to not be able noticing it.require("PGStoryMode")
require("PGStateMachine")
--================================= Base Definitions =================================
function Definitions()
Define_State("State_Init", State_Init)
end
--================================= The Mission begins =================================
function State_Init(message)
if message == OnEnter then
Planet_01 = Find_First_Object("Planet_Name")
Planet_02 = Find_First_Object("Planet_Name")
All_Units = Find_All_Objects_Of_Type("Transport | Fighter | Bomber | Corvette | Frigate | Capital")
Orbital_Fleet = {}
-- Removing any non player Units
for each, Unit in pairs(All_Units) do
if TestValid(Unit) and Unit.Get_Owner() == Object.Get_Owner() then
if Unit.Get_Planet_Location() == Planet_02 then
-- All Nearby Units get duplicated to the destination planet then Deleted
SpawnList({Unit.Get_Type().Get_Name()}, Planet_01, Object.Get_Owner(), true, false)
table.insert(Orbital_Fleet, Unit)
end
-- Need to despawn seperately using this list in oder to prevent the script form crashing
for each, Unit in pairs(Orbital_Fleet) do
Unit.Despawn()
end
end
end
-- The player gets some money to see if the script still runs
Object.Get_Owner().Give_Money(1000)
end
end
Keeping Simple wrote: Human_Player = Find_Player("Underworld")
Planet_01 = Find_First_Object("Campaign_Planet_A")
Planet_02 = Find_First_Object("Campaign_Planet_B")
-- First parameter can contain one unit only as well
Spawned_Fleet = SpawnList({"Ancient_Cruiser", "Ancient_Battleship"}, Planet_01, Human_Player, true, false)
Planet_03 = Spawned_Fleet[1].Get_Planet_Location() -- Where ever this fleet currently is, you will love this
Fleet_01 = Assemble_Fleet(Spawned_Fleet)
Sleep(1) -- Optional
BlockOnCommand(Fleet_01.Move_To(Planet_02))
-- You can either move to the current planet, which switches from one of the 3 slots to another
-- BlockOnCommand(Fleet_01.Move_To(Planet_03))
Being Clever wrote: Human_Player = Find_Player("Underworld")
Planet_01 = Find_First_Object("Campaign_Planet_A")
Planet_02 = Find_First_Object("Campaign_Planet_B")
-- Fancy Oneliner:
Assemble_Fleet(SpawnList(All_Units, Planet_01, Human_Player, true, false)).Move_To(Planet_02)
Being a Maniac wrote: Assemble_Fleet(SpawnList(All_Units, Find_First_Object("Campaign_Planet_A"), Find_Player("Underworld"), true, false)).Move_To(Find_First_Object("Campaign_Planet_B"))
You also can leave the part with the planet ownership change away so the fleet of a planet moves 1 slot towards the target planet. (Caution you would need to run Orbital_Fleet.Move_To(Planet_02) for each jump, maybe in a for loop.Planet_01 = Find_First_Object("Campaign_Planet_A")
Planet_02 = Find_First_Object("Campaign_Planet_B")
Orbital_Units = {}
-- Getting all Units, don't use Fighters or they will crash the script after assambling fleet
All_Units = Find_All_Objects_Of_Type("Hero | Infantry | Bomber | Corvette | Frigate | Capital")
for each, Unit in pairs(All_Units) do
-- If is located on the target Planet the 1 or 2 Planets will change faction and we put all units there into a variable
if TestValid(Unit) and Unit ~= Object and Unit.Get_Planet_Location() == Planet_01 then
table.insert(Orbital_Units, Unit)
end
end
Sleep (0.5)
-- Sending all units away from the conquered planet.
Orbital_Fleet = Assemble_Fleet(Orbital_Units)
Orbital_Fleet.Move_To(Planet_02)
-- Careful this line could cause crashes because of Change_Owner
Planet_01.Change_Owner(Object.Get_Owner())
-- The planet will turn neutral unless you instantly spawn or move own units to it.
Planet_01.Change_Owner(Find_Player("Neutral"))
For the code above you additonally will need a function to test whether a planet is contained in the table, paste it to the bottom of your script OUTSIDE of the state above:Planet_Exclusion_List = {"Planet_01", "Planet_02", "Planet_03",
"Planet_04", "Planet_05"}
-- Specifies if we like to conquer all Planets in this GC that are listed in the table above, or if we reverse it to conquer all of the not listed ones.
Reverse_Planet_Selection = false
for each, Planet in pairs(FindPlanet.Get_All_Planets()) do
-- Only excluded planets wont get conquered
if Reverse_Planet_Selection == false and not Is_Object_In_List(Planet_Exclusion_List, Planet) then
-- Conquering Planet to the Owner faction
Planet.Change_Owner(Object.Get_Owner())
-- This causes to conquer only the selected planets, above it conqers all unselected ones
elseif Reverse_Planet_Selection and Is_Object_In_List(Planet_Exclusion_List, Planet) then
Planet.Change_Owner(Object.Get_Owner())
end
-- Little break between each planet conquer so the user can get all conquer messages one by one
Sleep (0.4)
end
-- SGMG Function: Destroy a planet in GC
Death_Star_Fleet_List = SpawnList({"Death_Star"}, Planet, Find_Player("Neutral"), false, false)
Death_Star = Find_First_Object("Death_Star")
Death_Star.Set_Check_Contested_Space(false)
Death_Star.Activate_Ability("Death_Star")
Death_Star.Set_Check_Contested_Space(true)
Death_Star.Despawn()
-- The Planet is useless wasteland now, careful this line could cause crashes because of Change_Owner
Planet.Change_Owner(Find_Player("Neutral"))
-- Waiting abit before we destroy the next one
Sleep (0.6)
- Show_Radar_Blips is meant to be used only for a single ship on the map, actually. Otherwise the blips would overlap eachother.-- Universal Settings
Trigger_Distance = 600
Show_Radar_Blips = false
Debug_Mode = false
Patrol_Relays_Infinitely = false
-- This overwrites Relay_A to pingpong between 2 points if Patrol_Relays_Infinitely is true as well
Patrol_Between_Atk_and_Def_Position = false
-- Costum settings, here each ship can have different values
if Object.Get_Type() == Find_Object_Type(Patrole_Ship[1]) then
Relay_List = Relay_B
-- You can set for each type of ship other universal settings, they may patrol different markers
-- Some types may patrol infinitely while others run once only. Dont use Radar Blips for more then one type per map.
elseif Object.Get_Type() == Find_Object_Type(Patrole_Ship[2]) then
Trigger_Distance = 500
-- Possability to overwrite relay plans = patrol routes
Relay_B = {"MARKER_GENERIC_GREEN"}
Relay_List = Relay_B
Show_Radar_Blips = false
Patrol_Relays_Infinitely = true
end
as universal variable for enemies.Enemy_Player = Object.Get_Owner().Get_Enemy()
Enemy_Units = Find_All_Objects_Of_Type(Find_Player("Empire"))
for each,Unit in pairs(Enemy_Units) do
-- All structures that cant use the command above to flee need to despawn. Because Starbases have Capital Cathegory
if not Unit.Is_Category("Frigate | Corvette | Hero | Transport")
or Unit.Is_Category("Structure") then
Unit.Despawn()
end
end
Sleep(0.4)
for each,Unit in pairs(Enemy_Units) do
-- If its still there
if Unit ~= nil then
-- Remaining Ships fleet
Unit.Hyperspace_Away()
end
end
Name_of_Engine_Hardpoint = "Hardpoint_Name" -- Needs to be a Hardpoint that exists in your mod, otherwise wont work
Damage_Amount = 10000
for each,Unit in pairs(Enemy_Units) do
Unit.Take_Damage(Damage_Amount, Name_of_Engine_Hardpoint)
end