You must be logged in to post messages.
Please login or register

Modding and Scripting
Moderated by Yeebaagooon, nottud

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: Triggers with Gusto - Using The Knowledge Base
posted 13 March 2003 07:50 AM EDT (US)   
I was playing around with the victory conditions file trying to fix a screw in Spill Blood that allows norse units to repair buildings practically free, and wrote some nice triggers using the knowledge base. Since the VC file is not transferred on a sync, I decided to try to move them into the typetest.xml file. I found that you can put full code blocks right into the trigger xml file.

Here's a trigger I wrote that queries the knowledge base to find any Military Unit (Type 639) for a player that is repairing (Action 13) and converts them to Gaia.

001 <?xml version = "1.0"?>
002 <trigger version="2">
003 <Effects>
004 <Effect name="$$99421$$ConvertBuildersToGaia">
005 <Param name="PlayerID" dispName="$$22301$$Player" VarType="player">1</Param>
006 <Param name="ArmyName" dispName="$$99420$$ArmyName" varType="string">default</Param>
007 <Command>int prevPlayer = xsGetContextPlayer();</Command>
008 <Command>if (trPlayerActive(%PlayerID%)) {</Command>
009 <Command> xsSetContextPlayer(%PlayerID%);</Command>
010 <Command> int aid=kbArmyGetID("%ArmyName%");</Command>
011 <Command> kbArmyRemoveUnits(aid);</Command>
012 <Command> int myQueryID=kbUnitQueryCreate("WhoIsBuilding");</Command>
013 <Command> if (myQueryID >= 0) {</Command>
014 <Command> kbUnitQuerySetPlayerID(myQueryID, %PlayerID%);</Command>
015 <Command> kbUnitQuerySetUnitType(myQueryID, 639);</Command>
016 <Command> kbUnitQuerySetState(myQueryID, 2);</Command>
017 <Command> kbUnitQuerySetActionType(myQueryID, 13);</Command>
018 <Command> kbUnitQueryResetResults(myQueryID);</Command>
019 <Command> int myCnt=kbUnitQueryExecute(myQueryID);</Command>
020 <Command> if (myCnt>0) {</Command>
021 <Command> trChatSend(0, "Player %PlayerID% who is "+ kbGetCivName(kbGetCiv())+ " just lost "+myCnt+" builders...");</Command>
022 <Command> while (myCnt>0) {</Command>
023 <Command> myCnt--;</Command>
024 <Command> int myID=kbUnitQueryGetResult(myQueryID, myCnt);</Command>
025 <Command> kbArmyAddUnit(aid,myID);</Command>
026 <Command> }</Command>
027 <Command> trArmySelect(%PlayerID%+","+aid);</Command>
028 <Command> trUnitConvert(0);</Command>
029 <Command> }</Command>
030 <Command> }</Command>
031 <Command>}</Command>
032 <Command>xsSetContextPlayer(prevPlayer);</Command&g t;
033 </Effect>
034 </Effects>
035 </trigger>

This trigger takes two parameters, Player # & the STRING NAME of an existing Army. Due to variable declarations & the way I have it set up, you can only use this effect once per trigger - this could be coded around. Also, never use the < symbol in your code block. I had to rewrite my for loops as while blocks to get around that (this is why the ES Create Multi triggres don't work! - which could be easily fixed...)

Line 007 - Save whatever player context the game is set at.
Line 008 - Check player is active.
Line 009 - Switches context to the player in question so KB queries correctly.
Line 010 & 011 - Select & clear the army.
Line 012 & 013 - Create new KB query & Check if sucessful
Line 014-017 - Add query parameters for Player, Unit Type, State, Action.
Line 018-020 - Execute the query & check for results.
Line 022-026 - Loop over results & add to army
Line 027-028 - Select & Convert Army.
Line 032 - Return Context back to whatever the game was using when we took over.

That's the short of it. Now go create some awesome triggers.

See it work (play as player 1): http://www.BeerInHand.com/aom/TOS_NoRepairs.scn

To test it out:
Download & put this file in the aom/trigger directory http://www.BeerInHand.com/aom/TOS_TypeTest.xml
Create a 2 player scenario & add a TC for each. Put a Portable Ram for Player 2 next to player 1's TC.
Create an army for player one.
Add a 10 sec timed trigger with the effect ConvertBuildersToGaia for player 1 with the name of the army created.
Play scenario & try to repair the TC as the ram beats on it.

Note: Using an army in this trigger is not necessary, but I did to show that you could.


"Just invite him over for dinner. Turn him from an enemy into a friend. Then when he's least expecting, BAM! The old fork in the eye!" - M.S.
--
Member °ƒ Tsunami Studios <<< Play TOS Maps - 9 Maps - Avg Rating: 4.67! >>>

[This message has been edited by TwentyOneScore (edited 03-13-2003 @ 10:53 AM).]

Replies:
posted 13 March 2003 10:28 AM EDT (US)     1 / 1  
WOW! Im sure that when people start getting creative, we can have some incredible triggers!

  • >> LKS_Cheeselord >>
  • Proud member of LKS. Click here to join.
  • Member of Arcane Studios, DGDN, and LKSware
  • PROJECTS: Magic Rugs - Cheese Giant - Anim Editor
  • Fear the power of CHEESE!
  • Age of Mythology Heaven » Forums » Modding and Scripting » Triggers with Gusto - Using The Knowledge Base
    Top
    You must be logged in to post messages.
    Please login or register
    Hop to:    
    Age of Mythology Heaven | HeavenGames