Jump to content

Welcome to Gaming On Steroids Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

How to: Script in GoS - Part 1/x


  • Please log in to reply
14 replies to this topic

#1
Inspired

Inspired

    Took the red pill.

  • Ex-Core Dev
  • PipPipPip
  • 723 posts
  • LocationWonderland
Guide #1 will explain what lua is and use basic examples to show basic lua stuff, therefore run in nearly any lua environment.
Guide #2 native lua libraries, optimizations, speed of different functions etc
Guides #3 - #x will use GoS api only and show a bit more advanced stuff
Guides #x - #y will use Inspired_new.lua api to actually show how to write a simple champion script

Guide #1:
The basics:

Lection #1:
GET ****ING SUBLIME TEXT
Setup.exe
x64 Setup.exe
license:
Spoiler


Lection #2:
Care: The following code is executed on https://repl.it/languages/lua
If you want it to work for GoS you either have to write
require("Inspired.lua")
or
print = PrintChat
at the top of your file

Since you actually want to store stuff you will have to use something called variables.
myVar1 = "Hello World!"
This code assigns the string "Hello World!" to the variable called myVar1

What can we do with those variables?
myVar1 = "Hello World!"
print(myVar1)
This will print out the assigned value to the variable!

But what if we only want to print something under a certain circumstance?
myVar1 = "Hello World!"
myVar2 = 3
if myVar2 == 3 then
    print(myVar1)
end
Conditions in lua have to go like this: "if .... then .... end"
If myVar2 is equals 3 (double = is a conditional check!) then we execute the print function!

As you saw above there is a function called print and we call it with parentheses
But how do we define our own functions?
myVar1 = "Hello!"
function MyFunction1()
    print(myVar1)
end
Now we defined a function! If we execute this... nothing happens, why? We did not call it yet!

But how do we call it?
myVar1 = "Hello!"
function MyFunction1()
    print(myVar1)
end
MyFunction1()
Now we called it and it printed myVar1!

But why are functions useful?
function MyFunction1(var)
    print(var * 3)
end
As you can see there is now something in the parentheses. This is a local variable that only exists in the function and can be used there!


But why are functions useful? #2
function MyFunction1(var)
    print(var * 3)
end
MyFunction1(1)
MyFunction1(2)
MyFunction1(3)
MyFunction1(4)
MyFunction1(5)
As you can see after executing it we used the same function with different variables to get a different outcome but did not have to write print( var * 3 ) every single time.

As you saw I just multiplied a number by 3, what other numeric operators does lua have?
a = 13
b = 2
print( a + b )
print( a - b )
print( a * b )
print( a / b )
print( a % b )
Wow so much math!

Let's quickly move on to something else... strings!
text1 = "Hello"
text2 = " "
text3 = "World"
Now we declared 3 text variables but we'd like to print them all at once

How we do that? We append them!
text1 = "Hello"
text2 = " "
text3 = "World"
print(text1 .. text2 .. text3 .. "!")
As you can see you can append variables containing strings together with other variables and strings with the .. operator

As we had previously we can make a condition under which we want to execute certain stuff, but how do we check if condition is not met?
a = 5
b = 10
if a == b then
    print("a is equal to b!")
else
    print("a is not equal to b!")
end
And how do we check if a variable is simply higher or lower than another?
a = 5
b = 10
if a ~= b then
    print("a is not equals b")
end
if a > b then
    print("a is bigger than b")
end
if a >= b then
    print("a is bigger or equals b")
end
if a <= b then
    print("a is smaller or equals b")
end
if a < b then
    print("a is smaller than b")
end
Now we have more conditional checks, yey!

But on certain conditions more than one gets print, what can we do?
a = 10
b = 5
if a < b then
    print("a is smaller than b")
elseif a == b then
    print("a is equals b")
elseif a > b then
    print("a is bigger than b")
end
Now only one of those cases will get printed!

Now how do we add a comment to our code so it is easier to understand lateron?
a = 10 -- a is now 10
b = 5 -- b is now 5
if a == b then -- check for a equals b
    print("a is b!") -- print
end
Wow so many comments! But too many is unreadable aswell..

But what if i want to store a lot of data? Like, a lot a lot? Fear not! Lua has exactly the concept you need!
myTable1 = {1, 6, 2, 8, 3, 4, 9} -- define a table
print(myTable1[3]) -- this will print the 3rd entry in my table -> 2
print(myTable1[7]) -- this will print the 7th entry in my table -> 9
print(myTable1[10]) -- this does not exist in the table and therefore will not print anything!
But what if i want to index the table for something else?
myTable1 = { myIndex1 = "Hello!", myIndex2 = 1, myIndex3 = 42 }
print(myTable1.myIndex1)
print(myTable1.myIndex2)
print(myTable1.myIndex3)
Can i store functions in tables? Of course! Can i save anything in tables? OF COURSE!
myTable1 = { function1 = function() print("hi!") end, table1 = { 1, 2, 3}, string1 = "HHello!", number1 = 57 }
print(myTable1.function1())
print(myTable1.table1[1])
print(myTable1.table1[2])
print(myTable1.table1[3])
print(myTable1.string1)
print(myTable1.number1)
But.. How do i automate this?

You can iterate over tables!
myTable1 = { 1, 5, 2, 3, 8, 7, 5, 1, 4, 2, 3, 5, 7, 9 }
for key = 1, #myTable1 do -- #myTable1 returns table length
    value = myTable1[key]
    print("Entry: "..key.." holds Value: "..value)
end
for key, value in ipairs(myTable1) do -- sorted
    print("Entry: "..key.." holds Value: "..value)
end
for key, value in pairs(myTable1) do -- unsorted, faster
    print("Entry: "..key.." holds Value: "..value)
end
What other lua functions are there?
assert(condtition, message) -- will print the message if condition is not met and end execution

error(message) -- will print the message and end execution

require(path) -- will load the lua file located at specified path
Lesson #3:
Native lua libraries:
-> math
math.abs(number) -- returns absolute value of a number

math.acos(number) -- arc cosine of x (radians)

math.asin(number) -- arc sine of x (radians)

math.cos(number) -- cosine of x (radians)

math.sin(number) -- sine of x (radians)

math.atan(number) -- arc tan of x (radians)

math.tan(number) -- tan of x (radians)

math.ceil(number) -- rounds number up

math.floor(number) -- rounds number down

math.deg(number) -- converts angle x from radians to degree

math.rad(number) -- converts angle x from degree to radians 

math.exp(number) -- e ^ number

math.huge -- biggest number ever

math.pi -- pi.. longest number ever?

math.max(number1, number2) -- the one that is bigger number1 or number2

math.min(number1, number2) -- the one that is smaller number1 or number2

math.maxinteger -- max integer value

math.mininteger -- min integer value

math.random() -- random number between 0 and 1

math.random(num1) -- random number between 1 and num1

math.random(num1, num2) -- random number between num1 and num2

math.sqrt(num1) -- square root of num1
-> string
string.byte(string) -- returns number of the string

string.char (num1) -- returns string of a number

string.len(string) -- returns string length

string.lower(string) -- returns the given string but in lowercase

string.upper(string) -- returns the given string but in uppercase

string.reverse(string) -- returns the given string but reversed

string.find(string, searchpattern) -- searches a pattern in a givens tring and returns its position or nothing

string.sub(string, number) -- returns a sub string
Continue?
  • 6

#2
aizjg

aizjg

    GoS's Firefighter

  • Banned
  • PipPipPip
  • 325 posts
  • Locationfire dep 24/7 Kappa

oh nice to know XD


  • 0

#3
Noddy

Noddy

    Surrender The Throne

  • Scripts Developer
  • 496 posts

:spacebar: Kappa


  • 0

#4
Hanndel

Hanndel

    The Developerino

  • Contributor
  • 602 posts
:fappa:
  • 0

#5
Zwei

Zwei

    Advanced Member

  • Contributor
  • 2,201 posts
Wow such script Doge
  • 0

#6
ilovesona

ilovesona

    Sona's wife

  • Contributor
  • 1,096 posts

nice post farm Kappa


  • 0

#7
Rekt

Rekt

    Advanced Member

  • Members
  • 88 posts
  • LocationSky

KappaClaus


  • 0

#8
Deftsu

Deftsu

    AFK

  • Contributor
  • 4,806 posts
post farm confirmed Kappa
  • 0

#9
Hanndel

Hanndel

    The Developerino

  • Contributor
  • 602 posts

post farm confirmed Kappa


Rly? Kappa
  • 0

#10
Imstuckinhell

Imstuckinhell

    l o a d s e m o n e

  • +VIP
  • 829 posts

Rly? Kappa

no Kappa but it's good to know were getting a guide from inspired tho Kappa


  • 0

#11
Inspired

Inspired

    Took the red pill.

  • Ex-Core Dev
  • PipPipPip
  • 723 posts
  • LocationWonderland
Updated this btw :fappa:
  • 0

#12
aaronses

aaronses

    Member

  • Members
  • 15 posts

Thank you, really


  • 0

#13
Ryzuki

Ryzuki

    Advanced Member

  • Contributor
  • 297 posts
  • LocationOsu!z

Nah, i want to press upvote button but... :fappa: how to revote :dogecry:


  • 0

#14
Zwei

Zwei

    Advanced Member

  • Contributor
  • 2,201 posts

Nah, i want to press upvote button but... :fappa: how to revote :dogecry:


PogChamp Hater!
  • 0

#15
xAmaGeddoNx

xAmaGeddoNx

    Newbie

  • Members
  • 7 posts
  • Locationkurrwa

Nice


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users