Guest User

betterAi_template

a guest
Jun 28th, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1.  
  2. --Basic template:
  3. require("betterAi");
  4.  
  5. function DeleteObject(handle)
  6. betterAi.DeleteObject(handle);
  7. end
  8.  
  9. function AddObject(handle)
  10. betterAi.AddObject(handle);
  11. end
  12.  
  13. function Update(dTime)
  14. betterAi.Update(dTime);
  15. end
  16.  
  17. --End of basic template
  18.  
  19. --Creating a custom "ai" 1:
  20.  
  21. local myTankAi = betterAi.createCustomAi("tankAi");
  22. myTankAi.init = function(self,handle)
  23. self.super.init(self,handle);
  24. self.myClassLabel = GetClassLabel(handle);
  25. --This function is called when a object that uses the ai is added to the map
  26. end
  27.  
  28. myTankAi.update = function(self,dTime)
  29. print(self.myClassLabel);
  30. --Update for each object that uses this ai
  31. --Can be used with self.handle to command unit
  32. --i.e Goto(self.handle,path/vector/etc);
  33. end
  34.  
  35. myTankAi.destroy = function(self)
  36. print(self.handle,self.label .. " died");
  37. --Called when the unit using the ai is destroyed
  38. end
  39. --Makes "avtank" and "svtank" use the ai.
  40.  
  41. betterAi.setCustomAi("avtank","tankAi");
  42. betterAi.setCustomAi("svtank","tankAi");
  43.  
  44. --Create a custom "ai" 1 end
  45.  
  46. --Create a custom "ai" 2:
  47.  
  48. local myWingmanAi = betterAi.createCustomAi("wingmanAi");
  49.  
  50. myWingmanAi.init = function(self,handle)
  51. self.super.init(self,handle);
  52. self.currentTarget = nil;
  53. end
  54.  
  55. myWingmanAi.update = function(self,dTime)
  56. if(self.currentTarget ~= GetNearestEnemy(self.handle)) then
  57. --Selecting target every update will paralyse the unit.
  58. self.currentTarget = GetNearestEnemy(self.handle);
  59. Attack(self.handle,self.currentTarget);
  60. end
  61. end
  62.  
  63. myWingmanAi.destroy = function(self)
  64. print("Dead");
  65. end
  66.  
  67. --Makes all units of the type "wingman" use the "wingmanAi"
  68. --Look in the odf files to find out what the class type is for a given unit
  69.  
  70. betterAi.setCustomAiForClass("wingman","wingmanAi")
  71.  
  72. --Create a custom "ai" 2 end
Advertisement
Add Comment
Please, Sign In to add comment