Define Properties() command_state = "enemyTurn" ui_color = {red = 255, green = 255, blue = 255, alpha = 1} -- script information script_description = 'All Player Commands' script_long_description = 'Player Commands and Inputs' end Define Commands() -- MakeCommand(name, description, [arg-name:arg-type, ...]) -- MakeInput(input-description, input-code, input-event, input-modifier, command-string) -- ** MAIN SCREEN COMMANDS ** -- handle click on terrain MakeCommand("handle_terrain", "request move", "x:float", "y:float", "z:float") MakeInput('Click on terrain.', 'mouse-terrain', 'click', 'none', 'handle_terrain') -- handle click on an object MakeCommand("pick", "pick an object", "target:object") MakeInput('pick','mouse-object', 'click', 'none', 'pick') -- test -- various test functions used to test functionality MakeCommand("test", "test") MakeInput('test', 'a', 'down', 'none', 'test') MakeCommand("test2", "test2") MakeInput('test2', 'x', 'down', 'none', 'test2') MakeCommand("test3", "test3", "val:int") MakeCommand("test4", "test4") MakeInput('test4', 'd', 'down', 'none', 'test4') -- ** UNIT PANEL COMMANDS ** -- select unit MakeCommand("selectUnit", "select the specified unit", "val:int") -- end turn MakeCommand("endTurn", "endTurn") -- hold unit MakeCommand("holdUnit", "Orders the selected unit to hold") MakeInput('order unit to hold until next turn', 'h', 'down', 'none', 'holdUnit') -- shift selection to next unit MakeCommand("nextUnit", "Selects the next unit with remaining AP") MakeInput('select next unit with available AP', 'n', 'down', 'none', 'nextUnit') -- display inventory MakeCommand("showUnitInventory", "Displays the unit inventory window", "flag:int") MakeInput('display inventory screen for current unit', 'i', 'down', 'none', 'showUnitInventory 1') -- display status MakeCommand("showUnitStatus", "Displays the unit stats window") MakeInput('display status screen for current unit', 's', 'down', 'none', 'showUnitStatus') -- hand MakeCommand("useInventoryItem", "Activates item from inventory", "location:string", "slot:int") MakeCommand("moveInventory", "Takes an item from inventory", "location:string", "i:int", "j:int") MakeCommand("dismissExternalUI", "Dismiss UI belonging to an object", "containerId:int", "UiID:int") MakeCommand("moveContainer", "move objects to and from container", "containerId:int", "i:int", "j:int") end -- **** COMMANDS **** -- ** MAIN SCREEN COMMANDS ** -- pick -- Click on an object - no SHFT, CTRL, ALT modifiers Command pick(target) local selectedObject = GetObjectById(self.selected_object_id) -- select unit objects on click if (target.owner == self.id) then selectUnit(self, target) end if (selectedObject.inHand ~= 0) then SendTo(target, "useWithObject", 0, user, self.selected_object_id, selectedObject.inHand) else if (target.pickable and target.pickable == 1) then Debug("Pick up object %d", target.pickable) SendTo(selectedObject, "pickupObject", 0, target, "backpack") else Debug("Use world object") SendTo(target, "useObject", 0, user, self.selected_object_id) end end end -- handle_terrain -- Click on the terrain - no SHFT, CTRL, ALT modifiers Command handle_terrain(x, y, z) local selectedObject = GetObjectById(self.selected_object_id) -- if selected object is one of our units, order it to move if (selectedObject.inHand ~= 0) then --Debug("%d %d", x, y) SendTo(selectedObject, "dropObjectInHand", 0, x, y) elseif (selectedObject.owner == self.id) then -- move the player with the unit self.speed = 2 PathToLocation(self, round(x), round(y)) -- request unit to move SendTo(GetObjectById(self.selected_object_id), "requestMove", 0, x, y) end end -- Test -- Reusable commands for testing new script(s) Command test() createPMCMgmt(self) end Command test2() --deployUnits(self) SendTo(GetObjectById(self.selected_object_id), "checkInventory", 0) --createTestPanel(self) -- destroyUI(self) -- UiDelete(self.commandPanel) -- self.commandPanel = 0 end Command test3(val) Debug("Test3") --selectUnit(self, GetObjectById(self.team[val].id)) end Command test4() --pickUpUnits(self) --dismissTestPanel(self) ui_dismissControlPanel(self) --SendTo(GetObjectById(self.selected_object_id), "dropObject", 0, GetObjectById(10130), self.x, self.y + 1, 0, 0) end -- ** TEAM PANEL COMMANDS ** -- selectUnit -- selects a specified unit Command selectUnit(val) selectUnit(self, GetObjectById(val)) end -- endTurn -- ends the user's current turn Command endTurn() self.command_state = "enemyTurn" SendToPlace("endedTurn", 0, self.id) SendTo(self, "startTurn", 0) end -- ** UNIT PANEL COMMANDS ** -- holdUnit -- orders the current unit to hold until the next turn -- effectively it makes the nextUnit command ignore it until the next turn Command holdUnit() AlertToUser(self, 1500, "Hold Unit!") SendTo(GetObjectById(self.team[self.selected_unit_index].id), "hold", 0) end -- nextUnit -- selects the next available unit with AP Command nextUnit() AlertToUser(self, 1500, "Next Unit!") -- local var for unit storage local unit = 0 -- store where we start the search local startIndex = self.selected_unit_index Debug("StartIndex: %d", startIndex) -- increment the index and create a local copy local selectIndex = self.selected_unit_index + 1 if selectIndex > #(self.team) then selectIndex = 1 end -- loop thru the team table until we return to the start index while selectIndex ~= startIndex do --Debug("%d - %d Unit: %d", selectIndex, startIndex, self.team[selectIndex].id) -- if the unit has available AP and is not on hold, select the unit unit = GetObjectById(self.team[selectIndex].id) if (unit.curActionPoints > 0 and unit.state ~= "hold") then selectUnit(self, GetObjectById(self.team[selectIndex].id)) return end selectIndex = selectIndex + 1 -- set the index to start of team table if we reach the end of the table if selectIndex > #(self.team) then --Debug("Out of range") selectIndex = 1 end end -- check the current unit unit = GetObjectById(self.team[startIndex].id) if (unit.actionPoints > 0 and unit.state ~= "hold") then AlertToUser(self, 1500, "Other Units Out of Action Points!") else AlertToUser(self, 1500, "All Units Out of Action Points!") end end -- showUnitInventory -- displays the inventory UI for the selected unit Command showUnitInventory(flag) SendTo(GetObjectById(self.selected_object_id), "showInventory", 0, self, flag) --AlertToUser(self, 1500, "Inventory!") end -- showUnitStatus -- displays the status UI for the selected unit Command showUnitStatus() AlertToUser(self, 1500, "Current Team Size: %d Container Size: %d", #self.team, GetContainerSize(self.locker)) end -- useInventoryItem -- use item from inventory -- Args: -- location - which inventory location is the item in (l_hand, r_hand, belt, or backpack) -- slot - which slot of the inventory location is the item in Command useInventoryItem(location, slot) SendTo(getCurrentUnit(self), "useInventoryItem", 0, self, location, slot) end Command moveInventory(location, i, j) SendTo(GetObjectById(self.selected_object_id), "moveInventory", 0, self, location, i, j) end Command moveContainer(containerId, i, j) Debug("MoveContainer!") unit = GetObjectById(self.selected_object_id) SendTo(GetObjectById(containerId), "moveContainer", 0, self, unit, i, j) end Command dismissExternalUI(containerId, UiID) Debug("Dismiss Object %d Ui %d", containerId, UiID) SendTo(GetObjectById(containerId), "closeUI", 0, self, UiID) end