×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [e-Book] Lua Programming Language
1 / 2 › »
[e-Book] Lua Programming Language
Benbirkralm
« Citoyen »
1390670580000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#1
  0
[e-Book] Lua Programming Language

Hello Friends! I am Benbirkralm, Today I will show my new e-Book to you.

In this book;
₪ Make a Simple Game,
₪ Create a Button,
₪ Use Handler,
₪ [DELETED for faults](SPECIAL)Make a Database ...


Part 1 Make a Simple Game
We settle down to Lua. We know few codes. But we don't know hot to use this... Let's make simple gzme
Example, if the player get cheese, his/her mouse will be die.

a dit :
function eventPlayerGetCheese(isim) --- Function, If Player Get Cheese;
tfm.exec.killPlayer(isim) --- Kill him.
end --- End.

Now, Run this code in /lua. If we get cheese, we will die.If anyone gets cheese, he/she will die.
Now, print a code to show;"This game is working."
a dit :
tfm.exec.chatMessage("Working! :)",nil) --- Show 'Working! :)' text to everyone in chatbox.

We can't use this code in tribehouses... So you can use 'print'. But only activator can see 'print'.
a dit :
print("Working! :)") --- Show 'Working' text to activator.

We can use these text in same time.
Now, Let's create help command. First, show 'We have help command...' to everyone.
a dit :
tfm.exec.chatMessage(" You can learn more with this command, !help<ROSE> .",nil)

Now, create a command :
a dit :
function eventChatCommand(name command) --- Function of chat Command.
if command == "help" then --- If command is, 'help',
tfm.exec.chatMessage("Help: If you get cheese, you will die..", name) --- Chat Command to writer.
end --- End
end --- End


This is Okay, too. Our game is close on completed. We haven't got only 'maps' parameter and function for newPlayer.
Now, Let's make maps table.
Making a 'maps' Table. After connects with 'math.random'
a dit :
maps={mapCode1, mapCode2}
tfm.exec.newGame(maps[math.random(#maps)])

And, function of newPlayer...
a dit :

function eventNewPlayer(name) --- Function for New Player
tfm.exec.chatMessage("Welcome to the our game! Want to help? Type !help", name) --- Text for New Player.
end --- End

Part Completed...


Part 2 Making a Button
We will use textArea to make button.
ui.zaddTextArea(1,"Thix is my button!",nil,80,80,80,80)[/quote]
Now, Let's Update this. Example, Ask a question. And answer it.
a dit :
ui.addPopup(5,2,"Do you like this game?",nil)

function popupAnswer(id, answer)
if id == 5 then
if answer == 'no' then
ui.addTextArea(5,"Why? -,-", name)
tfm.exec.killPlayer(name)
else
ui.addTextArea(5, "Thank you! :)", name)
tfm.exec.giveCheese(name)
end
end
end

Part 3 Making Handler

We making game. Now we must add admins/autocrats. We must add 'admins' code in first area....
a dit :
admins={admin1=true, admin2=true}

Now we must add code.
a dit :
function isAdmin(name)
return (admins[name] or false)
end

function eventChatCommand(player, message)
local args = string.split(message, "%s")
local text = table.remove(args, 1)
command.handle(string.lower(text), player, args)
end
command = {handlers = {}}
function command.addHandler(text, handler)
if command.handlers[text] == nil then
command.handlers[text] = {}
end
table.insert(command.handlers[text], handler)
end

function command.removeHandler(text, handler)
if command.handlers[text] ~= nil then
local index
for i, h in ipairs(command.handlers[text]) do
if handler == h then
index = i
end
end
if index ~= nil then
table.remove(command.handlers[text], index)
if #command.handlers[text] == 0 then
command.handlers[text] = nil
end
end
end
end
function command.handle(text, player, args)
if command.handlers[text] ~= nil then
for i, handler in ipairs(command.handlers[text]) do
handler(player, unpack(args))
end
end
end
function string.split(str, s)
local res = {};
for part in string.gmatch(str, "[^" .. s .. "]+") do
table.insert(res, part)
end
return res;
end
function unpack (t, i)
i = i or 1
if t ~= nil then
return t, unpack(t, i + 1)
end
end
main();


Now, add a any code.
a dit :
function main()
command.addHandler("map",mapCodd)
end

We are creating a new function with this handler/code
a dit :
function mapCodd(player, map)
if player.is(admins) then --- If player is in table of 'admins',
tfm.exec.newGame(map) --- Open new map.
end
end

Using with !map
1
2
3
4
5
6
.


[color=#FFD300] Book is finished. Thanks to every readers!
Writed by Benbirkralm in 07-01-2014 to 11-01-2014 for with phone/notebook/computer for TR Server. Translated for EN Server in 24-01-2014 to 25-01-2014 by Benbirkralm~~
###Benbirkralm###[/color]
Benbirkralm
« Citoyen »
1390677840000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  0
Your Questions and Answers :
Ulllyyyy
« Citoyen »
1390678500000
    • Ulllyyyy#0000
    • Profil
    • Derniers messages
    • Tribu
#3
  0
Benbirkralm a dit :
Your Questions and Answers :

Just asking do you know lua
Benbirkralm
« Citoyen »
1390678620000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  0
Ulllyyyy a dit :
Just asking do you know lua

Yes, I Know.
Safwanrockz
« Censeur »
1390679520000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#5
  0
Sorry but your tutorial has got some grammar and spelling mistakes and isn't very descriptive. Even though, good job.
Benbirkralm
« Citoyen »
1390680060000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#6
  0
Safwanrockz a dit :
Sorry but your tutorial has got some grammar and spelling mistakes and isn't very descriptive. Even though, good job.

Thanks, I Know it has some mistakes. I Will fix this in e-Book2.
Mikuhl
« Citoyen »
1390777680000
    • Mikuhl#3311
    • Profil
    • Derniers messages
    • Tribu
#7
  0
Some of your code looks quite like Moepls framework code.

Benbirkralm a dit :

function string.split(str, s)
local res = {};
for part in string.gmatch(str, "[^" .. s .. "]+") do
table.insert(res, part)
end
return res;
end

Moepl a dit :

function string.split(input, seperator)
seperator = seperator or " "
local res = {}
for part in string.gmatch(input, "[^" .. seperator .. "]+") do
table.insert(res, part)
end
return res
end

-

Benbirkralm a dit :

function unpack (t, i)
i = i or 1
if t ~= nil then
return t, unpack(t, i + 1)
end
end

Moepl a dit :

function moepl.unpack(a, i, m)
i = i or 1
if (m ~= nil and i <= m) or (not m) then
if a ~= nil then
return a, moepl.unpack(a, i + 1, m)
end
end
end

Its not a good idea to copy.
Moepl
« Citoyen »
1390782540000
    • Moepl#0095
    • Profil
    • Derniers messages
#8
  0
oh, don't be too harsh :S
Those are pretty standard functions that one can often find in lua tutorials in similiar if not in the exact same forms. Personally, I learned lua by going through the official lua documentation and actually copied the unpack function as described there http://www.lua.org/pil/5.1.html
(merely changed it a bit to better suit my needs)
Anyway, I uploaded my code so people can use it (and copy it). There are actually a couple of things in there from the official docu or from lua-users.org.
Mikuhl
« Citoyen »
1390783080000
    • Mikuhl#3311
    • Profil
    • Derniers messages
    • Tribu
#9
  0
Moepl a dit :

Still isnt the best idea to directly cut and paste and just change letters and call it your own. :/
Especially if you dont understand what your copying, judging by "now you must add code."

It still looks like he did most of it by himself so atleast there is that.
Moepl
« Citoyen »
1390783860000
    • Moepl#0095
    • Profil
    • Derniers messages
#10
  0
Yes, I agree with you.
This guide could use some more ~words~. Right now it feels a bit like another function library/snippets thread. Especially part3 which I don't think is helpful for a beginner.

note: split, trim, unpack, execption handlers, etc are functions that are so basic that they are so often in tutorials. I don't think that anyone can claim ownership of it :)
Benbirkralm
« Citoyen »
1390835700000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#11
  0
Jaackster a dit :
Some of your code looks quite like Moepls framework code.


-


Its not a good idea to copy.

I don't make copy. It is simple codes?
Evilsantah
« Citoyen »
1390836600000
    • Evilsantah#0000
    • Profil
    • Derniers messages
#12
  0
Also the command handler is written by Makinit, atleast add the appropriate credits for everything you got elsewhere :)

Nevertheless, nice effort.

E:
Benbirkralm a dit :

player.is(admins)

I don't see any player.is(table) defined, nor string:is(table), both not fitting the code and your desired result either way.
You can just use
Evilsantah a dit :

if admins[player] then

~
Benbirkralm
« Citoyen »
1390837320000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#13
  0
Evilsantah a dit :
Also the command handler is written by Makinit, atleast add the appropriate credits for everything you got elsewhere :)

Nevertheless, nice effort.

E:
I don't see any player.is(table) defined, nor string:is(table), both not fitting the code and your desired result either way.
You can just use

~

a dit :
function isAdmin(name)
return (admins[name] or false)
end

?
Benbirkralm
« Citoyen »
1391180880000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#14
  0
Updated!
Benbirkralm
« Citoyen »
1393012320000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#15
  0
Updated and fixed some things.
Rebornaddict
« Citoyen »
1393073100000
    • Rebornaddict#0000
    • Profil
    • Derniers messages
#16
  0
OMG THANK YOU SO MUCH!
Benbirkralm
« Citoyen »
1393153140000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#17
  0
Rebornaddict a dit :
OMG THANK YOU SO MUCH!

You're Welcome :)
Rebornaddict
« Citoyen »
1393158780000
    • Rebornaddict#0000
    • Profil
    • Derniers messages
#18
  0
what is (isim) for ?
Benbirkralm
« Citoyen »
1393161060000
    • Benbirkralm#0000
    • Profil
    • Derniers messages
    • Tribu
#19
  0
Rebornaddict a dit :
what is (isim) for ?

isim=name
a dit :
with phone/notebook/computer for TR Server. Translated for EN Server
Facumice
« Citoyen »
1393238880000
    • Facumice#0000
    • Profil
    • Derniers messages
    • Tribu
#20
  0
Jaackster a dit :
Still isnt the best idea to directly cut and paste and just change letters and call it your own. :/
Especially if you dont understand what your copying, judging by "now you must add code."

It still looks like he did most of it by himself so atleast there is that.

Mostly stop judging others.I would want to see your work Jaack.I think this is good lesson for you dont judge others if your not better then them.
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [e-Book] Lua Programming Language
1 / 2 › »
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27