1. Learn lua first
- how-to-script-in-gos-part-1x
- Google: local variable, performance, reference type in lua
2. Some tips
a) Use local variables if could.
local pi = math.pi -- then just use var pi, don't need to access _G.math.pi next time --------------------------------------------------------- OnTick(function() a() end) function a() -- do smth end ----- Chage to ----- local function a() -- do smth end OnTick(function() a() end)
b.) Don't re-creates somethings that can be create 1time
Ex: https://github.com/Fret13103/Gaming-On-Steroids/blob/master/InsidiousTwitch.lua#L288-L294 ------- function DrawCircleMinimap(origin, radius, color) local MapData = { [SUMMONERS_RIFT] = {min = {x = -120, z = -120}, max = {x = 14870, z = 14980}}, [TWISTED_TREELINE] = {min = {x = 0, z = 0}, max = {x = 15398, z = 15398}}, [CRYSTAL_SCAR] = {min = {x = 0, z = 0}, max = {x = 13987, z = 13987}}, [HOWLING_ABYSS] = {min = {x = -28, z = -19}, max = {x = 12849, z = 12858}}, } .... end Do you think you can get a litte memory because MapData will be deleted after end func although the loop will create that var again like 30 times each second? Also you will need time for creating variable before doing anything else, if too much smth like that, your prog might be slow/lag. ----- Chage to ----- local MapData = { [SUMMONERS_RIFT] = {min = {x = -120, z = -120}, max = {x = 14870, z = 14980}}, [TWISTED_TREELINE] = {min = {x = 0, z = 0}, max = {x = 15398, z = 15398}}, [CRYSTAL_SCAR] = {min = {x = 0, z = 0}, max = {x = 13987, z = 13987}}, [HOWLING_ABYSS] = {min = {x = -28, z = -19}, max = {x = 12849, z = 12858}}, } local function DrawCircleMinimap(origin, radius, color) .... end
c) Tablezzz .-.
if you just want to insert element at the end of table, use: t[#t+1] = val instead of table.insert(t, val); -- why? google .-. Loop through a table like this: local table = {1, 2, 3, "zdfdf", 34, 17, function() end} use: for key = 1, #table, 1 do local value = table[key] -- dosmth end other case: local table = { 1, 2, [1012314] = 5, -- [unit.networkID]? ['z'] = 27, ["abc"] = 21 } for key, value in pairs(table) do -- do smth end -- Look like minionManger.objects? then use case1 ----------- Why? google: performance lua, for loop lua .-. -----------
d) Reference in lua
local function UpdateColor(tbl) tbl[1] = tbl[1] +1; return tbl; -- useless end local table1 = {254, 255, 255}; table1 = UpdateColor(table1); -- also need a litte time for operator'=' ----- Change to ----- local function UpdateColor(tbl) tbl[1] = tbl[1] +1; end local table1 = {254, 255, 255}; UpdateColor(table1); -------------------------------- Some examples (this one is for multi pred support, some spells need update range each level) class "AddSpell" function AddSpell:__init(spellData --[[table]]) .... end local spellData = {delay = 250, speed = math.huge, width = 100, range = myHero:GetSpellData(_Q).range, slot = _Q}; local spell = AddSpell(spellData); OnTick(function() spellData.range = myHero:GetSpellData(_Q).range; spell:Cast(target) end) ------- If you didn't know about reference, u maybe write smth like this: function AddSpell:UpdateRange(value) self.range = value end OnTick(function() spellData.range = myHero:GetSpellData(_Q).range; spell:UpdateRange(spellData.range) -- or spell.range = spellData.range spell:Cast(target) end) Look so hard and useless .-.
e) Some codes need change .-.
https://github.com/UnchainedScripts/GoS/blob/master/KhazixUnchained.lua#L221-L261 ------------------------------------------- function GetEnemyHeroes() for i = 1, Game.HeroCount() do -- loop again when call func although just need 1 loop to get enemies list? .-. ... end Same as for function GetAllyHeroes() since it's Game.HeroCount(), you can get both enemies and allies. Write the loop just 1time with Callback.Add("Load") .-. ------------------------------------------- function Utility:GetBuffs(unit) self.T = {} for i = 0, unit.buffCount do local Buff = unit:GetBuff(i) if Buff.count > 0 then table.insert(self.T, Buff) end end return self.T end function Utility:HasBuff(unit, buffname) for K, Buff in pairs(self:GetBuffs(unit)) do -- self:GetBuffs(unit): table{buff1, buff2,...} should use for i = 1, n do but this func still useless .-. if Buff.name:lower() == buffname:lower() then return true end end return false end ----- Chage to ----- local function Utility:HasBuff(unit, buffname) for i = 0, unit.buffCount, 1 do local buff = unit:GetBuff(i) if buff.count > 0 and buff.name == buffname then return true end end return false end ------------------------------------------- https://github.com/Fret13103/Gaming-On-Steroids/blob/master/InsidiousVarus.lua#L527-L553 let's consider we had 40 minions at current time (20 enemies, 20 allies) and 5 minions inside QRange, ERange first: loop 1 -> 40, then at 5 minions inside QRange, loop 1 -> 40 again => 40 + 40*5 = 240 (not add CountObjectsOnLineSegment) same as his laneclearE => 240*2 = 480 .-. so now we should do like this: https://hastebin.com/rafigifice.lua First loop: 40 QLoop: 5 + 5*5 == 30 ELoop: 5 + 5*5 == 30 => 100 Also some scripts write too much functions/variables and didn't use it .-. u should delete some vars/funcs that never used .-.
3. More tips .-.
a) LoL Wiki
b) Calc damage
Ex Lucian's QDmg : 80 / 115 / 150 / 185 / 220 (+ 60 / 70 / 80 / 90 / 100% bonus AD) => 45+35*myHero:GetSpellData(_Q).level + (0.5 + 0.1*myHero:GetSpellData(_Q).level)*myHero.totalDamage -- because "%" | myHero.totalDamage: current AD dmg Then how can i calc it: 45+35*myHero:GetSpellData(_Q).level? -- Choose 3 nearest level (1/2/3, 2/3/4, 3/4/5) -- I'll use 1/2/3 -- subtract: dmglv3 - dmglv2 = 35 -- subtract: dmglv1 - 35 = 45 => 45+35*myHero:GetSpellData(_Q).level -- Check again if at lv1, 2, 3, 4, 5 == Lucian's QDmg then ok -- If wrong then you must use ({dmglv1, dmglv2, dmglv3,...})[myHero:GetSpellData(_Q).level] because u can get the formula for this spell's dmg ---------- Lv 2/3/4 and 3/4/5 should give the same formula ---------- Ex2: Varus's maxQDmg: 15 / 70 / 125 / 180 / 235 (+ 150% AD) -- subtract: dmglv3 - dmglv2 = 55 -- subtract: dmglv1 - 55 = -40 => -40+55*myHero:GetSpellData(_Q).level + 1.5*myHero.totalDamage --------------------------------------------------------------------------------------- Ex3: Shyvana's WDmg per sec: 20 / 32 / 45 / 57 / 70 (+ 20% bonus AD) (+ 10% AP) => 7+13*myHero:GetSpellData(_Q).level --[[ -> {20, 33, 46, 59, 72} ]] => wrong So you must use this: ({20, 32, 45, 57, 70})[myHero:GetSpellData(_Q).level] + 0.2*myHero.totalDamage + 0.1*myHero.ap --------------------------------------------------------------------------------------- You still can alway use: ({dmglv1, dmglv2, dmglv3,...})[myHero:GetSpellData(_Q).level] .-.
c) .-.
class "abc" same as: class("abc") local tbl = Set {"KogMaw", "Annie"} same as: local tbl = Set({"KogMaw", "Annie"}) class/Set: functions print('Hello "World"') --> Hello "World" print("Hello 'World!'") --> Hello 'World!' print("Hello \"World!\"") --> Hello "World!"
d) Your tips here
first time at gos? take a look at Education Annie and join our discord
Please comment if you found any mistake.
Exam is just for example, not to complain anyone.