MegaGlest Forum

Modding and game content creation => Maps, tilesets and scenarios => Topic started by: ElimiNator on 13 May 2009, 05:46:43

Title: Help me script my scenario
Post by: ElimiNator on 13 May 2009, 05:46:43
I made a scenario, and 3 units attack you when you destroy them 4 more come if you survive that then you win, But it they destroy your main unit (Like a castle) you lose. And it wont work? Help!

Here is the scenario script

---------------------------------------------------

<?xml version="1.0" standalone="yes" ?>
<scenario>
   <difficulty value="3"/>
   <players>
      <player control="human" faction="pirates" team="1"/>
      <player control="cpu" faction="pirates" team="1"/>
      <player control="cpu" faction="pirates" team="2"/>
      <player control="closed"/>      
   </players>
   <map value="The_sea2"/>
   <tileset value="sea"/>
   <tech-tree value="magitech"/>
   <default-resources value="false"/>
   <default-units value="false"/>
   <default-victory-conditions value="false"/>
   <scripts>
      <startup>
         --disable AI
         disableAi(1)
         disableAi(2)
         disableAi(3)
         
         --allied units
         createUnit('docks', 0, startLocation(2))
         dockUnit= lastCreatedUnit()
         giveResource('gold', 0, 500);
         giveResource('wood', 0, 500);
         giveResource('stone', 0, 500);
         giveResource('food', 0, 50);
         createUnit('worker', 0, startLocation(2))
         createUnit('worker', 0, startLocation(2))
         createUnit('worker', 0, startLocation(2))
         createUnit('captain', 1, startLocation(2))
         summonerUnit= lastCreatedUnit()
         <!--setCameraPosition(unitPosition(summonerUnit))-->
         <!--givePositionCommand(summonerUnit, 'attack', startLocation(1))-->
         
         --player units
         for i=1, 1 do
            createUnit('pirate_ship', 0, startLocation(0))
         end

         <!--enemy units village
         createUnit('library', 2, startLocation(1))   
         libraryUnit= lastCreatedUnit()
         createUnit('golem', 2, startLocation(1))-->   
         
         --create enemy attackers
         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
                 ship1Unit= lastCreatedUnit()
            givePositionCommand(ship1Unit(), 'attack', startLocation(2))   
         end   
         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
         end
         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
         end
         
         --objectives
         objective='ObjectiveBoat'
         showMessage('start', 'captain')
         setDisplayText('ObjectiveBoat')
         
      </startup>   
      
      <unitDied>
         --check for dock dying
         if lastDeadUnit()==dockUnit then
            clearDisplayText()
            setPlayerAsWinner(3)            
            endGame()
         end
         
         --check for first village destroyed
         if lastDeadUnit()==ship1Unit then

         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
                 ship2Unit= lastCreatedUnit()
            givePositionCommand(ship2Unit(), 'attack', startLocation(2))   
         end

         for i=1, 3 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
         end   

         --check for second village destroyed
         if lastDeadUnit()==ship2Unit then
            clearDisplayText()
            setPlayerAsWinner(0)
            setPlayerAsWinner(1)            
            endGame()
         end
         
      </unitDied>      
   </scripts>      
</scenario>
Title: Re: Help me script my scenario
Post by: Omega on 14 May 2009, 19:55:09
Well, its hard without the files, but here's POSSIBILITIES (just from looking at it quickly, no in depth reading):

-You tried to comment out a line withg <!-- --> This is HTML/XML only, and lau comments with --. That's all you need, and may be the problem. Not sure how lau likes seeing <! (the rest will end up commented out though).
-The map name may be wrong
-Ditto for the tileset, though this is most likely NOT the problem
-You disabled ai number 3 (player 4), who does not exist.
-Its possible you forgot to make the .lng file or didn't name it right
-possible case problems (map, scenario name, not in folder, folder titled wrong, lng titled wrong, etc;)
-You tried to set player 3 (this is actually 4 in normal terms) as the winner, player 3 does not exist.
-A unit may not exist.

Not sure though, since I don't have time to look more carefully, and don't know the files you are using.

Do you get an error message??? What does it say? Are you using glest 3.2.x?
Title: Re: Help me script my scenario
Post by: ElimiNator on 14 May 2009, 20:11:23
Yes I am using glest 3.2.x

It is the right map and tileset.

Here is the error, Couldn't process event: Error loading lua code: Syntax error: [string "unitDied"]:32: 'end' expected (to close 'function' at line 1) near '<eof>'
Segmentation fault

and here is the script again with the stuff you said fixed.
-----------------------------------------------
<?xml version="1.0" standalone="yes" ?>
<scenario>
   <difficulty value="3"/>
   <players>
      <player control="human" faction="pirates" team="1"/>
      <player control="cpu" faction="pirates" team="1"/>
      <player control="cpu" faction="pirates" team="2"/>
      <player control="closed"/>     
   </players>
   <map value="The_sea2"/>
   <tileset value="sea"/>
   <tech-tree value="magitech"/>
   <default-resources value="false"/>
   <default-units value="false"/>
   <default-victory-conditions value="false"/>
   <scripts>
      <startup>
         --disable AI
         disableAi(1)
         disableAi(2)
         
         --allied units
         createUnit('docks', 0, startLocation(2))
         dockUnit= lastCreatedUnit()
         giveResource('gold', 0, 500);
         giveResource('wood', 0, 500);
         giveResource('stone', 0, 500);
         giveResource('food', 0, 50);
         createUnit('worker', 0, startLocation(2))
         createUnit('worker', 0, startLocation(2))
         createUnit('worker', 0, startLocation(2))
         createUnit('captain', 1, startLocation(2))
         
         --player units
         for i=1, 1 do
            createUnit('pirate_ship', 0, startLocation(0))
         end 
         
         --create enemy attackers
         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
                 ship1Unit= lastCreatedUnit()
            givePositionCommand(ship1Unit(), 'attack', startLocation(2))   
         end   
         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
         end
         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
         end
         
         --objectives
         objective='ObjectiveBoat'
         showMessage('start', 'captain')
         setDisplayText('ObjectiveBoat')
         
      </startup>   
     
      <unitDied>
         --check for dock dying
         if lastDeadUnit()==dockUnit then
            clearDisplayText()
            setPlayerAsWinner(3)           
            endGame()
         end
         
         --check for first village destroyed
         if lastDeadUnit()==ship1Unit then

         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
                 ship2Unit= lastCreatedUnit()
            givePositionCommand(ship2Unit(), 'attack', startLocation(2))   
         end

         for i=1, 3 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
         end   

         --check for second village destroyed
         if lastDeadUnit()==ship2Unit then
            clearDisplayText()
            setPlayerAsWinner(0)
            setPlayerAsWinner(1)           
            endGame()
         end
         
      </unitDied>     
   </scripts>     
</scenario>
Title: Re: Help me script my scenario
Post by: hailstone on 14 May 2009, 23:29:29
I'm not an expert on Lua but from what I can see you aren't 'end'ing
Code: [Select]
--check for first village destroyed
         if lastDeadUnit()==ship1Unit then
Title: Re: Help me script my scenario
Post by: Omega on 15 May 2009, 19:36:16
Yes, the whole if statement is blank!

The message tells you exactly where to look (in the unit died section).

Code: [Select]
if lastDeadUnit()==ship1Unit then
   <perform script here>
end
Title: Re: Help me script my scenario
Post by: hailstone on 16 May 2009, 00:53:31
To be picky it's not really blank it just doesn't end, whether the intention was to encapsulate the rest of the script or not. Hence the error " 'end' expected ".
Title: Re: Help me script my scenario
Post by: ElimiNator on 16 May 2009, 04:30:54
         --check for first village destroyed
         if lastDeadUnit()==ship1Unit then

         for i=1, 1 do
            createUnit('cargo_ship', 2, startLocation(1))
                 ship2Unit= lastCreatedUnit()
            givePositionCommand(ship2Unit(), 'attack', startLocation(2))   
            end

         for i=1, 3 do
            createUnit('cargo_ship', 2, startLocation(1))
            givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
            end

It ends
Title: Re: Help me script my scenario
Post by: hailstone on 16 May 2009, 09:28:17
each control block needs its own end, therefore it would be something like.

Code: [Select]
         --check for first village destroyed
         if lastDeadUnit()==ship1Unit then
             for i=1, 1 do
                 createUnit('cargo_ship', 2, startLocation(1))
                 ship2Unit= lastCreatedUnit()
                 givePositionCommand(ship2Unit(), 'attack', startLocation(2))   
            end

            for i=1, 3 do
                createUnit('cargo_ship', 2, startLocation(1))
                givePositionCommand(lastCreatedUnit(), 'attack', startLocation(2))   
            end
        end
Title: Re: Help me script my scenario
Post by: ElimiNator on 20 May 2009, 21:48:01
Ok thanks  :)