9
3

NPCModule.lua 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. --[[
  2. Script Name : SpawnScripts/Generic/NPCModule.lua
  3. Script Author : LordPazuzu
  4. Script Date : 2023.11.20 08:11:41
  5. Script Purpose : NPC Statistics Control Script- In Development
  6. : Supersedes CombatModule.lua
  7. --]]
  8. require "SpawnScripts/Generic/EquipmentModule"
  9. GlobalDmgMod = 1.0 -- Global Damage Multiplier- make global adjustments to all NPC autoattack damage.
  10. GlobalStatMod = 1.0 -- Global Attribute Multiplier- make global adjustments to NPC attribute scores.
  11. GlobalHPMod = 1.0 -- Global Hit Point Multiplier
  12. GlobalPowerMod = 1.0 -- Global Power Pool Multiplier
  13. function NPCModule(NPC, Spawn)
  14. level = GetLevel(NPC) -- NPC Level
  15. difficulty = GetDifficulty(NPC) -- NPC Difficulty
  16. MeleeDmgMod = GetStr(NPC) / 10 -- Determines strength bonus to auttoattack damage.
  17. --Included functions. Comment out a function to disable.
  18. Attributes(NPC, Spawn) -- Determines basic stats of the NPC(str, agi, sta, int, wis)
  19. AutoAttack(NPC, Spawn) -- Determines the NPC's tier for the purposes of autoattack damage.
  20. Regen(NPC, Spawn) -- Sets NPC's health and/or power regeneration rates or disables regeneration entirely.
  21. HealthPower(NPC, Spawn) -- Calculates NPC's based on level and difficulty.
  22. --Heroic(NPC, Spawn) -- Detects if an NPC should be flagged as heroic and sets the heroic flag accordingly.
  23. AddTimer(NPC, 25, "Heroic") -- Applies heroic flag immediately after spawn in accordance with the way the server loads spawns.
  24. AddTimer(NPC, 1000, "Heroic") -- Redundant heroic check to compensate for server lag when using developer commands to reload spawns.
  25. end
  26. --Determine damage function based on NPC level.
  27. function AutoAttack(NPC, Spawn)
  28. if level <= 3 then
  29. TierOneA(NPC)
  30. elseif level >= 4 and level <= 5 then
  31. TierOneB(NPC)
  32. elseif level >= 6 and level <= 9 then
  33. TierOneC(NPC)
  34. elseif level >= 10 and level <= 15 then
  35. TierTwoA(NPC)
  36. elseif level >= 16 and level <= 19 then
  37. TierTwoB(NPC)
  38. elseif level >= 20 and level <= 24 then
  39. TierThreeA(NPC)
  40. elseif level >= 25 and level <= 29 then
  41. TierThreeB(NPC)
  42. end
  43. end
  44. -- Set attributes based on NPC level and difficulty
  45. function Attributes(NPC, Spawn)
  46. -- Calculate attributes
  47. if level <= 4 then
  48. baseStat = 19 else
  49. baseStat = level + 15
  50. end
  51. local low = baseStat - 15 -- Difficulty 1-3 vvv
  52. local four = baseStat - 10 -- Difficulty 4 vv
  53. local five = baseStat - 5 -- Difficulty 5 v
  54. local seven = baseStat + 10 -- Difficulty 7 ^
  55. local eight = baseStat + 15 -- Difficulty 8 ^^
  56. local nine = baseStat + 20 -- Difficulty 9 ^^^
  57. lowStat = math.floor(low * GlobalStatMod)
  58. fourStat = math.floor(four * GlobalStatMod)
  59. fiveStat = math.floor(five * GlobalStatMod)
  60. sixStat = math.floor(baseStat * GlobalStatMod)
  61. sevenStat = math.floor(seven * GlobalStatMod)
  62. eightStat = math.floor(eight * GlobalStatMod)
  63. nineStat = math.floor(nine * GlobalStatMod)
  64. -- Determine attribute by difficulty
  65. if difficulty <= 3 then
  66. finalStat = lowStat
  67. elseif difficulty == 4 then
  68. finalStat = fourStat
  69. elseif difficulty == 5 then
  70. finalStat = fiveStat
  71. elseif difficulty == 6 then
  72. finalStat = sixStat
  73. elseif difficulty == 7 then
  74. finalStat = sevenStat
  75. elseif difficulty == 8 then
  76. finalStat = eightStat
  77. elseif difficulty == 9 then
  78. finalStat = nineStat
  79. end
  80. SetInfoStructFloat(NPC, "str", finalStat)
  81. SetStrBase(NPC, finalStat)
  82. SetInfoStructFloat(NPC, "agi", finalStat)
  83. SetAgiBase(NPC, finalStat)
  84. SetInfoStructFloat(NPC, "sta", finalStat)
  85. SetStaBase(NPC, finalStat)
  86. SetInfoStructFloat(NPC, "intel", finalStat)
  87. SetIntBase(NPC, finalStat)
  88. SetInfoStructFloat(NPC, "wis", finalStat)
  89. SetWisBase(NPC, finalStat)
  90. end
  91. --Health and power regeneration rates
  92. function Regen(NPC, Spawn)
  93. -- In-combat health regeneration
  94. SetInfoStructUInt(NPC, "hp_regen_override", 1) -- Set to 0 to disable and allow the server to set the regen rate.
  95. SetInfoStructSInt(NPC, "hp_regen", 0) -- Set Regen Amount. Default 0
  96. -- In-combat power regeneration
  97. SetInfoStructUInt(NPC, "pw_regen_override", 1) -- Set to 0 to disable and allow the server to set the regen rate.
  98. SetInfoStructSInt(NPC, "pw_regen", 0) -- Set Regen Amount. Default 0
  99. end
  100. --Damage functions based on NPC level range.
  101. --Level 1-3
  102. function TierOneA(NPC, Spawn)
  103. lowDmg = math.floor(0 * GlobalDmgMod + MeleeDmgMod)
  104. highDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  105. damage(NPC)
  106. end
  107. --Level 4-5
  108. function TierOneB(NPC, Spawn)
  109. if difficulty <=4 then --
  110. lowDmg = math.floor(1 * GlobalDmgMod + MeleeDmgMod)
  111. highDmg =math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  112. elseif difficulty == 5 then
  113. lowDmg = math.floor(1 * GlobalDmgMod + MeleeDmgMod)
  114. highDmg = math.floor(3 * GlobalDmgMod + MeleeDmgMod)
  115. elseif difficulty >=6 and difficulty <=9 then
  116. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  117. highDmg = math.floor(4 * GlobalDmgMod + MeleeDmgMod)
  118. end
  119. damage(NPC)
  120. end
  121. --Level 6-9
  122. function TierOneC(NPC, Spawn)
  123. if difficulty <=4 then -- 1-3 dif 1-4
  124. lowDmg = math.floor(1 * GlobalDmgMod + MeleeDmgMod)
  125. highDmg =math.floor(3 * GlobalDmgMod + MeleeDmgMod)
  126. elseif difficulty == 5 then -- 2-4 dif 5MeleeDmgMod
  127. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  128. highDmg = math.floor(4 * GlobalDmgMod + MeleeDmgMod)
  129. elseif difficulty ==6 then -- 2-7 damage- Dif 6
  130. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  131. highDmg = math.floor(7 * GlobalDmgMod + MeleeDmgMod)
  132. elseif difficulty >=7 then -- 2-7 damage- Dif 7+
  133. lowDmg = math.floor(5 * GlobalDmgMod + MeleeDmgMod)
  134. highDmg = math.floor(10 * GlobalDmgMod + MeleeDmgMod)
  135. end
  136. damage(NPC)
  137. end
  138. --Level 10-15
  139. function TierTwoA(NPC, Spawn)
  140. if difficulty <=4 then
  141. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  142. highDmg =math.floor(4 * GlobalDmgMod + MeleeDmgMod)
  143. elseif difficulty == 5 then
  144. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  145. highDmg = math.floor(7 * GlobalDmgMod + MeleeDmgMod)
  146. elseif difficulty ==6 then
  147. lowDmg = math.floor(6 * GlobalDmgMod + MeleeDmgMod)
  148. highDmg = math.floor(15 * GlobalDmgMod + MeleeDmgMod)
  149. elseif difficulty == 7 then
  150. lowDmg = math.floor(8 * GlobalDmgMod + MeleeDmgMod)
  151. highDmg = math.floor(17 * GlobalDmgMod + MeleeDmgMod)
  152. elseif difficulty >= 8 then
  153. lowDmg = math.floor(12 * GlobalDmgMod + MeleeDmgMod)
  154. highDmg = math.floor(24 * GlobalDmgMod + MeleeDmgMod)
  155. end
  156. damage(NPC)
  157. end
  158. --Level 16-19
  159. function TierTwoB(NPC, Spawn)
  160. if difficulty <=4 then
  161. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  162. highDmg =math.floor(7 * GlobalDmgMod + MeleeDmgMod)
  163. elseif difficulty == 5 then
  164. lowDmg = math.floor(6 * GlobalDmgMod + MeleeDmgMod)
  165. highDmg = math.floor(15 * GlobalDmgMod + MeleeDmgMod)
  166. elseif difficulty ==6 then
  167. lowDmg = math.floor(12 * GlobalDmgMod + MeleeDmgMod)
  168. highDmg = math.floor(24 * GlobalDmgMod + MeleeDmgMod)
  169. elseif difficulty == 7 then
  170. lowDmg = math.floor(18 * GlobalDmgMod + MeleeDmgMod)
  171. highDmg = math.floor(32 * GlobalDmgMod + MeleeDmgMod)
  172. elseif difficulty >= 8 then
  173. lowDmg = math.floor(25 * GlobalDmgMod + MeleeDmgMod)
  174. highDmg = math.floor(55 * GlobalDmgMod + MeleeDmgMod)
  175. end
  176. damage(NPC)
  177. end
  178. --Level 20-24
  179. function TierThreeA(NPC, Spawn)
  180. if difficulty <=4 then
  181. lowDmg = math.floor(2 * GlobalDmgMod + MeleeDmgMod)
  182. highDmg =math.floor(7 * GlobalDmgMod + MeleeDmgMod)
  183. elseif difficulty == 5 then
  184. lowDmg = math.floor(6 * GlobalDmgMod + MeleeDmgMod)
  185. highDmg = math.floor(15 * GlobalDmgMod + MeleeDmgMod)
  186. elseif difficulty ==6 then
  187. lowDmg = math.floor(12 * GlobalDmgMod + MeleeDmgMod)
  188. highDmg = math.floor(24 * GlobalDmgMod + MeleeDmgMod)
  189. elseif difficulty == 7 then
  190. lowDmg = math.floor(18 * GlobalDmgMod + MeleeDmgMod)
  191. highDmg = math.floor(32 * GlobalDmgMod + MeleeDmgMod)
  192. elseif difficulty >= 8 then
  193. lowDmg = math.floor(25 * GlobalDmgMod + MeleeDmgMod)
  194. highDmg = math.floor(55 * GlobalDmgMod + MeleeDmgMod)
  195. end
  196. damage(NPC)
  197. end
  198. --Level 25-29
  199. function TierThreeB(NPC, Spawn)
  200. if difficulty <=4 then
  201. lowDmg = math.floor(6 * GlobalDmgMod + MeleeDmgMod)
  202. highDmg =math.floor(15 * GlobalDmgMod + MeleeDmgMod)
  203. elseif difficulty == 5 then
  204. lowDmg = math.floor(12 * GlobalDmgMod + MeleeDmgMod)
  205. highDmg = math.floor(24 * GlobalDmgMod + MeleeDmgMod)
  206. elseif difficulty ==6 then
  207. lowDmg = math.floor(20 * GlobalDmgMod + MeleeDmgMod)
  208. highDmg = math.floor(35 * GlobalDmgMod + MeleeDmgMod)
  209. elseif difficulty == 7 then
  210. lowDmg = math.floor(18 * GlobalDmgMod + MeleeDmgMod)
  211. highDmg = math.floor(32 * GlobalDmgMod + MeleeDmgMod)
  212. elseif difficulty >= 8 then
  213. lowDmg = math.floor(35 * GlobalDmgMod + MeleeDmgMod)
  214. highDmg = math.floor(75 * GlobalDmgMod + MeleeDmgMod)
  215. end
  216. damage(NPC)
  217. end
  218. --Autoattack damage override function.
  219. function damage(NPC, Spawn)
  220. SetInfoStructUInt(NPC, "override_primary_weapon", 1) --Set to 1 enables override for autoattack damage. Set to 0 to allow server to set damage.
  221. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  222. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  223. end
  224. --Calculate Hitpoints and Power
  225. function HealthPower(NPC, Spawn)
  226. -- Calculate multipliers based on difficulty tier
  227. if difficulty == 1 then
  228. HPMod = 0.20
  229. PWMod = 0.20
  230. elseif difficulty == 2 then
  231. HPMod = 0.25
  232. PWMod = 0.25
  233. elseif difficulty == 3 then
  234. HPMod = 0.35
  235. PWMod = 0.35
  236. elseif difficulty == 4 then
  237. HPMod = 0.45
  238. PWMod = 0.45
  239. elseif difficulty == 5 then
  240. HPMod = 0.66
  241. PWMod = 0.66
  242. elseif difficulty == 6 then
  243. HPMod = 1.0
  244. PWMod = 1.0
  245. elseif difficulty == 7 then
  246. HPMod = 1.45
  247. PWMod = 1.45
  248. elseif difficulty == 8 then
  249. HPMod = 2.2
  250. PWMod = 2.2
  251. elseif difficulty == 9 then
  252. HPMod = 3.25
  253. PWMod = 3.25
  254. end
  255. --Calculate hitpoints and power based on level and difficuty
  256. if level == 1 then
  257. hp = 30 * HPMod * GlobalHPMod
  258. pw = 25 * PWMod * GlobalPowerMod
  259. elseif level == 2 then
  260. hp = 45 * HPMod * GlobalHPMod
  261. pw = 35 * PWMod * GlobalPowerMod
  262. elseif level == 3 then
  263. hp = 75 * HPMod * GlobalHPMod
  264. pw = 45 * PWMod * GlobalPowerMod
  265. elseif level == 4 then
  266. hp = 110 * HPMod * GlobalHPMod
  267. pw = 55 * PWMod * GlobalPowerMod
  268. elseif level == 5 then
  269. hp = 130 * HPMod * GlobalHPMod
  270. pw = 65 * PWMod * GlobalPowerMod
  271. elseif level == 6 then
  272. hp = 150 * HPMod * GlobalHPMod
  273. pw = 80 * PWMod * GlobalPowerMod
  274. elseif level == 7 then
  275. hp = 200 * HPMod * GlobalHPMod
  276. pw = 90 * PWMod * GlobalPowerMod
  277. elseif level == 8 then
  278. hp = 240 * HPMod * GlobalHPMod
  279. pw = 100* PWMod * GlobalPowerMod
  280. elseif level == 9 then
  281. hp = 275 * HPMod * GlobalHPMod
  282. pw = 110 * PWMod * GlobalPowerMod
  283. elseif level == 10 then
  284. hp = 370 * HPMod * GlobalHPMod
  285. pw = 130 * PWMod * GlobalPowerMod
  286. elseif level == 11 then
  287. hp = 430 * HPMod * GlobalHPMod
  288. pw = 160 * PWMod * GlobalPowerMod
  289. elseif level == 12 then
  290. hp = 550 * HPMod * GlobalHPMod
  291. pw = 185 * PWMod * GlobalPowerMod
  292. elseif level == 13 then
  293. hp = 680 * HPMod * GlobalHPMod
  294. pw = 205 * PWMod * GlobalPowerMod
  295. elseif level == 14 then
  296. hp = 795 * HPMod * GlobalHPMod
  297. pw = 240 * PWMod * GlobalPowerMod
  298. elseif level == 15 then
  299. hp = 920 * HPMod * GlobalHPMod
  300. pw = 270 * PWMod * GlobalPowerMod
  301. elseif level == 16 then
  302. hp = 1045 * HPMod * GlobalHPMod
  303. pw = 310 * PWMod * GlobalPowerMod
  304. elseif level == 17 then
  305. hp = 1180 * HPMod * GlobalHPMod
  306. pw = 360 * PWMod * GlobalPowerMod
  307. elseif level == 18 then
  308. hp = 1290 * HPMod * GlobalHPMod
  309. pw = 410 * PWMod * GlobalPowerMod
  310. elseif level == 19 then
  311. hp = 1440 * HPMod * GlobalHPMod
  312. pw = 425 * PWMod * GlobalPowerMod
  313. elseif level == 20 then
  314. hp = 1930 * HPMod * GlobalHPMod
  315. pw = 475 * PWMod * GlobalPowerMod
  316. elseif level == 21 then
  317. hp = 2120 * HPMod * GlobalHPMod
  318. pw = 500 * PWMod * GlobalPowerMod
  319. elseif level == 22 then
  320. hp = 2355 * HPMod * GlobalHPMod
  321. pw = 545 * PWMod * GlobalPowerMod
  322. elseif level == 23 then
  323. hp = 2595 * HPMod * GlobalHPMod
  324. pw = 575 * PWMod * GlobalPowerMod
  325. elseif level == 24 then
  326. hp = 2840 * HPMod * GlobalHPMod
  327. pw = 620 * PWMod * GlobalPowerMod
  328. elseif level == 25 then
  329. hp = 3080 * HPMod * GlobalHPMod
  330. pw = 670 * PWMod * GlobalPowerMod
  331. elseif level == 26 then
  332. hp = 3340 * HPMod * GlobalHPMod
  333. pw = 700 * PWMod * GlobalPowerMod
  334. elseif level == 27 then
  335. hp = 3600 * HPMod * GlobalHPMod
  336. pw = 755 * PWMod * GlobalPowerMod
  337. elseif level == 28 then
  338. hp = 3820 * HPMod * GlobalHPMod
  339. pw = 795 * PWMod * GlobalPowerMod
  340. elseif level == 29 then
  341. hp = 4240 * HPMod * GlobalHPMod
  342. pw = 835 * PWMod * GlobalPowerMod
  343. else
  344. hp = 5000 * HPMod * GlobalHPMod --temp values
  345. pw = 900 * PWMod * GlobalPowerMod -- temp values
  346. end
  347. ModifyMaxHP(NPC, math.floor(hp))
  348. ModifyHP(NPC, math.floor(hp))
  349. ModifyMaxPower(NPC, math.floor(pw))
  350. ModifyPower(NPC, math.floor(hp))
  351. end
  352. --Automatically set heroic flags based on specified criteria
  353. function Heroic(NPC, Spawn)
  354. local group = GetGroup(NPC)
  355. if group ~= nil then
  356. local groupsize = #group
  357. if groupsize > 1 then
  358. SpawnSet(NPC, "heroic", 1)
  359. end
  360. end
  361. if difficulty == 8 or difficulty == 9 then
  362. SpawnSet(NPC, "heroic", 1)
  363. end
  364. end
  365. -- OPTIONAL COSMETIC FUNCTIONS--
  366. --Race functions for DoF compatibility. These are called independently in the NPC's spawn function.
  367. function dwarf(NPC, Spawn)
  368. SpawnSet(NPC,"race",2)
  369. if GetGender(NPC)==2 then
  370. SpawnSet(NPC,"model_type",109)
  371. else
  372. SpawnSet(NPC,"model_type",110)
  373. end
  374. hair(NPC)
  375. end
  376. function froglok(NPC, Spawn)
  377. SpawnSet(NPC,"race",4)
  378. if GetGender(NPC)==2 then
  379. SpawnSet(NPC,"model_type",76)
  380. else
  381. SpawnSet(NPC,"model_type",77)
  382. end
  383. hair(NPC)
  384. end
  385. function halfling(NPC, Spawn)
  386. local hair = MakeRandomInt(1,2)
  387. SpawnSet(NPC,"race",7)
  388. if GetGender(NPC)==2 then
  389. SpawnSet(NPC,"model_type",107)
  390. else
  391. SpawnSet(NPC,"model_type",108)
  392. end
  393. if hair == 1 then
  394. SpawnSet(NPC, "hair_type", MakeRandomInt(1125,1128))
  395. else
  396. SpawnSet(NPC, "hair_type", MakeRandomInt(1133,1139))
  397. end
  398. haircolor(NPC)
  399. end
  400. function highelf(NPC, Spawn)
  401. SpawnSet(NPC,"race",8)
  402. if GetGender(NPC)==2 then
  403. SpawnSet(NPC,"model_type",135)
  404. else
  405. SpawnSet(NPC,"model_type",136)
  406. end
  407. hair(NPC)
  408. end
  409. function woodelf(NPC, Spawn)
  410. SpawnSet(NPC,"race",15)
  411. if GetGender(NPC)==2 then
  412. SpawnSet(NPC,"model_type",113)
  413. else
  414. SpawnSet(NPC,"model_type",114)
  415. end
  416. SpawnSet(NPC, "hair_type", MakeRandomInt(1133, 1139))
  417. haircolor(NPC)
  418. end
  419. function barbarian(NPC, Spawn)
  420. local hair = MakeRandomInt(1,2)
  421. SpawnSet(NPC,"race",0)
  422. if GetGender(NPC)==2 then
  423. SpawnSet(NPC,"model_type",111)
  424. else
  425. SpawnSet(NPC,"model_type",112)
  426. end
  427. if hair == 1 then
  428. SpawnSet(NPC, "hair_type", MakeRandomInt(1125,1128))
  429. else
  430. SpawnSet(NPC, "hair_type", MakeRandomInt(1133,1139))
  431. end
  432. haircolor(NPC)
  433. end
  434. function erudite(NPC, Spawn)
  435. SpawnSet(NPC,"race",3)
  436. if GetGender(NPC)==2 then
  437. SpawnSet(NPC,"model_type",120)
  438. else
  439. SpawnSet(NPC,"model_type",119)
  440. end
  441. hair(NPC)
  442. end
  443. function gnome(NPC, Spawn)
  444. SpawnSet(NPC,"race",5)
  445. if GetGender(NPC)==2 then
  446. SpawnSet(NPC,"model_type",122)
  447. else
  448. SpawnSet(NPC,"model_type",121)
  449. end
  450. hair(NPC)
  451. end
  452. function halfelf(NPC, Spawn)
  453. SpawnSet(NPC,"race",6)
  454. if GetGender(NPC)==2 then
  455. SpawnSet(NPC,"model_type",79)
  456. else
  457. SpawnSet(NPC,"model_type",78)
  458. end
  459. hair(NPC)
  460. end
  461. function human(NPC, Spawn)
  462. SpawnSet(NPC,"race",9)
  463. if GetGender(NPC)==2 then
  464. SpawnSet(NPC,"model_type",132)
  465. else
  466. SpawnSet(NPC,"model_type",134)
  467. end
  468. hair(NPC)
  469. end
  470. function kerra(NPC, Spawn)
  471. SpawnSet(NPC,"race",11)
  472. if GetGender(NPC)==2 then
  473. SpawnSet(NPC,"model_type",81)
  474. else
  475. SpawnSet(NPC,"model_type",82)
  476. end
  477. hair(NPC)
  478. end
  479. function darkelf(NPC, Spawn)
  480. SpawnSet(NPC,"race",1)
  481. if GetGender(NPC)==2 then
  482. SpawnSet(NPC,"model_type",116)
  483. else
  484. SpawnSet(NPC,"model_type",115)
  485. end
  486. hair(NPC)
  487. DarkElfHairColor(NPC, Spawn)
  488. end
  489. function iksar(NPC, Spawn)
  490. SpawnSet(NPC,"race",10)
  491. if GetGender(NPC)==2 then
  492. SpawnSet(NPC,"model_type",104)
  493. else
  494. SpawnSet(NPC,"model_type",103)
  495. end
  496. hair(NPC)
  497. end
  498. function ogre(NPC, Spawn)
  499. SpawnSet(NPC,"race",12)
  500. if GetGender(NPC)==2 then
  501. SpawnSet(NPC,"model_type",123)
  502. else
  503. SpawnSet(NPC,"model_type",124)
  504. end
  505. hair(NPC)
  506. end
  507. function ratonga(NPC, Spawn)
  508. SpawnSet(NPC,"race",13)
  509. if GetGender(NPC)==2 then
  510. SpawnSet(NPC,"model_type",54)
  511. else
  512. SpawnSet(NPC,"model_type",53)
  513. end
  514. hair(NPC)
  515. end
  516. function troll(NPC, Spawn)
  517. SpawnSet(NPC,"race",14)
  518. if GetGender(NPC)==2 then
  519. SpawnSet(NPC,"model_type",105)
  520. else
  521. SpawnSet(NPC,"model_type",106)
  522. end
  523. hair(NPC)
  524. end
  525. -- Classic Orcs
  526. function Deathfist(NPC, Spawn)
  527. SpawnSet(NPC,"model_type",137)
  528. SpawnSet(NPC, "race", 20)
  529. end
  530. function Bloodskull(NPC, Spawn)
  531. SpawnSet(NPC,"model_type",137)
  532. SpawnSet(NPC, "race", 20)
  533. SpawnSet(NPC, "skin_color", "50 60 50")
  534. SpawnSet(NPC, "eye_color", "98 63 28")
  535. end
  536. function Brokentusk(NPC, Spawn)
  537. SpawnSet(NPC,"model_type",137)
  538. SpawnSet(NPC, "race", 20)
  539. SpawnSet(NPC, "skin_color", "110 75 75")
  540. SpawnSet(NPC, "eye_color", "98 63 28")
  541. end
  542. function Lonetusk(NPC, Spawn)
  543. SpawnSet(NPC,"model_type",137)
  544. SpawnSet(NPC, "race", 20)
  545. SpawnSet(NPC, "skin_color", "92 52 52")
  546. SpawnSet(NPC, "eye_color", "98 63 28")
  547. end
  548. function Ree(NPC, Spawn)
  549. SpawnSet(NPC,"model_type",137)
  550. SpawnSet(NPC, "race", 20)
  551. end
  552. -- DoF compatible hair functions
  553. function hair(NPC, Spawn)
  554. SpawnSet(NPC, "hair_type", MakeRandomInt(1125, 1139))
  555. if GetRace(NPC)==1 then --Darkelf
  556. DarkElfHairColor(NPC, Spawn)
  557. else
  558. haircolor(NPC)
  559. end
  560. end
  561. function haircolor(NPC, Spawn)
  562. local color = MakeRandomInt(1,5)
  563. if color == 1 then
  564. SpawnSet(NPC, "hair_type_color", "102 36 18")
  565. SpawnSet(NPC, "hair_type_highlight_color", "138 129 121")
  566. SpawnSet(NPC, "hair_face_color", "102 36 18")
  567. SpawnSet(NPC, "hair_face_highlight_color", "138 129 121")
  568. elseif color == 2 then
  569. SpawnSet(NPC, "hair_type_color", "218 187 120")
  570. SpawnSet(NPC, "hair_type_highlight_color", "114 65 4")
  571. SpawnSet(NPC, "hair_face_color", "218 187 120")
  572. SpawnSet(NPC, "hair_face_highlight_color", "114 65 4")
  573. elseif color == 3 then
  574. SpawnSet(NPC, "hair_type_color", "51 18 8")
  575. SpawnSet(NPC, "hair_type_highlight_color", "60 59 55")
  576. SpawnSet(NPC, "hair_face_color", "51 18 8")
  577. SpawnSet(NPC, "hair_face_highlight_color", "60 59 55")
  578. elseif color == 4 then
  579. SpawnSet(NPC, "hair_type_color", "5 5 10")
  580. SpawnSet(NPC, "hair_type_highlight_color", "5 5 10")
  581. SpawnSet(NPC, "hair_face_color", "5 5 10")
  582. SpawnSet(NPC, "hair_face_highlight_color", "5 5 10")
  583. elseif color == 5 then
  584. SpawnSet(NPC, "hair_type_color", "230 230 230")
  585. SpawnSet(NPC, "hair_type_highlight_color", "154 147 81")
  586. SpawnSet(NPC, "hair_face_color", "230 230 230")
  587. SpawnSet(NPC, "hair_face_highlight_color", "154 147 81")
  588. end
  589. end
  590. function DarkElfHairColor(NPC, Spawn)
  591. local color = MakeRandomInt(1,5)
  592. if color == 1 then
  593. SpawnSet(NPC, "hair_type_color", "183 177 183")
  594. SpawnSet(NPC, "hair_type_highlight_color", "84 32 14")
  595. SpawnSet(NPC, "hair_face_color", "183 177 183")
  596. SpawnSet(NPC, "hair_face_highlight_color", "84 32 14")
  597. elseif color == 2 then
  598. SpawnSet(NPC, "hair_type_color", "170 191 191")
  599. SpawnSet(NPC, "hair_type_highlight_color", "84 32 4")
  600. SpawnSet(NPC, "hair_face_color", "170 191 191")
  601. SpawnSet(NPC, "hair_face_highlight_color", "84 32 4")
  602. elseif color == 3 then
  603. SpawnSet(NPC, "hair_type_color", "179 173 194")
  604. SpawnSet(NPC, "hair_type_highlight_color", "198 184 78")
  605. SpawnSet(NPC, "hair_face_color", "179 173 194")
  606. SpawnSet(NPC, "hair_face_highlight_color", "198 184 78")
  607. elseif color == 4 then
  608. SpawnSet(NPC, "hair_type_color", "219 244 244")
  609. SpawnSet(NPC, "hair_type_highlight_color", "105 103 97")
  610. SpawnSet(NPC, "hair_face_color", "219 244 244")
  611. SpawnSet(NPC, "hair_face_highlight_color", "105 103 97")
  612. elseif color == 5 then
  613. SpawnSet(NPC, "hair_type_color", "139 122 138")
  614. SpawnSet(NPC, "hair_type_highlight_color", "105 103 97")
  615. SpawnSet(NPC, "hair_face_color", "139 122 138")
  616. SpawnSet(NPC, "hair_face_highlight_color", "105 103 97")
  617. end
  618. end
  619. --Idle Animation Packages: Call the function in the main spawn function of the spawn script.
  620. function IdleAggressive(NPC)
  621. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  622. local choice = MakeRandomInt(1,5)
  623. if choice == 1 then
  624. PlayFlavor(NPC,"","","scheme",0,0)
  625. elseif choice == 2 then
  626. PlayFlavor(NPC,"","","brandish",0,0)
  627. elseif choice == 3 then
  628. PlayFlavor(NPC,"","","tapfoot",0,0)
  629. elseif choice == 4 then
  630. PlayFlavor(NPC,"","","swear",0,0)
  631. elseif choice == 5 then
  632. PlayFlavor(NPC,"","","threaten",0,0)
  633. end
  634. end
  635. AddTimer(NPC,MakeRandomInt(6500,12000),"IdleAggressive")
  636. end
  637. function IdleAlert(NPC)
  638. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  639. local choice = MakeRandomInt(1,5)
  640. if choice == 1 then
  641. PlayFlavor(NPC,"","","peer",0,0)
  642. elseif choice == 2 then
  643. PlayFlavor(NPC,"","","listen",0,0)
  644. elseif choice == 3 then
  645. PlayFlavor(NPC,"","","tapfoot",0,0)
  646. elseif choice == 4 then
  647. PlayFlavor(NPC,"","","yawn",0,0)
  648. elseif choice == 5 then
  649. PlayFlavor(NPC,"","","ponder",0,0)
  650. end
  651. end
  652. AddTimer(NPC,MakeRandomInt(6500,12000),"IdleAlert")
  653. end
  654. function IdleMischief(NPC)
  655. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  656. local choice = MakeRandomInt(1,5)
  657. if choice == 1 then
  658. PlayFlavor(NPC,"","","moon",0,0)
  659. elseif choice == 2 then
  660. PlayFlavor(NPC,"","","neener",0,0)
  661. elseif choice == 3 then
  662. PlayFlavor(NPC,"","","giggle",0,0)
  663. elseif choice == 4 then
  664. PlayFlavor(NPC,"","","dance",0,0)
  665. elseif choice == 5 then
  666. PlayFlavor(NPC,"","","heartattack",0,0)
  667. end
  668. end
  669. AddTimer(NPC,MakeRandomInt(6500,12000),"IdleMischief")
  670. end
  671. function IdleBored(NPC)
  672. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  673. local choice = MakeRandomInt(1,5)
  674. if choice == 1 then
  675. PlayFlavor(NPC,"","","tapfoot",0,0)
  676. elseif choice == 2 then
  677. PlayFlavor(NPC,"","","sigh",0,0)
  678. elseif choice == 3 then
  679. PlayFlavor(NPC,"","","stretch",0,0)
  680. elseif choice == 4 then
  681. PlayFlavor(NPC,"","","yawn",0,0)
  682. elseif choice == 5 then
  683. PlayFlavor(NPC,"","","stare",0,0)
  684. end
  685. end
  686. AddTimer(NPC,MakeRandomInt(6500,12000),"IdleBored")
  687. end
  688. function IdlePlayful(NPC)
  689. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  690. local choice = MakeRandomInt(1,5)
  691. if choice == 1 then
  692. PlayFlavor(NPC,"","","dance",0,0)
  693. elseif choice == 2 then
  694. PlayFlavor(NPC,"","","flirt",0,0)
  695. elseif choice == 3 then
  696. PlayFlavor(NPC,"","","smile",0,0)
  697. elseif choice == 4 then
  698. PlayFlavor(NPC,"","","thumbsup",0,0)
  699. elseif choice == 5 then
  700. PlayFlavor(NPC,"","","yeah",0,0)
  701. end
  702. end
  703. AddTimer(NPC,MakeRandomInt(6500,12000),"IdlePlayful")
  704. end
  705. function IdleSad(NPC)
  706. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  707. local choice = MakeRandomInt(1,5)
  708. if choice == 1 then
  709. PlayFlavor(NPC,"","","sad",0,0)
  710. elseif choice == 2 then
  711. PlayFlavor(NPC,"","","pout",0,0)
  712. elseif choice == 3 then
  713. PlayFlavor(NPC,"","","sigh",0,0)
  714. elseif choice == 4 then
  715. PlayFlavor(NPC,"","","sulk",0,0)
  716. elseif choice == 5 then
  717. PlayFlavor(NPC,"","","cry",0,0)
  718. end
  719. end
  720. AddTimer(NPC,MakeRandomInt(6500,12000),"IdleSad")
  721. end
  722. function IdleSneaky(NPC)
  723. if not IsInCombat(NPC) and GetRunbackDistance(NPC)<2 then
  724. local choice = MakeRandomInt(1,5)
  725. if choice == 1 then
  726. PlayFlavor(NPC,"","","scheme",0,0)
  727. elseif choice == 2 then
  728. PlayFlavor(NPC,"","","smirk",0,0)
  729. elseif choice == 3 then
  730. PlayFlavor(NPC,"","","whome",0,0)
  731. elseif choice == 4 then
  732. PlayFlavor(NPC,"","","beckon",0,0)
  733. elseif choice == 5 then
  734. PlayFlavor(NPC,"","","cutthroat",0,0)
  735. end
  736. end
  737. AddTimer(NPC,MakeRandomInt(6500,12000),"IdleSneaky")
  738. end
  739. function IdlePriest(NPC)
  740. if IsInCombat(NPC) == false then
  741. choice = MakeRandomInt(1,5)
  742. if choice == 1 then
  743. CastSpell(NPC, 110002, 5, NPC)
  744. elseif choice == 2 then
  745. CastSpell(NPC, 110003, 5, NPC)
  746. PlayFlavor(NPC,"","","yawn",0,0)
  747. -- PlayAnimation(NPC, 891)
  748. elseif choice == 4 then
  749. PlayFlavor(NPC,"","","tapfoot",0,0)
  750. -- PlayAnimation(NPC, 713)
  751. elseif choice == 5 then
  752. PlayFlavor(NPC,"","","sniff",0,0)
  753. -- PlayAnimation(NPC, 553)
  754. end
  755. end
  756. AddTimer(NPC,MakeRandomInt(6500,12000),"IdlePriest")
  757. end
  758. function IdleAngry(NPC)
  759. if IsInCombat(NPC) == false then
  760. choice = MakeRandomInt(1,5)
  761. if choice == 1 then
  762. PlayFlavor(NPC,"","","frustrated",0,0)
  763. elseif choice == 2 then
  764. PlayFlavor(NPC,"","","curse",0,0)
  765. elseif choice == 3 then
  766. PlayFlavor(NPC,"","","scold",0,0)
  767. elseif choice == 4 then
  768. PlayFlavor(NPC,"","","shakefist",0,0)
  769. elseif choice == 5 then
  770. PlayFlavor(NPC,"","","swear",0,0)
  771. end
  772. end
  773. AddTimer(NPC,MakeRandomInt(7000,10000),"IdleAngry")
  774. end
  775. function IdleBeggar(NPC)
  776. if IsInCombat(NPC) == false then
  777. choice = MakeRandomInt(1,5)
  778. if choice == 1 then
  779. PlayFlavor(NPC,"","","beg",0,0)
  780. -- PlayAnimation(NPC, 310)
  781. elseif choice == 2 then
  782. PlayFlavor(NPC,"","","peer",0,0)
  783. -- PlayAnimation(NPC, 411)
  784. elseif choice == 3 then
  785. PlayFlavor(NPC,"","","yawn",0,0)
  786. -- PlayAnimation(NPC, 891)
  787. elseif choice == 4 then
  788. PlayFlavor(NPC,"","","tapfoot",0,0)
  789. -- PlayAnimation(NPC, 713)
  790. elseif choice == 5 then
  791. PlayFlavor(NPC,"","","sniff",0,0)
  792. -- PlayAnimation(NPC, 553)
  793. end
  794. end
  795. AddTimer(NPC,MakeRandomInt(10000,15000),"IdleBeggar")
  796. end
  797. function IdleTinker(NPC)
  798. if IsInCombat(NPC) == false then
  799. choice = MakeRandomInt(1,7)
  800. if choice == 1 then
  801. PlayFlavor(NPC,"","","confused",0,0)
  802. -- PlayAnimation(NPC, 310)
  803. elseif choice == 2 then
  804. PlayFlavor(NPC,"","","yes",0,0)
  805. -- PlayAnimation(NPC, 411)
  806. elseif choice == 3 then
  807. PlayFlavor(NPC,"","","boggle",0,0)
  808. -- PlayAnimation(NPC, 891)
  809. elseif choice == 4 then
  810. PlayFlavor(NPC,"","","ponder",0,0)
  811. -- PlayAnimation(NPC, 713)
  812. elseif choice == 5 then
  813. PlayFlavor(NPC,"","","grumble",0,0)
  814. -- PlayAnimation(NPC, 553)
  815. elseif choice == 6 then
  816. PlayFlavor(NPC,"","","doh",0,0)
  817. -- PlayAnimation(NPC, 553)
  818. elseif choice == 7 then
  819. PlayFlavor(NPC,"","","crazy",0,0)
  820. -- PlayAnimation(NPC, 553)
  821. end
  822. end
  823. AddTimer(NPC,MakeRandomInt(8000,13000),"IdleTinker")
  824. end
  825. -- PATHING SCRIPTS --
  826. --[[ Randomized Movement Loops
  827. Call the RandomMovement() function in the NPC's spawn function.
  828. Example format: RandomMovement(NPC, Spawn, -5, 5, 2, 8, 15)
  829. This exampled sets the NPC to randomly move anywhere in a 5 meter radius
  830. from it's spawn point at a speed of 2, moving every 8-15 seconds.
  831. --]]
  832. function RandomMovement(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  833. local X = GetX(NPC)
  834. local Y = GetY(NPC)
  835. local Z = GetZ(NPC)
  836. MovementLoopAddLocation(NPC, X, Y, Z, Speed, MakeRandomInt(MinDly, MaxDly))
  837. MovementMod(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  838. MovementLoopAddLocation(NPC, X + LocModX, Y, Z + LocModZ, Speed, MakeRandomInt(MinDly, MaxDly))
  839. MovementMod(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  840. MovementLoopAddLocation(NPC, X + LocModX, Y, Z + LocModZ, Speed, MakeRandomInt(MinDly, MaxDly))
  841. MovementMod(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  842. MovementLoopAddLocation(NPC, X + LocModX, Y, Z + LocModZ, Speed, MakeRandomInt(MinDly, MaxDly))
  843. MovementMod(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  844. MovementLoopAddLocation(NPC, X + LocModX, Y, Z + LocModZ, Speed, MakeRandomInt(MinDly, MaxDly))
  845. MovementMod(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  846. MovementLoopAddLocation(NPC, X + LocModX, Y, Z + LocModZ, Speed, MakeRandomInt(MinDly, MaxDly))
  847. end
  848. function RandomMovementFlight(NPC, Spawn, NegDist, PosDist, NegHeight, PosHeight, Speed, MinDly, MaxDly)
  849. local X = GetX(NPC)
  850. local Y = GetY(NPC)
  851. local Z = GetZ(NPC)
  852. MovementLoopAddLocation(NPC, X, Y, Z, Speed, MakeRandomInt(MinDly, MaxDly))
  853. MovementLoopAddLocation(NPC, X + MakeRandomInt(NegDist, PosDist), Y + MakeRandomInt(NegHeight, PosHeight), Z + MakeRandomInt(NegDist, PosDist), Speed, MakeRandomInt(MinDly, MaxDly))
  854. MovementLoopAddLocation(NPC, X + MakeRandomInt(NegDist, PosDist), Y + MakeRandomInt(NegHeight, PosHeight), Z + MakeRandomInt(NegDist, PosDist), Speed, MakeRandomInt(MinDly, MaxDly))
  855. MovementLoopAddLocation(NPC, X + MakeRandomInt(NegDist, PosDist), Y + MakeRandomInt(NegHeight, PosHeight), Z + MakeRandomInt(NegDist, PosDist), Speed, MakeRandomInt(MinDly, MaxDly))
  856. MovementLoopAddLocation(NPC, X + MakeRandomInt(NegDist, PosDist), Y + MakeRandomInt(NegHeight, PosHeight), Z + MakeRandomInt(NegDist, PosDist), Speed, MakeRandomInt(MinDly, MaxDly))
  857. MovementLoopAddLocation(NPC, X + MakeRandomInt(NegDist, PosDist), Y + MakeRandomInt(NegHeight, PosHeight), Z + MakeRandomInt(NegDist, PosDist), Speed, MakeRandomInt(MinDly, MaxDly))
  858. end
  859. ---Set an NPC to follow another NPC
  860. function FollowNPC(NPC, Spawn, LocID, Speed, Distance)
  861. local zone = GetZone(NPC)
  862. local leader = GetSpawnByLocationID(zone, LocID)
  863. if GetDistance(NPC, leader) >= Distance then
  864. MovementLoopAddLocation (NPC, GetX(leader), GetY(leader), GetZ(leader), Speed, 0)
  865. end
  866. -- in progress, do not use
  867. end
  868. function MovementMod(NPC, Spawn, NegDist, PosDist, Speed, MinDly, MaxDly)
  869. MinNegDist = math.floor(NegDist/2)
  870. MinPosDist = math.floor(PosDist/2)
  871. MinX = MakeRandomInt(1,2)
  872. MinZ = MakeRandomInt(1,2)
  873. if MinX == 1 then
  874. LocModX = MakeRandomInt(MinNegDist, NegDist)
  875. elseif MinX == 2 then
  876. LocModX = MakeRandomInt(MinPostDist, PosDist)
  877. end
  878. if MinZ == 1 then
  879. LocModZ = MakeRandomInt(MinNegDist, NegDist)
  880. elseif MinZ == 2 then
  881. LocModZ = MakeRandomInt(MinPostDist, PosDist)
  882. end
  883. end
  884. -- Automatically calculate hit points, power, and regeneration for named NPCs
  885. function Named(NPC, Spawn)
  886. level = GetLevel(NPC)
  887. difficulty = GetDifficulty(NPC)
  888. NamedMod = 1.5
  889. HealthPower(NPC)
  890. ModifyMaxHP(NPC, math.floor(hp * NamedMod))
  891. ModifyHP(NPC, math.floor(hp * NamedMod))
  892. ModifyMaxPower(NPC, math.floor(pw * NamedMod))
  893. ModifyPower(NPC, math.floor(hp * NamedMod))
  894. SetInfoStructUInt(NPC, "hp_regen_override", 1)
  895. SetInfoStructSInt(NPC, "hp_regen", (level * 2) + (difficulty * 2))
  896. SetInfoStructUInt(NPC, "pw_regen_override", 1)
  897. SetInfoStructSInt(NPC, "pw_regen", (level * 2) + (difficulty * 2))
  898. end
  899. -- Social Aggro by Faction- IN PROGRESS, DO NOT USE
  900. function Social(NPC, Spawn)
  901. MyFaction = GetFactionID(NPC)
  902. SocialRadius = GetAggroRadius(NPC) * 2
  903. SetPlayerProximityFunction(NPC, SocialRadius, "CheckCombat")
  904. end
  905. function CheckCombat(NPC, Spawn)
  906. Say(NPC, "Checking for combat.")
  907. if IsInCombat(Spawn) then
  908. Say(NPC, "You're in combat!")
  909. SocialAggro(NPC, Spawn)
  910. end
  911. end
  912. function SocialAggro(NPC, Spawn)
  913. local MobAssist = GetTarget(Spawn)
  914. local AssistFaction = GetFactionID(MobAssist)
  915. if MyFaction == AssistFaction then
  916. Attack(NPC, Spawn)
  917. end
  918. end