• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Wannabe Scripter Looking for advice.

Taurus

Texass
Joined
Jan 11, 2009
Messages
616
Solutions
2
Reaction score
30
Location
United States
So, I really don't suck at fixing scripts someone else wrote. But, I can't yet write my own scripts.

I feel like there is a missing link here. When I look at the impressive scripts that other's write, I think "there's no way they typed this out by hand". Are they using some kind of software/macro within a certain program? How do they make such elaborately organized tables and all?

I feel like I missed out on the best book ever to be read about LUA, or possibly that there is a software that would help me along a great deal. I'm willing to put in the effort, but I am unsure of where to start

About myself:
  • I hold an A.A.S. degree with honors in electronics and computer technology.
  • I am familiar with programming logic and design, though unpracticed.
  • My education was focused on components rather than coding.
  • I have written programs in the past for small microchips (built/programmed a digital compass, it still works.)
  • I have played Tibia on/off for 18 years and the day I found OTs was the best day of my life.
  • I have modified/expanded/re-used every script on this forum, just about.
  • I understand where everything goes in OT servers, I've never encountered a problem I couldn't fix or a system I couldn't modify.
  • I am mostly interested in this because I want to make my servers MORE CUSTOM.
  • I'm sick of only being able to use what is available, though thankful to the people who made it available.
  • I want to understand how to make my own scripts 110%

My questions for you, the expert scripter who, to me, is a rockstar in our obscure community.
  1. Where should I begin? (Also, it can't be easy, learning lies between challenge and despair for me.)
  2. Do you know of any software that LUA/other scripters use, other than Notepad++?
  3. Do you know if there are extensions for Norepad++ that would assist OT scripters?
  4. What am I missing here?
  5. Am I asking the right questions?

Hope I've put my thread in the right place. I figured this falls along the lines of "discussion".

Edit: I keep thinking of other questions like...
  • Is there a place I can read the entire list of OT functions and their parameters?
  • Are there programs that can display LUA in a "psuedo-code" fashion?
 
Well you can get any Lua IDE out there to check for syntax errors in your code. I use SciTE from http://luaforge.net/projects/luaforwindows/

If you are talking about scripting for 1.x you can find all the functions available here: https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp, just search for the comments like
C++:
// player:addItem(itemId[, count = 1[, canDropOnMap = true[, subType = 1[, slot = CONST_SLOT_WHEREEVER]]]])
Or look at the registerMethod calls.

Now for the Lua specific tutorials you can read tutorials from http://lua-users.org/wiki/LuaDirectory and the Lua 5.1 Reference Manual https://www.lua.org/manual/5.1/

And the most important thing is: Ask people for help when you don't know how to do a specific thing, I'm sure there will be someone to help you here on the Support Board
 
Is there a place I can read the entire list of OT functions and their parameters?
Download the source for any server. Lua.cpp contains 95-100% of the functions available for the server.
Where should I begin?
I'm not an "expert" scripter by any means, but to make a script from scratch, is basically taking a bunch of small scripts, and putting them together.
Awhile ago, I kind of explained how I mentally create scripts. https://otland.net/threads/234306/page-26#post-2372722

Sometimes a less professional view, might get you that kick forward in the right direction. :p
 
I'm gonna do that.
If you are talking about scripting for 1.x
Excellent guess.
search for the comments
This is a wealth of info I didn't have previously. I ran across them long ago, before I recognized what they were. Thanks for the direction.


I'm not an "expert"
Yet, you have managed to help me at least once in the past...

explained how I mentally create scripts.
It's called psuedocode, it's a very common method of modularizing programs.

Thank you both for your contribution, I definitely got a lot out of this.
 
Hi, I came across your thread, and figured out I could actually give you some tips, but you should prepare that every beginning hurts, and only depending on how much stubborn and excited about programing you are, would eventually lead you to your success :)
If you would like to learn lua specifically, there are various manuals over the web. When I was making my baby steps with lua I was frequently visiting this site :
http://lua-users.org/

I guess this subsection is worth reading :
http://lua-users.org/wiki/SampleCode

Unfortunately I doubt that there exist an IDE which heavily would give you a support in terms of development for OTS. I myself use CLION with lua plugin, but I am mostly programming in C++ and making scripts occasionaly. If you are able to and keen spare some money, I strongly recommend it by capital R. It has perfect built-in debugger, if you wish to debug server localy you could do that as well as you are able to debug remotely. There are even more features I could tell you about but there is simply too much. Try it out, you wont regret it, and probably would be hard for you to use something else later on ;)

To make your server more custom, don't stick only to lua. Go there and explore C++. New standards have been released (C++11 and C++14) and there is upcoming C++17. All of them worth exploring in my opinion. But it is long journey to go through alone by yourself, I've been down this road (I guess couple of people on this forum were down this road too, maybe they could share their experiences aswell). If you would ever learn C++, invest in a book or video tutorials made by pros. Unfortunately about lua you gotta stick to whats there in internet, I dont think any one is actually teaching it.

Nevertheless, I wish you good luck bro - to succeed you have to stay curious and allow no one to kill your enthusiasm :)
 
Download the source for any server. Lua.cpp contains 95-100% of the functions available for the server.
you don't need to check sources to get your lua environment, getfenv() return a tables with whole environment, example
Code:
local file = io.open("output.txt", "w")
for k, v in pairs(getfenv()) do
  io.output(file)
  io.write(string.format("%s\t%s\n", tostring(k), tostring(v)))
end
io.close(file)
output will be all metatables (aka lua objects) and global variables/functions, so if you want an output with all methods to particular object lets say player as an example
Code:
local file = io.open("output.txt", "w")
for k, v in pairs(getfenv().Player) do
  io.output(file)
  io.write(string.format("%s\t%s\n", tostring(k), tostring(v)))
  end
io.close(file)
 
you don't need to check sources to get your lua environment, getfenv() return a tables with whole environment, example
Code:
local file = io.open("output.txt", "w")
for k, v in pairs(getfenv()) do
  io.output(file)
  io.write(string.format("%s\t%s\n", tostring(k), tostring(v)))
end
io.close(file)
output will be all metatables (aka lua objects) and global variables/functions, so if you want an output with all methods to particular object lets say player as an example
Code:
local file = io.open("output.txt", "w")
for k, v in pairs(getfenv().Player) do
  io.output(file)
  io.write(string.format("%s\t%s\n", tostring(k), tostring(v)))
  end
io.close(file)
Still you wont know the parameters of the functions, thats basically useless by itself for a beginner.
 
Still you wont know the parameters of the functions, thats basically useless by itself for a beginner.
sure, i wasn't referring to beginner tho, but that's true, well noticed, that is just my way to get names of methods i don't remember
 
Go there and explore C++
It is another goal of mine. For now though, I'm sticking with lua, there is a lot I can learn here and I don't have to deal with the headache that comes with libraries/etc. At least for now.

just my way
Thank you for sharing it. For now I think I have what I need to move forward. I think that tarjei is right and I'll eventually have to move into C++ to get my desired result.
 
www.youtube.com/watch?v=-iU1pCgmjx4&list=PLxgtJR7f0RBKGid7F2dfv7qc-xWwSee2O
This playlist covers most of the basics, should be of great assistance to anyone starting to learn Lua.
Fantastic, thank you.

I used this when I wanted to learn how to make scripts, it helped a lot back then
https://otland.net/threads/scripting-guide.74030/#post758231
Sadly, he never completed all the parts

There is also these by Codex that would probably help
https://otland.net/threads/lua-broken-down.235555/
I'm gonna do this. Thank you.
 
Back
Top