Spawn and de-spawn hero on tech level / multiplayer g-campaign

Mehr
30 Okt 2015 19:50 #76202 von vlnikolic
Hello everybody!

I would like to ask for help for creating /probably/ lua script.

That script should on upgrade of tech level in multiplayer galactic campaign:

1)
check if hero X is alive

2)
if 1) is true
despawn hero X
and
spawn hero Y

3)
if 1) is false
do nothing

Thank you very much for your interest.
: )

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

  • Locutus
  • Locutuss Avatar
  • Offline
  • Administrator
  • Administrator
  • [SGMG] Project Co-Lead, Lead Coder, 3D-Artist
Mehr
30 Okt 2015 20:09 #76203 von Locutus
Hello,

welcome to the forums!:)
You know the basics of lua, I guess?

What you want to achieve is quite easy.

First, make the event that checks for a tech level upgrade:
<Event Name="Event_vlnikolic_Tech_Level_X">
	<Event_Type>STORY_TECH_LEVEL</Event_Type>
	<Event_Param1>1</Event_Param1>
</Event>

In the lua script, create a state that listens to that event:
StoryModeEvents = {Event_vlnikolic_Tech_Level_X = State_Event_vlnikolic_Tech_Level_X}

The function would then look like this:
function State_Event_vlnikolic_Tech_Level_X(message) 
   if message == OnEnter then
      --1) find hero x
      local heroX = Find_Hero("Hero_X_XML_Name")
   
      -- if he is alive despawn hero X and spawn hero Y
      if TestValid(heroX) then
         heroX.Despawn()
         heroY = Spawn_Unit(Find_Object_Type("Hero_Y_XML_Name"), YOURPLANET, YOURFACTION) 
      end
   
   end
end

But you could also do this completely with XML events if your hero can't respawn using STORY_DEFEAT_HERO, REMOVE_UNIT and SPAWN_HERO.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
30 Okt 2015 20:43 - 30 Okt 2015 20:58 #76208 von vlnikolic
Hello again,

Thank you for your fast reply!

Firstly, I am sorry if I am wrong with my knowledge of this subject, I am trying to do my best.

First, make the event that listens to a tech level upgrade:


I am not sure that events are on in multiplayer g-campaign.

My multiplayer map from CAMPAIGNS_MULTIPLAYER.XML is using Story_Plots_Universal_Triggers_E.xml as only plot file. That file activates STORY_UNIVERSAL_TRIGGERS_E.XML, so events that are in this file should be executed in the game.

One event, for examle, states that on tech level 0, I must have Grand_Moff_Tarkin_Team:
	<Event Name="Empire_AI_Heroes_01">
		<Event_Type>STORY_TRIGGER</Event_Type>
		<Reward_Type>SPAWN_HERO</Reward_Type>
		<Reward_Param1>Grand_Moff_Tarkin_Team</Reward_Param1>
		<Reward_Param2>Naboo</Reward_Param2>
		<Prereq>Universal_Story_Start</Prereq>
	</Event>
... and if I remove Grand_Moff_Tarkin_Team from the map in CAMPAIGNS_MULTIPLAYER.XML, there is no Tarkin in the galaxy.
: )
Letzte Änderung: 30 Okt 2015 20:58 von vlnikolic.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
30 Okt 2015 22:41 #76214 von Imperial
Well then you could write a Object Script, place it in the GameObjects directory and insert its name (without the .lua extention) into the <lua_script> tag of the Starbase for skirmish of the Fraction you wish it for.

As soon it detects that the upgrade was built you use :

Set_Next_State("function State_Event_vlnikolic_Tech_Level_X")
to start the state below:

function State_Event_vlnikolic_Tech_Level_X(message)
-- Because of OnUpdate this state will check once every 0.5 Seconds
if message == OnUpdate then

local heroX = Find_Hero("Hero_X_XML_Name")

if TestValid(heroX) then
heroX.Despawn()

-- We take Object as 2nd parameter so it spawns by the Starbase
heroY = Spawn_Unit(Find_Object_Type("Hero_Y_XML_Name"), Object, YOURFACTION)

end

end
end


By the way nice idea to upgrade Heroes via Starbase.

@Locutus; Hmm I currently have no Idea how to detect the upgrade from inside the lua script, without involving any Storyscript, any ideas?

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
31 Okt 2015 18:52 #76235 von vlnikolic
Hi again

@Locutus
So, there is no way to use XML events in multiplayer g-campaign... I've used the very same story XML file for one galactic singleplayer map (defined in CAMPAIGNS_SINGLEPLAYER.XML), as well as in one multiplayer map (defined in CAMPAIGNS_MULTIPLAYER.XML). Magic happens in singleplayer map, but nothing happens in multiplayer.

@Imperial
Hm, interesting by-pass. I've tried with this - but without success (nothing happend). Maybe I've made a mistake with script, but I'm not sure if that change would be permanent (not only in space-battle, but in galactic map as well)
?

.. it seems that /maybe/ the only way would be using lua in some wise way
: )

thank you
vlad



Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
31 Okt 2015 19:55 #76237 von Imperial
Im not on my PC now, but I think there is a test to detect if the game is in skirmish mode. Otherwise yeah it would be permanent, but it wouldnt do anything if that upgrade is only available in skirmish mode.

Yeah my last post only shows the functuon itself, but we'd still need to figure out how to detect the upgrade.

We could build the upgrade as invisible dummy unit (miscobject) and use "if Testvalid()" to detect that it was built.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

  • Locutus
  • Locutuss Avatar
  • Offline
  • Administrator
  • Administrator
  • [SGMG] Project Co-Lead, Lead Coder, 3D-Artist
Mehr
01 Nov 2015 00:28 #76243 von Locutus

Imperial schrieb: @Locutus; Hmm I currently have no Idea how to detect the upgrade from inside the lua script, without involving any Storyscript, any ideas?

Unfortunately there is no way to detected whether an upgrade has been build by the player. That's why you always need to work with fake units that pose as upgrades because you can use STORY_CONSTRUCT on them.
I believe an object script is the wrong way to go here as the tech level of a star base is not necessarily related to actual tech progress (i.e. I can still have a level 1 star base on a planet even if I've researched tech 5). Also this would never trigger unless the player triggers a tactical space battle and thus not be a solution to auto-resolve matches.

vlnikolic schrieb: So, there is no way to use XML events in multiplayer g-campaign...

What makes you say that?
In every GC file there is a tag, <Is_Multiplayer>, set it to "yes" and you're good to go.
I believe there are a couple of event triggers and rewards that may cause instability issues but other than that you can do everything you can do in a singleplayer GC.

However, you don't even need to worry about that, since Story_Universal_Triggers_E.xml already contains the xml functions you need.
Let's assume you want to trigger your hero spawn when the Empire reaches the second tech level.
In the lua script, simply make sure that you listen to this event, so add "Empire_AI_Heroes_05" in the StoryModeEvents list and change the state accordingly. Then make sure that the lua gets loaded in the plot file (Story_Plots_Universal_Triggers_E.xml) and, voilà, you're done.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
01 Nov 2015 14:20 #76255 von vlnikolic
Hi

I've tried with this - but still without success
:''(

There is <MP_Default_Allow_Random_Events> tag in GAMECONSTANTS.XML file, i've tried with switching this on too, but still nothing.

I am not sure if I am asking too much, but is there a chance that you create a template for us / set of files needed for this miracle
?
0: )

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
01 Nov 2015 20:02 #76268 von Imperial

I am not sure if I am asking too much, but is there a chance that you create a template for us / set of files needed for this miracle
?

So you want it the easy way, a copy/paste solution?
Well you're lucky because I am currently working on a similar script and it isnt many changes away from what you like to achieve.. it still took over 1 hour, there you go:

The script itself is abit advanced, but because it manages everything I think this is still the easieset possible solution. I personally hate this endless file seperation and like the idea of a simple 1 file solution.

Step 1: You need to paste this Code in any registered .xml file:

<!-- === Used to prevent multiple usage of the lua code === -->
<MiscObject Name="Upgrade_Dummy">
<Text_ID/>
<Space_Model_Name>W_LASER_INVISIBLE.ALO</Space_Model_Name>
<Land_Model_Name>W_LASER_INVISIBLE.ALO</Land_Model_Name>
<Scale_Factor>1.0</Scale_Factor>
<Behavior>DUMMY_ORBITAL_STRUCTURE, SPACE_OBSTACLE, IDLE</Behavior>
<SpaceBehavior>ABILITY_COUNTDOWN, UNIT_AI, HUNT</SpaceBehavior>
<Layer_Z_Adjust>0.0</Layer_Z_Adjust>
<Sort_Order_Adjust>-1</Sort_Order_Adjust>
<Remove_Upon_Death>true</Remove_Upon_Death>
<Space_Layer> StaticObject </Space_Layer>
<Target_Stealth_Units>Yes</Target_Stealth_Units>
<Victory_Relevant>no</Victory_Relevant>
<Lua_Script>ObjectScript_Hero_Upgrade</Lua_Script>
</MiscObject>


Step 2:
Please paste

<Lua_Script>ObjectScript_Hero_Upgrade</Lua_Script>

into any .xml instance in UpgradeObjects.xml (you can create an new upgrade). Dont forget to additionally paste the name of this upgrade into the <Tactical_Buildable_Objects_Multiplayer> tag of your MULTIPLAYER version of the Starbase, or it wont be buildable.

Actually, you could paste <Lua_Script>ObjectScript_Hero_Upgrade</Lua_Script> directly into the code of the LV2 Starbases, the upgrade would take effect as soon that starbase upgrades to Level 2. But it would overwrite any lua script that starbase already uses, so you might want to check that unit for oldar lua entries first.

Step 3:
Please copy all content below into a empty .lua file and place it into the /Data/Scripts/GameObjects Directory:
Warnung: Spoiler! [ Zum Anzeigen klicken ]


Now, what this script is going to do is;
It checks what unit executes it. If you inserted its lua tag to more then 1 xml units on the map this doesent matter, only the first one of them will spawn a Upgrade_Dummy (the object we inserted to the .xml before). Exception: It allows only 1 instance of Upgrade_Dummy per fraction, so other players can use it as well.

If this script is executed by the (invisible) Dummy (for test purpose you can turn it visible uncommenting the Highlight line),
then it will run through the State_Init state without doing anything and will continue with State_Inactive, which refreshes OnUpdate and sleeps 10 secs, so it checks the map every 10 secs for the units listed in Valid_Units.

Step 4, the last thing you need to do:
Please insert units into the Valid_Units table. But do it with caution, as any mistyping or non existent .xml instance in this table will instantly crash the script. (you can use the (commented) .give_money line at the bottom to test when the script crashes).

The script works like this:
Valid_Units[1] (the first listed object) will be replaced by Valid_Units[2],
then Valid_Units[3] getts replaced by Valid_Units[4]
Valid_Units[5] getts replaced by Valid_Units[6], and so on... you just need to make sure to have the right units in that table, thats it.

BUUT, please dont use Squadron or HeroCompanys, because these are groups of Objects (containers) and the script would not detect them, instead use the actual SpaceUnits, or UniqueUnits, or Infantry .. what ever of these Squadrons/Teams so the script can detect them on the map and replace them.

In my script example I used SG1 to be upgraded by the Daedalus as soon the Upgrade was built.
If the upgrade was built before this unit enters the map the script will keep running and check until these units spawned, then it will auto upgrade them.

Sorry if I over explained, I thik its better to explain too much then leaving open questions. Its actually simply following the 4 steps, thats it.
I can imagine this script, now that it works can be used for The Pegasus Chronicles as well ^^

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
02 Nov 2015 01:24 #76286 von vlnikolic
Hi

Thank you very much for your time and knowledge
:)

This actually works, however there is a major issue: my hero is dead after combat. I had the same issue with tactical_retreat script (that allows single space unit to retreat - despawn - from space combat).

With this script:
- my old hero (old Vader's Tie_A / squadron .. although in script is tie_advanced) was not despawned
- my new hero (Boba Fett / Slave I - just to try) does not exist after the space combat (in galaxy view)

Have you tried this script with heroes in multiplayer gc?
(maybe I am doing something wrong .. yet again)

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Ladezeit der Seite: 2.546 Sekunden