Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- betterAi = {};
- betterAi.objectCatch = {};
- betterAi.classes = {};
- betterAi.altClassMap = {
- --For spesific odf i.e:
- --avtank = "aTankAi"
- }
- betterAi.objectClassMap = {
- turretTank = "turrAi",
- turret = "turrAi"
- }
- betterAi.setCustomAi = function(odf,aiName)
- betterAi.altClassMap[odf] = aiName;
- end
- betterAi.setCustomAiForType = function(classLabel,aiName)
- betterAi.objectClassMap[classLabel] = aiName;
- end
- betterAi.createCustomAi = function(name)
- betterAi.classes[name] = betterAi.classes.extend(betterAi.classes.gameObject);
- return betterAi.classes[name].prototype;
- end
- betterAi.Update = function(dTime)
- for i,v in pairs(betterAi.objectCatch) do
- v:update(dTime);
- end
- end
- betterAi.DeleteObject = function(h)
- if(betterAi.objectCatch[h]) then
- betterAi.objectCatch[h]:destroy();
- betterAi.objectCatch[h] = nil;
- end
- end
- betterAi.AddObject = function(h)
- local odf = GetOdf(h);
- local objClass = GetClassLabel(h);
- odf = odf:sub(1,6);
- if(betterAi.classes[odf]) then
- betterAi.objectCatch[h] = betterAi.classes[odf](h);
- elseif(betterAi.altClassMap[odf]) then
- betterAi.objectCatch[h] = betterAi.classes[betterAi.altClassMap[odf]](h);
- elseif(betterAi.objectClassMap[objClass]) then
- betterAi.objectCatch[h] = betterAi.classes[betterAi.objectClassMap[objClass]](h);
- end
- end
- betterAi.classes.extend = function(base)
- local child = {};
- child.prototype = {super = base};
- if base then
- setmetatable(child.prototype,{__index = base.prototype});
- else
- child.prototype.new = function(self,...)
- local nInst = setmetatable({},self.mt);
- nInst:init(...);
- return nInst;
- end
- end
- child.mt = {__index = child.prototype};
- setmetatable(child,{__index = child.prototype,__call = child.prototype.new});
- return child;
- end
- betterAi.classes.gameObject = {};
- betterAi.classes.gameObject.prototype = {
- new = function(self,...)
- local nInst = setmetatable({},self.mt);
- nInst:init(...);
- return nInst;
- end,
- init = function(self,handle)
- print(self);
- self.handle = handle;
- self.odf = GetOdf(handle);
- self.label = GetLabel(handle);
- end,
- update = function(self,dTime)
- --"virtual" function
- end,
- destroy = function(self)
- --"virtual" function
- end
- };
- betterAi.classes.gameObject.mt = {
- __index = betterAi.classes.gameObject.prototype;
- }
- setmetatable(betterAi.classes.gameObject,{
- __index = betterAi.classes.gameObject.prototype,
- __call = betterAi.classes.gameObject.prototype.new
- });
- betterAi.classes.turrAi = betterAi.classes.extend(betterAi.classes.gameObject);
- betterAi.classes.turrAi.prototype.init = function(self,...)
- self.super.init(self,...);
- self.target = nil;
- self.lastTimeShot = 0;
- self.hasWaited = false;
- self.ignoreShot = false;
- end
- betterAi.classes.turrAi.prototype.update = function(self,dTime)
- self.lastTimeShot = GetTime() - GetLastEnemyShot(self.handle);
- if(self.lastTimeShot > 5) then
- self.hasWaited = true;
- end
- self.ignoreShot = self.lastTimeShot > 15;
- if(self.lastTimeShot < 1 and self.hasWaited and GetWhoShotMe(self.handle) ~= self.target) then
- self.target = GetWhoShotMe(self.handle);
- self.hasWaited = false;
- Attack(self.handle,self.target);
- end
- if(self.ignoreShot and self.target ~= GetNearestEnemy(self.handle)) then
- self.target = GetNearestEnemy(self.handle);
- Attack(self.handle,self.target);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment