Basic Lua Knowledge

agonic
VIP
Posts: 159
Joined: Tue Jan 10, 2017 6:39 pm
Has thanked: 34 times
Been thanked: 112 times

Basic Lua Knowledge

Post by agonic » Fri Jan 13, 2017 8:58 pm

********************* PLS CHECK AND FIX/EDIT ENGRISSHHHH**********

Basic lua knowledge;

-Ofcourse, It is a programming language.
-File association is *.lua
-Lua files contain scripts in aionscript folder and that scripts must be written by someone.
-Similar to basic english mixed math. (My opinion)
-Class scripts must be written by someone. Never falls from sky.
-Better editing tool is Notepad++. https://notepad-plus-plus.org/

Some explanations about terms in the scripts;
-Entity is your target. It can be enemy or friendly, who is targeted by you, even yourself too. Player is, ofc, you.
-State,as simply, is your buffs, debuffs. You can check your and entity's state(s).

Code: Select all

Player/Entity:GetState():GetState("State's name")
or

Code: Select all

Player/Entity:GetState():GetState(State ID, as number ofc)
- "~= nil" means is exist. "== nill" means is not exist. For example,

Code: Select all

Player/Entity:GetState():GetState(8224) ~= nill/== nill
.
-"local" is using for an abbreviation for some similar situations or juts using as an abbreviation. For example;

Code: Select all

local EntityState = Entity:GetState();
local Posion = EntityState:GetState( "Venomous Strike" ) ~= nil or EntityState:GetState( "Massacre" ) ~= nil
-Basic writing template of skill is like;

Code: Select all

if Helper:CheckAvailable("Skill name like in game") then
	Helper:CheckExecute( "Skill name like in game" );
end
-You can use abbreviations like;

Code: Select all

if Poison and Helper:CheckAvailable("Skill name like in game") then
	Helper:CheckExecute( "Skill name like in game" );
end
-Script files contain some "function"s to run some situations. For example;
function Attack() is your main attack routine funciton. function Pause() is doing somethings, when you are not busy. You can add your own functions into the script.
-Functions is written like;

Code: Select all

function Desired name(Desired situations like Stunned, Range, Entity, EntityState)
	your lines
end
-How to add your functions into Attack funcion ?

Code: Select all

self:Desired name(Desired situations like Stunned, Range, Entity, EntityState);
Or

Code: Select all

local desired abbreviation = self:Desired name(Desired situations like Stunned, Range, Entity, EntityState);

-Some examples;

Code: Select all

local Entity = EntityList:GetEntity( Player:GetTargetID());
local EntityState = Entity:GetState();
local Range = Player:GetPosition():DistanceToPosition( Entity:GetPosition());
Entity:GetClass():ToString() == "Assassin, Gladiator, Chanter..."
Entity:GetName() == "Stormwing"
Player:GetHealthCurrent() < Player:GetHealthMaximum() == / <= / >= 2500

Code: Select all

function GetBuff()

	-- Loop through the state of the target entity 
	for i = 0, Player:GetState():GetStateSize() - 1, 1 do
				
	-- Retrieve the state from the EntityState.
	local StateIndex = Player:GetState():GetStateIndex( i );

	-- Check if the state is correct and check if it is a debuff.
		if StateIndex ~= nil and StateIndex:IsDebuff() then		
			return true;			
		end
					
	end
				
end

Code: Select all

if self:GetBuff() then
	if Helper:CheckAvailableInventory( "Greater Healing Potion" ) then
		PlayerInput:Inventory( "Greater Healing Potion" );
		return false;
	end
end
I can add more examples..

User avatar
0x00
VIP
Posts: 105
Joined: Tue Jan 10, 2017 11:40 pm
Has thanked: 10 times
Been thanked: 23 times

Re: Basic Lua Knowledge

Post by 0x00 » Wed Feb 15, 2017 2:06 am

I really love your dedication! Nice job, keep it up!

agonic
VIP
Posts: 159
Joined: Tue Jan 10, 2017 6:39 pm
Has thanked: 34 times
Been thanked: 112 times

Re: Basic Lua Knowledge

Post by agonic » Wed Feb 15, 2017 2:27 pm

0x00 wrote:
Wed Feb 15, 2017 2:06 am
I really love your dedication! Nice job, keep it up!
Thank youuu :DD

crazymonkey84
Posts: 37
Joined: Sun Jan 29, 2017 4:33 am
Has thanked: 6 times
Been thanked: 3 times

Re: Basic Lua Knowledge

Post by crazymonkey84 » Tue Feb 28, 2017 8:31 am

thank you agoinc

Im a visual studio developer, i have created some small applications for the company i work for. and I´d like to spend some free time creating good scripts to share with the community (as i have no social life at all ahahahahaha)


let me get this straigth:

player= our char
entity = our target
state = buff/debuff
"~= nil" = entity/player exists
"== nill"= entity/player doesnt exist

"local" = abbreviation for similar situations.... (didn´t get it). Can you please explain it in a more detailed way ?

---------------------------------------


What about "helper"?? Who´s the helper? how does it work? i think i understand it refers to the AS itself but i just dont know for sure

---------------------------------------

"Function", works like this??:

self:desired name (stunned)
helper:checkexecute("Remove shock")
end

--------------------------------------------------------------------------------------------------------------------------------------------------

local Entity = EntityList:GetEntity( Player:GetTargetID()); <----(are we getting the ID number from the target so we can program some actions according to the mob/player/npc we have selected?)

local EntityState = Entity:GetState(); <----(are we getting the buff/debuff state of our target so we can program a good reaction depending on the target state?)

local Range = Player:GetPosition():DistanceToPosition( Entity:GetPosition()); <---(are we getting the distance our target is from us?)

Entity:GetClass():ToString() == "Assassin, Gladiator, Chanter..." <---( easy to understand, it gets the target class, so we can program some reaction according to buffs or skills our opponent could use)

Entity:GetName() == "Stormwing" <---(it got the name of the target)

Player:GetHealthCurrent() < Player:GetHealthMaximum() == / <= / >= 2500 <-(in here we are telling the script to heal us when our maximim health is ??? less or equals, major or equals to 2500??

-----------------------------------------------------------------

At this moment all i have done was to open a TeMPLAR.lua and changed the Skills names in a notepad, since it had the very old ones. i made it work anyway.

Im going to start to read the luas i already have to start to understand in a better way every command/function.

as 0x00 said in another post, we were all noob at the begining we have to learn, i will try to learn about offsets too.

Thank you in advance for ur support.

Regards

Online
User avatar
nucular
Site Admin
Posts: 260
Joined: Sat Jan 07, 2017 9:08 pm
Has thanked: 27 times
Been thanked: 388 times

Re: Basic Lua Knowledge

Post by nucular » Tue Feb 28, 2017 11:08 am

crazymonkey84 wrote:
Tue Feb 28, 2017 8:31 am
thank you agoinc

Im a visual studio developer, i have created some small applications for the company i work for. and I´d like to spend some free time creating good scripts to share with the community (as i have no social life at all ahahahahaha)


let me get this straigth:

player= our char
entity = our target
state = buff/debuff
"~= nil" = entity/player exists
"== nill"= entity/player doesnt exist

"local" = abbreviation for similar situations.... (didn´t get it). Can you please explain it in a more detailed way ?

---------------------------------------


What about "helper"?? Who´s the helper? how does it work? i think i understand it refers to the AS itself but i just dont know for sure

---------------------------------------

"Function", works like this??:

self:desired name (stunned)
helper:checkexecute("Remove shock")
end

--------------------------------------------------------------------------------------------------------------------------------------------------

local Entity = EntityList:GetEntity( Player:GetTargetID()); <----(are we getting the ID number from the target so we can program some actions according to the mob/player/npc we have selected?)

local EntityState = Entity:GetState(); <----(are we getting the buff/debuff state of our target so we can program a good reaction depending on the target state?)

local Range = Player:GetPosition():DistanceToPosition( Entity:GetPosition()); <---(are we getting the distance our target is from us?)

Entity:GetClass():ToString() == "Assassin, Gladiator, Chanter..." <---( easy to understand, it gets the target class, so we can program some reaction according to buffs or skills our opponent could use)

Entity:GetName() == "Stormwing" <---(it got the name of the target)

Player:GetHealthCurrent() < Player:GetHealthMaximum() == / <= / >= 2500 <-(in here we are telling the script to heal us when our maximim health is ??? less or equals, major or equals to 2500??

-----------------------------------------------------------------

At this moment all i have done was to open a TeMPLAR.lua and changed the Skills names in a notepad, since it had the very old ones. i made it work anyway.

Im going to start to read the luas i already have to start to understand in a better way every command/function.

as 0x00 said in another post, we were all noob at the begining we have to learn, i will try to learn about offsets too.

Thank you in advance for ur support.

Regards
Hi crazymonkey, just look inside AionScript Folder and open AionScript.pdf .
It will show you all supported functions and variables.

As an example maybe to understand how everything works just create inside Scripting Folder lua files like that.

GellAllBuffStateIds.lua (Shows you all Buffs you have currently up)

Code: Select all

function OnLoad
	for ID, BuffSkill in DictionaryOperator ( Player:GetState():GetList() ) do
		Write (ID .. " " .. BuffSkill:GetName() );
	end
end
GellAllAbilites.lua (Shows you all Abilities available)

Code: Select all

function OnLoad
	for ID, Skill in DictionaryOperator ( AbilityList:GetList() ) do
		Write (ID .. " " .. Skill:GetName() .. " Cooldown " .. Skill:GetCooldown() );
	end
end
The Player object is static and is always availabe.
Inside the classes lua Attack function "Entity" is the current selected target your bot want's to kill.

Code: Select all

function Attack (Entity)
 ...
 << Your attack code for the entity >>
 ...
end
local means the variable only exists inside the function. https://www.lua.org/pil/4.2.html
Helper functions are defined inside Scripting/OfficialGrinderFramework/HelperFunction.lua

crazymonkey84
Posts: 37
Joined: Sun Jan 29, 2017 4:33 am
Has thanked: 6 times
Been thanked: 3 times

Re: Basic Lua Knowledge

Post by crazymonkey84 » Wed Mar 01, 2017 5:16 am

oh tyvm 4 the explanantion, i started to put all pieces together.

i think soon ill be sharing some good scripts

again thank u very much

locatelli
VIP
Posts: 71
Joined: Mon Jan 16, 2017 10:38 pm
Has thanked: 11 times
Been thanked: 8 times

Re: Basic Lua Knowledge

Post by locatelli » Tue Mar 21, 2017 10:13 pm

I'm looking for a really deep lua guide, where I can learn all the returns calls and other advanced commands like string search and so on, if anyone can find a decent one - didn't find one yet sadly - feel free to write me

agonic
VIP
Posts: 159
Joined: Tue Jan 10, 2017 6:39 pm
Has thanked: 34 times
Been thanked: 112 times

Re: Basic Lua Knowledge

Post by agonic » Wed Mar 22, 2017 4:27 pm


izanami
Posts: 7
Joined: Thu Feb 16, 2017 9:23 am
Has thanked: 1 time

Re: Basic Lua Knowledge

Post by izanami » Fri Mar 31, 2017 3:32 pm

Hi all, i have a little question, how i can obtain and write into console the list of item inside the inventory?

I'm tring this but id does not work

Code: Select all

local InventoryLst = InventoryList:GetList();
for i, Inventory in InventoryLst do
  Write(Inventory:GetName() .. " || " .. Inventory:GetAmount());
end
i get this error:
attempt to call a userdata value

Can someone hel me a bit with this list?
if i have write this in an wrong section say me^^

agonic
VIP
Posts: 159
Joined: Tue Jan 10, 2017 6:39 pm
Has thanked: 34 times
Been thanked: 112 times

Re: Basic Lua Knowledge

Post by agonic » Fri Mar 31, 2017 5:22 pm

izanami wrote:
Fri Mar 31, 2017 3:32 pm
Hi all, i have a little question, how i can obtain and write into console the list of item inside the inventory?

I'm tring this but id does not work

Code: Select all

local InventoryLst = InventoryList:GetList();
for i, Inventory in InventoryLst do
  Write(Inventory:GetName() .. " || " .. Inventory:GetAmount());
end
i get this error:
attempt to call a userdata value

Can someone hel me a bit with this list?
if i have write this in an wrong section say me^^

Code: Select all

function OnLoad()
    for Item in ListIterator( InventoryList:GetList() ) do
        Write(""..Item:GetName().."  "..Item:GetAmount())
    end
end

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest