HighwaymanAmbush.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. --[[
  2. Script Name : SpawnScripts/Antonica/HighwaymanAmbush.lua
  3. Script Author : Dorbin
  4. Script Date : 2023.05.02 03:05:41
  5. Script Purpose : Handles 3 spawning highwaymen groups in Antonica that Ambush Players
  6. Proximity Trigger ->
  7. Randomizes race/models and changes 3 exsisting groups of 4 into attackable agro spawns ->
  8. Timer starts for despawn ->
  9. Despawn is triggered if groups are not in combat ->
  10. Spawn cast Stealth and despawn shortly after.
  11. [Respawn of Trigger and Invisisble groups allows for re-trigger]
  12. :
  13. --]]
  14. function spawn(NPC)
  15. SetPlayerProximityFunction(NPC, 12, "InRange", "LeaveRange")
  16. local zone = GetZone(NPC)
  17. if GetSpawnByLocationID(zone, 133784732) == nil and GetSpawnLocationID(NPC)== 133784683 then
  18. SpawnByLocationID(zone,133784732)
  19. end
  20. end
  21. function InRange(NPC, Spawn) --PROXIMITY TRIGGER
  22. local zone = GetZone(NPC)
  23. local Group1HWmanA = GetSpawnByLocationID(zone, 133784689)
  24. local Group1HWmanB = GetSpawnByLocationID(zone, 133784686)
  25. local Group1HWmanC = GetSpawnByLocationID(zone, 133784687)
  26. local Group1HWmanD = GetSpawnByLocationID(zone, 133784688)
  27. local Group2HWmanA = GetSpawnByLocationID(zone, 133784693)
  28. local Group2HWmanB = GetSpawnByLocationID(zone, 133784690)
  29. local Group2HWmanC = GetSpawnByLocationID(zone, 133784691)
  30. local Group2HWmanD = GetSpawnByLocationID(zone, 133784692)
  31. local Group3HWmanA = GetSpawnByLocationID(zone, 133784697)
  32. local Group3HWmanB = GetSpawnByLocationID(zone, 133784694)
  33. local Group3HWmanC = GetSpawnByLocationID(zone, 133784695)
  34. local Group3HWmanD = GetSpawnByLocationID(zone, 133784696)
  35. if GetSpawnByLocationID(zone, 133784732) ~= nil and
  36. Group1HWmanA ~=nil and
  37. Group1HWmanB ~=nil and
  38. Group1HWmanC ~=nil and
  39. Group1HWmanD ~=nil and
  40. Group2HWmanA ~=nil and
  41. Group2HWmanB ~=nil and
  42. Group2HWmanC ~=nil and
  43. Group2HWmanD ~=nil and
  44. Group3HWmanA ~=nil and
  45. Group3HWmanB ~=nil and
  46. Group3HWmanC ~=nil and
  47. Group3HWmanD ~=nil
  48. then
  49. Despawn(GetSpawnByLocationID(zone, 133784732))
  50. if IsPlayer(Spawn)== true and IsAlive(Group1HWmanA) == true and IsAlive(Group1HWmanB) == true and IsAlive(Group1HWmanC) == true and IsAlive(Group1HWmanD) == true then
  51. AddTimer(NPC,2000,"Group1Pop",1, Spawn)
  52. end
  53. if IsPlayer(Spawn)== true and IsAlive(Group2HWmanA) == true and IsAlive(Group2HWmanB) == true and IsAlive(Group2HWmanC) == true and IsAlive(Group2HWmanD) == true then
  54. AddTimer(NPC,2000,"Group2Pop",1, Spawn)
  55. end
  56. if IsPlayer(Spawn)== true and IsAlive(Group3HWmanA) == true and IsAlive(Group3HWmanB) == true and IsAlive(Group3HWmanC) == true and IsAlive(Group3HWmanD) == true then
  57. AddTimer(NPC,2000,"Group3Pop",1, Spawn)
  58. end
  59. AddTimer(NPC,MakeRandomInt(720000,900000),"AliveCheck") --12 to 15 min despawn
  60. end
  61. end
  62. function Group1Pop(NPC,Spawn)
  63. local zone = GetZone(NPC)
  64. local Group1HWmanA = GetSpawnByLocationID(zone, 133784689)
  65. local Group1HWmanB = GetSpawnByLocationID(zone, 133784686)
  66. local Group1HWmanC = GetSpawnByLocationID(zone, 133784687)
  67. local Group1HWmanD = GetSpawnByLocationID(zone, 133784688)
  68. if IsInCombat(Group1HWmanA) == false then
  69. RaceSet(Group1HWmanA)
  70. end
  71. if IsInCombat(Group1HWmanB) == false then
  72. RaceSet(Group1HWmanB)
  73. end
  74. if IsInCombat(Group1HWmanC) == false then
  75. RaceSet(Group1HWmanC)
  76. end
  77. if IsInCombat(Group1HWmanD) == false then
  78. RaceSet(Group1HWmanD)
  79. end
  80. end
  81. function Group2Pop(NPC,Spawn)
  82. local zone = GetZone(NPC)
  83. local Group2HWmanA = GetSpawnByLocationID(zone, 133784693)
  84. local Group2HWmanB = GetSpawnByLocationID(zone, 133784690)
  85. local Group2HWmanC = GetSpawnByLocationID(zone, 133784691)
  86. local Group2HWmanD = GetSpawnByLocationID(zone, 133784692)
  87. if IsInCombat(Group2HWmanA) == false then
  88. RaceSet(Group2HWmanA)
  89. end
  90. if IsInCombat(Group2HWmanB) == false then
  91. RaceSet(Group2HWmanB)
  92. end
  93. if IsInCombat(Group2HWmanC) == false then
  94. RaceSet(Group2HWmanC)
  95. end
  96. if IsInCombat(Group2HWmanD) == false then
  97. RaceSet(Group2HWmanD)
  98. end
  99. end
  100. function Group3Pop(NPC,Spawn)
  101. local zone = GetZone(NPC)
  102. local Group3HWmanA = GetSpawnByLocationID(zone, 133784697)
  103. local Group3HWmanB = GetSpawnByLocationID(zone, 133784694)
  104. local Group3HWmanC = GetSpawnByLocationID(zone, 133784695)
  105. local Group3HWmanD = GetSpawnByLocationID(zone, 133784696)
  106. if IsInCombat(Group3HWmanA) == false then
  107. RaceSet(Group3HWmanA)
  108. end
  109. if IsInCombat(Group3HWmanB) == false then
  110. RaceSet(Group3HWmanB)
  111. end
  112. if IsInCombat(Group3HWmanC) == false then
  113. RaceSet(Group3HWmanC)
  114. end
  115. if IsInCombat(Group3HWmanD) == false then
  116. RaceSet(Group3HWmanD)
  117. end
  118. end
  119. function RaceSet(NPC) --RANDOMIZES RACE APPEARANCES BETWEEN BARBARIAN, HALFELF, & HUMAN
  120. --[[ RaceChoice = GetRace(NPC)
  121. if RaceChoice ==0 then
  122. if GetGender(NPC)==1 then
  123. SpawnSet(NPC,"model_type",MakeRandomInt(1467,1471))
  124. else
  125. SpawnSet(NPC,"model_type",MakeRandomInt(1462,1466))
  126. end
  127. elseif RaceChoice == 6 then
  128. if GetGender(NPC)==1 then
  129. SpawnSet(NPC,"model_type",78)
  130. else
  131. SpawnSet(NPC,"model_type",79)
  132. end
  133. elseif RaceChoice == 9 then
  134. if GetGender(NPC)==1 then
  135. SpawnSet(NPC,"model_type",134)
  136. else
  137. SpawnSet(NPC,"model_type",132)
  138. end ]]--
  139. local RaceChoice = MakeRandomInt(1,5)
  140. if RaceChoice ==1 then
  141. SpawnSet(NPC,"race",0)
  142. if GetGender(NPC)==1 then
  143. SpawnSet(NPC,"model_type",MakeRandomInt(1467,1471))
  144. else
  145. SpawnSet(NPC,"model_type",MakeRandomInt(1462,1466))
  146. end
  147. elseif RaceChoice == 2 or RaceChoice == 3 then
  148. SpawnSet(NPC,"race",6)
  149. if GetGender(NPC)==1 then
  150. SpawnSet(NPC,"model_type",78)
  151. else
  152. SpawnSet(NPC,"model_type",79)
  153. end
  154. elseif RaceChoice == 4 or RaceChoice == 5 then
  155. SpawnSet(NPC,"race",9)
  156. if GetGender(NPC)==1 then
  157. SpawnSet(NPC,"model_type",134)
  158. else
  159. SpawnSet(NPC,"model_type",132)
  160. end
  161. end --HANDLES SPAWN ANIMATIONS & ATTACKABLE FLAGGING
  162. CastSpell(NPC,41)
  163. AddTimer(NPC,1000,"Crouch")
  164. AddTimer(NPC,2300,"Uncrouch")
  165. SpawnSet(NPC,"faction",1)
  166. SpawnSet(NPC,"show_name",1)
  167. SpawnSet(NPC,"show_level",1)
  168. SpawnSet(NPC,"attackable",1)
  169. SpawnSet(NPC,"targetable",1)
  170. SpawnSet(NPC,"show_command_icon",1)
  171. SpawnSet(NPC,"collision_radius",30)
  172. SpawnSet(NPC,"initial_state",16512)
  173. end
  174. function Crouch(NPC,Spawn)
  175. CastSpell(NPC,41)
  176. SpawnSet(NPC,"visual_sate",220)
  177. end
  178. function Uncrouch(NPC,Spawn)
  179. SpawnSet(NPC,"visual_sate",0)
  180. end
  181. function AliveCheck(NPC,Spawn) --CHECKS FOR GROUPS AFTER 15 MIN OF SPAWN. IF NOT IN COMBAT/STILL EXISTS/STILL ALIVE, HIGHWAYMEN HIDE/Despawn AND ENCOUNTER RESETS
  182. local zone = GetZone(NPC)
  183. local Group1HWmanA = GetSpawnByLocationID(zone, 133784689)
  184. local Group1HWmanB = GetSpawnByLocationID(zone, 133784686)
  185. local Group1HWmanC = GetSpawnByLocationID(zone, 133784687)
  186. local Group1HWmanD = GetSpawnByLocationID(zone, 133784688)
  187. local Group2HWmanA = GetSpawnByLocationID(zone, 133784693)
  188. local Group2HWmanB = GetSpawnByLocationID(zone, 133784690)
  189. local Group2HWmanC = GetSpawnByLocationID(zone, 133784691)
  190. local Group2HWmanD = GetSpawnByLocationID(zone, 133784692)
  191. local Group3HWmanA = GetSpawnByLocationID(zone, 133784697)
  192. local Group3HWmanB = GetSpawnByLocationID(zone, 133784694)
  193. local Group3HWmanC = GetSpawnByLocationID(zone, 133784695)
  194. local Group3HWmanD = GetSpawnByLocationID(zone, 133784696)
  195. if IsInCombat(Group1HWmanA) == false and Group1HWmanA ~= nil and IsAlive(Group1HWmanA) == true or IsAlive(Group1HWmanA) == false or Group1HWmanA == nil then
  196. if IsInCombat(Group1HWmanB) == false and Group1HWmanB ~= nil and IsAlive(Group1HWmanB) == true or IsAlive(Group1HWmanB) == false or Group1HWmanB == nil then
  197. if IsInCombat(Group1HWmanC) == false and Group1HWmanC ~= nil and IsAlive(Group1HWmanC) == true or IsAlive(Group1HWmanC) == false or Group1HWmanC == nil then
  198. if IsInCombat(Group1HWmanD) == false and Group1HWmanD ~= nil and IsAlive(Group1HWmanD) == true or IsAlive(Group1HWmanD) == false or Group1HWmanD == nil then
  199. if IsInCombat(Group2HWmanA) == false and Group2HWmanA ~= nil and IsAlive(Group2HWmanA) == true or IsAlive(Group2HWmanA) == false or Group2HWmanA == nil then
  200. if IsInCombat(Group2HWmanB) == false and Group2HWmanB ~= nil and IsAlive(Group2HWmanB) == true or IsAlive(Group2HWmanB) == false or Group2HWmanB == nil then
  201. if IsInCombat(Group2HWmanC) == false and Group2HWmanC ~= nil and IsAlive(Group2HWmanC) == true or IsAlive(Group2HWmanC) == false or Group2HWmanC == nil then
  202. if IsInCombat(Group2HWmanD) == false and Group2HWmanD ~= nil and IsAlive(Group2HWmanD) == true or IsAlive(Group2HWmanD) == false or Group2HWmanD == nil then
  203. if IsInCombat(Group3HWmanA) == false and Group3HWmanA ~= nil and IsAlive(Group3HWmanA) == true or IsAlive(Group3HWmanA) == false or Group3HWmanA == nil then
  204. if IsInCombat(Group3HWmanB) == false and Group3HWmanB ~= nil and IsAlive(Group3HWmanB) == true or IsAlive(Group3HWmanB) == false or Group3HWmanB == nil then
  205. if IsInCombat(Group3HWmanC) == false and Group3HWmanC ~= nil and IsAlive(Group3HWmanC) == true or IsAlive(Group3HWmanC) == false or Group3HWmanC == nil then
  206. if IsInCombat(Group3HWmanD) == false and Group3HWmanD ~= nil and IsAlive(Group3HWmanD) == true or IsAlive(Group3HWmanD) == false or Group3HWmanD == nil then
  207. LeavingCrouch(NPC)--STARTS DESPAWN
  208. --LeavingCrouch(NPC,Spawn)
  209. else
  210. AddTimer(NPC,300000,"AliveCheck")
  211. end
  212. else
  213. AddTimer(NPC,300000,"AliveCheck")
  214. end
  215. else
  216. AddTimer(NPC,300000,"AliveCheck")
  217. end
  218. else
  219. AddTimer(NPC,300000,"AliveCheck")
  220. end
  221. else
  222. AddTimer(NPC,300000,"AliveCheck")
  223. end
  224. else
  225. AddTimer(NPC,300000,"AliveCheck")
  226. end
  227. else
  228. AddTimer(NPC,300000,"AliveCheck")
  229. end
  230. else
  231. AddTimer(NPC,300000,"AliveCheck")
  232. end
  233. else
  234. AddTimer(NPC,300000,"AliveCheck")
  235. end
  236. else
  237. AddTimer(NPC,300000,"AliveCheck")
  238. end
  239. else
  240. AddTimer(NPC,300000,"AliveCheck")
  241. end
  242. end
  243. end
  244. function LeavingCrouch(NPC) --DESPAWNING ANIMATIONS OF HIGHWAYMEN
  245. local zone = GetZone(NPC)
  246. local Group1HWmanA = GetSpawnByLocationID(zone, 133784689)
  247. local Group1HWmanB = GetSpawnByLocationID(zone, 133784686)
  248. local Group1HWmanC = GetSpawnByLocationID(zone, 133784687)
  249. local Group1HWmanD = GetSpawnByLocationID(zone, 133784688)
  250. local Group2HWmanA = GetSpawnByLocationID(zone, 133784693)
  251. local Group2HWmanB = GetSpawnByLocationID(zone, 133784690)
  252. local Group2HWmanC = GetSpawnByLocationID(zone, 133784691)
  253. local Group2HWmanD = GetSpawnByLocationID(zone, 133784692)
  254. local Group3HWmanA = GetSpawnByLocationID(zone, 133784697)
  255. local Group3HWmanB = GetSpawnByLocationID(zone, 133784694)
  256. local Group3HWmanC = GetSpawnByLocationID(zone, 133784695)
  257. local Group3HWmanD = GetSpawnByLocationID(zone, 133784696)
  258. if Group1HWmanA ~=nil then
  259. CastSpell(Group1HWmanA,320022)
  260. PlayFlavor(Group1HWmanA,"","","duck",0,0)
  261. AddTimer(NPC,2200,"Despawning")
  262. end
  263. if Group1HWmanB ~=nil then
  264. CastSpell(Group1HWmanB,320022)
  265. PlayFlavor(Group1HWmanB,"","","duck",0,0)
  266. AddTimer(NPC,2200,"Despawning")
  267. end
  268. if Group1HWmanC ~=nil then
  269. CastSpell(Group1HWmanC,320022)
  270. PlayFlavor(Group1HWmanC,"","","duck",0,0)
  271. AddTimer(NPC,2200,"Despawning")
  272. end
  273. if Group1HWmanD ~=nil then
  274. CastSpell(Group1HWmanD,320022)
  275. PlayFlavor(Group1HWmanD,"","","duck",0,0)
  276. AddTimer(NPC,2200,"Despawning")
  277. end
  278. if Group2HWmanA ~=nil then
  279. CastSpell(Group2HWmanA,320022)
  280. PlayFlavor(Group2HWmanA,"","","duck",0,0)
  281. AddTimer(NPC,2200,"Despawning")
  282. end
  283. if Group2HWmanB ~=nil then
  284. CastSpell(Group2HWmanB,320022)
  285. PlayFlavor(Group2HWmanB,"","","duck",0,0)
  286. AddTimer(NPC,2200,"Despawning")
  287. end
  288. if Group2HWmanC ~=nil then
  289. CastSpell(Group2HWmanC,320022)
  290. PlayFlavor(Group2HWmanC,"","","duck",0,0)
  291. AddTimer(NPC,2200,"Despawning")
  292. end
  293. if Group2HWmanD ~=nil then
  294. CastSpell(Group2HWmanD,320022)
  295. PlayFlavor(Group2HWmanD,"","","duck",0,0)
  296. AddTimer(NPC,2200,"Despawning")
  297. end
  298. if Group3HWmanA ~=nil then
  299. CastSpell(Group3HWmanA,320022)
  300. PlayFlavor(Group3HWmanA,"","","duck",0,0)
  301. AddTimer(NPC,2200,"Despawning")
  302. end
  303. if Group3HWmanB ~=nil then
  304. CastSpell(Group3HWmanB,320022)
  305. PlayFlavor(Group3HWmanB,"","","duck",0,0)
  306. AddTimer(NPC,2200,"Despawning")
  307. end
  308. if Group3HWmanC ~=nil then
  309. CastSpell(Group3HWmanC,320022)
  310. PlayFlavor(Group3HWmanC,"","","duck",0,0)
  311. AddTimer(NPC,2200,"Despawning")
  312. end
  313. if Group3HWmanD ~=nil then
  314. CastSpell(Group3HWmanD,320022)
  315. PlayFlavor(Group3HWmanD,"","","duck",0,0)
  316. AddTimer(NPC,2200,"Despawning")
  317. end
  318. end
  319. function Despawning(NPC,Spawn) --DESPAWNING OF HIGHWAYMEN
  320. local zone = GetZone(NPC)
  321. local Group1HWmanA = GetSpawnByLocationID(zone, 133784689)
  322. local Group1HWmanB = GetSpawnByLocationID(zone, 133784686)
  323. local Group1HWmanC = GetSpawnByLocationID(zone, 133784687)
  324. local Group1HWmanD = GetSpawnByLocationID(zone, 133784688)
  325. local Group2HWmanA = GetSpawnByLocationID(zone, 133784693)
  326. local Group2HWmanB = GetSpawnByLocationID(zone, 133784690)
  327. local Group2HWmanC = GetSpawnByLocationID(zone, 133784691)
  328. local Group2HWmanD = GetSpawnByLocationID(zone, 133784692)
  329. local Group3HWmanA = GetSpawnByLocationID(zone, 133784697)
  330. local Group3HWmanB = GetSpawnByLocationID(zone, 133784694)
  331. local Group3HWmanC = GetSpawnByLocationID(zone, 133784695)
  332. local Group3HWmanD = GetSpawnByLocationID(zone, 133784696)
  333. if Group1HWmanA ~=nil then
  334. Despawn(Group1HWmanA)
  335. end
  336. if Group1HWmanB ~=nil then
  337. Despawn(Group1HWmanB)
  338. end
  339. if Group1HWmanC ~=nil then
  340. Despawn(Group1HWmanC)
  341. end
  342. if Group1HWmanD ~=nil then
  343. Despawn(Group1HWmanD)
  344. end
  345. if Group2HWmanA ~=nil then
  346. Despawn(Group2HWmanA)
  347. end
  348. if Group2HWmanB ~=nil then
  349. Despawn(Group2HWmanB)
  350. end
  351. if Group2HWmanC ~=nil then
  352. Despawn(Group2HWmanC)
  353. end
  354. if Group2HWmanD ~=nil then
  355. Despawn(Group2HWmanD)
  356. end
  357. if Group3HWmanA ~=nil then
  358. Despawn(Group3HWmanA)
  359. end
  360. if Group3HWmanB ~=nil then
  361. Despawn(Group3HWmanB)
  362. end
  363. if Group3HWmanC ~=nil then
  364. Despawn(Group3HWmanC)
  365. end
  366. if Group3HWmanD ~=nil then
  367. Despawn(Group3HWmanD)
  368. end
  369. AddTimer(NPC,2000,"FinalDespawn")
  370. end
  371. function FinalDespawn(NPC)
  372. local zone = GetZone(NPC)
  373. if GetSpawnByLocationID(zone, 133784683) ~= nil then
  374. Despawn(GetSpawnByLocationID(zone, 133784683))
  375. end
  376. if GetSpawnByLocationID(zone, 133784684) ~= nil then
  377. Despawn(GetSpawnByLocationID(zone, 133784684))
  378. end
  379. end
  380. function respawn(NPC)
  381. spawn(NPC)
  382. end