Advertisement
Guest User

onStart

a guest
Oct 13th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. function onStart()
  2.     PrepDialog(200.0, 200.0)
  3.     ReceiveDialog(user) --as there is no current turn before turn execution start, must choose a user to receive dialog
  4.     PrepText('{Localization InterfaceStrings HelloWorld}', 'Notice')
  5.     PrepText('{Localization InterfaceStrings HelloWorld2}', 'Notice2')
  6.    
  7.     PrepText('{Localization InterfaceStrings PlusRed}', 'PlusRed')
  8.     AddFuncPrevText('PlusRed', true, true) --1st arg is funcname
  9.     --2nd arg is if whole text is pressable, 3rd arg true for lclick, false for rclick
  10.     --2nd and 3rd args are true by default and can be skipped
  11.     BindIgnorePrevTextFunc() --pressing on PlusRed func will not close the dialog anymore
  12.     PrepText('{Localization InterfaceStrings MinusRed}', 'MinusRed')
  13.     AddFuncPrevText('MinusRed')
  14.     BindIgnorePrevTextFunc()
  15.     PrepText('{Localization InterfaceStrings PlusBlue}', 'PlusBlue')
  16.     AddFuncPrevText('PlusBlue')
  17.     BindIgnorePrevTextFunc()
  18.     PrepText('{Localization InterfaceStrings MinusBlue}', 'MinusBlue')
  19.     AddFuncPrevText('MinusBlue')
  20.     BindIgnorePrevTextFunc()
  21.    
  22.     PrepButton('onStartProper', 50.0, 30.0, 'GenericAccept')
  23.     BindKeyPrevButton(false)
  24.    
  25.     FormFulldialog() --creates VN-like dialog at the bottom of the screen
  26. end
  27.  
  28. function PlusRed()
  29.     PlusUnit('Team1')
  30. end
  31.  
  32. function PlusBlue()
  33.     PlusUnit('Team0')
  34. end
  35.  
  36. function PlusUnit(teamName)
  37.     local ghosts = GetUnitGhosts()
  38.     if ghosts[1] != nil then --if there are ghost units - despawned units
  39.         local hexes = GetFreeHexes("SpawnPoint " .. teamName) --finding all free hexes of team's spawn point
  40.         if hexes[1] == nil then
  41.             hexes = GetFreeHexes() --if no free hexes, spawn in the world randomly
  42.         end
  43.        
  44.         local randUp = 0
  45.         for i in ipairs(hexes) do
  46.             randUp = i
  47.         end
  48.        
  49.         MoveUnit(hexes[RandomInt(randUp) + 1], ghosts[1]) --ghost unit must be "placed" in valid hex beforehand
  50.         --adjusting random by +1 because lua starts arrays from 1
  51.         ChangeUnitTeam(teamName, ghosts[1]) --assigning new team
  52.         EmbodyGhUnit(ghosts[1]) --giving new body to a ghost unit
  53.         ForceFloat('init', RandomFloat(9.0, 12,0), ghosts[1])
  54.     else
  55.         SpawnUnit('UnitBaseStats', 'BaseClass', teamName)
  56.         ForceFloat('init', RandomFloat(9.0, 12,0))
  57.     end
  58. end
  59.  
  60. function MinusRed()
  61.     MinusUnit('Team1')
  62. end
  63.  
  64. function MinusBlue()
  65.     MinusUnit('Team0')
  66. end
  67.  
  68. function MinusUnit(teamName)
  69.     local units = GetUnits(teamName)
  70.     if (units[1] != nil) then
  71.         DestroyObject(units[1])
  72.     end
  73. end
  74.  
  75. function onStartProper()
  76.     Start()
  77.     --game will start processing turns when onStart()'s thread ends
  78.     --can be used to give player some map-specific options, show some dialogs, story, etc.
  79.     --scripts that use turn execution-reliant commands will be ignored
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement