Jump to content

Scripting help needed, problems with task (ground unit route assignment)


gromit190

Recommended Posts

Hi,

 

I am trying to understand how to assign a task (route of waypoints) to a group. I want this to be a "vanilla" script (no script tools/mods).

 

In my attempt, I am simply trying to make the unit go from its current position to a point 200 units away. But the unit does not move.

 

Can someone please point at what I did wrong here?

 

local function foobar()
  env.info("WAYPOINT TEST")
  local group1 = Group.getByName("Group1")
  local group1Pos = group1:getUnit(1):getPosition().p
  local waypoints = {}
  waypoints[1] = {
    x = group1Pos.x+200,
    y = group1Pos.z,
    speed = 20,
    action = "Cone"
  }
  local task = {
    id = "Mission",
    params = {
      route = {
        points = waypoints
      }
    }
  }
  group1:getController():setTask(task)
end
foobar()

 

I am checking the logs, and I see that the info message "WAYPOINT TEST" is written.

 

Furthermore, I am certain that the group is found and that the position data is really retrieved because I tried printing them to log too. I see that the data exists (is not nil).

 

So I am not sure why this doesn't work.

Link to comment
Share on other sites

It seems like the problem was that the function was called too soon (immidiately) after mission start.

 

This is a working script:

 

local waypoints = {}
local function addWaypoint(x, y)
  waypoints[#waypoints + 1] = {
    x = x,
    y = y,
    speed = 20,
    action = "Cone"
  }
end

local function foobar()
  env.info("WAYPOINT TEST")
  local group1 = Group.getByName("Group1")
  local group1Pos = group1:getUnit(1):getPosition().p
  addWaypoint(group1Pos.x, group1Pos.z)
  addWaypoint(group1Pos.x + 2500, group1Pos.z)
  addWaypoint(group1Pos.x + 2500, group1Pos.z + 2500)
  addWaypoint(group1Pos.x, group1Pos.z + 2500)
  addWaypoint(group1Pos.x, group1Pos.z)
  local task = {
    id = "Mission",
    params = {
      route = {
        points = waypoints
      }
    }
  }
  log(group1:getController())
  group1:getController():setTask(task)
end
timer.scheduleFunction(foobar,nil,5)

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...