Pake: Patrolling -right now Point to Point ( Back and Forth
-------------------First : create NPCs who patrol------------------------
--template for patroling NPCs : "mobile name", respawn timer, X, Z, Y, facing, cellid #, "display name", "ID"
guards = {
--Imperial Base
{"pandorum_imperial_st_06", 360, 4294, 6.5, 150, 180, 0, "", "guard1"},
{"pandorum_imperial_st_06", 360, 4294, 6.5, 77, 0, 0, "", "guard2"},
{"pandorum_imperial_st_06", 360, 4920, 6.5, 172, 45, 0, "", "guard3"},
{"pandorum_imperial_st_06", 360, 4298, 6.5, 172, 45, 0, "", "guard4"},
--{"pandorum_imperial_st_06", 360, -45, 28, -4715, 0, 0, "", "guard5"}
},
-- droids
droids = {
{"imperial_sentinel", 360, 4300, 6.5, 0, 0, 0, "", "droid1"},
{"imperial_sentinel", 360, 4370, 6.5, 100, 0, 0, "", "droid2"},
{"imperial_sentinel", 360, 4370, 6.5, 163, 0, 0, "", "droid3"},
---------------------Second : Spawn Mobiles with Patrol Logic -------------------------
function skaradoshimperialbase01ScreenPlay:spawnMobiles()
--spawnMobile((self.planet), "le_repair_droid", 0, -29, 28, -4717, -15, 0)
for i,v in ipairs(self.guards) do
local pMobile = spawnMobile(self.planet, v[1], v[2], v[3], v[4], v[5], v[6], v[7])
if (pMobile ~= nil) then
writeData(SceneObject(pMobile):getObjectID() .. ":currentLoc", 1)
writeStringData(SceneObject(pMobile):getObjectID() .. ":name", v[9])
CreatureObject(pMobile):setCustomObjectName(v[8])
createEvent(getRandomNumber(350,450) * 100, "skaradoshimperialbase01ScreenPlay", "TestPatrol", pMobile, "")
createObserver(DESTINATIONREACHED, "skaradoshimperialbase01ScreenPlay", "testPatrolDestReached", pMobile)
AiAgent(pMobile):setAiTemplate("manualescortwalk")
AiAgent(pMobile):setFollowState(4)
end
end
for i,v in ipairs(self.droids) do
local pMobile = spawnMobile(self.planet, v[1], v[2], v[3], v[4], v[5], v[6], v[7])
if (pMobile ~= nil) then
writeData(SceneObject(pMobile):getObjectID() .. ":currentLoc", 1)
writeStringData(SceneObject(pMobile):getObjectID() .. ":name", v[9])
CreatureObject(pMobile):setCustomObjectName(v[8])
createEvent(getRandomNumber(450,550) * 100, "skaradoshimperialbase01ScreenPlay", "TestPatrol", pMobile, "")
createObserver(DESTINATIONREACHED, "skaradoshimperialbase01ScreenPlay", "testPatrolDestReached", pMobile)
AiAgent(pMobile):setAiTemplate("manualescortwalk")
AiAgent(pMobile):setFollowState(4)
end
end
end
----------------------------Third : Add patrol parameters --------------------------------------------
unction skaradoshimperialbase01ScreenPlay:TestPatrol(pMobile)
if (pMobile == nil) then
return
end
local name = readStringData(SceneObject(pMobile):getObjectID() .. ":name")
local curLoc = readData(SceneObject(pMobile):getObjectID() .. ":currentLoc")
local nextLoc
if (name == "guard1") then
if (curLoc == 1) then
nextLoc = { 4294, 6.5, 150, 0 }
else
nextLoc = { 4294, 6.5, 77, 0 }
end
end
if (name == "guard2") then
if (curLoc == 1) then
nextLoc = { 4294, 6.5, 77, 0 }
else
nextLoc = { 4294, 6.5, 150, 0 }
end
end
if (name == "guard3") then
if (curLoc == 1) then
nextLoc = { 4290, 6.5, 235, 0 }
else
nextLoc = { 4290, 6.5, 172, 0 }
end
end
if (name == "guard4") then
if (curLoc == 1) then
nextLoc = { 4298, 6.5, 235, 0 }
else
nextLoc = { 4298, 6.5, 172, 0 }
end
end
if (name == "droid1") then
if (curLoc == 1) then
nextLoc = { 4150, 6.5, 0, 0 }
else
nextLoc = { 4300, 6.5, 0, 0 }
end
end
if (name == "droid2") then
if (curLoc == 1) then
nextLoc = { 4370, 6.5, 214, 0 }
else
nextLoc = { 4370, 6.5, 100, 0 }
end
end
if (name == "droid3") then
if (curLoc == 1) then
nextLoc = { 4294, 6.5, 214, 0 }
else
nextLoc = { 4370, 6.5, 163, 0 }
end
end
AiAgent(pMobile):stopWaiting()
AiAgent(pMobile):setWait(0)
AiAgent(pMobile):setNextPosition(nextLoc[1], nextLoc[2], nextLoc[3], nextLoc[4])
AiAgent(pMobile):executeBehavior()
end
---------------------------Fourth -determinewhat happens when deistination is reached -----------------------
function skaradoshimperialbase01ScreenPlay:testPatrolDestReached(pMobile)
if (pMobile == nil) then
return 0
end
local curLoc = readData(SceneObject(pMobile):getObjectID() .. ":currentLoc")
if (curLoc == 1) then
writeData(SceneObject(pMobile):getObjectID() .. ":currentLoc", 2)
else
writeData(SceneObject(pMobile):getObjectID() .. ":currentLoc", 1)
end
createEvent(getRandomNumber(350,450) * 100, "skaradoshimperialbase01ScreenPlay", "TestPatrol", pMobile, "")
return 0
end