Lua Scripting Guide

EvilSkillz

Back
Joined
Jul 12, 2012
Messages
1,719
Best answers
0
Reaction score
300
Location
Egypt - Cairo
How do you allow characters to dualwield?
dual need to be exist in the source :)
u can find it in 0.4 and OTX

and i think the attribute is
<attribute key="dual" value="1"/>
or
<attribute key="dualwield" value="1"

try each of them xD
 

Black Dove

Web-Developer
Joined
Apr 14, 2010
Messages
129
Best answers
0
Reaction score
4
Location
Egypt
PART V -- For loops...(How do I use them? In which case are they suited the best?)

Here we are to take a first look at loops.
They are maybe confusing at the first time but from time to time you will get used to them.
For loops are most suited for a combination of loop and table, I'll show that in a later part.

For loops are basicly nothing different then a counter, they start at one point and stop on a different.
It is a bit hard to explain that (atleast for me) that is why I am going for an example and comment it, I think that is a way better explained then writing 200 lines about it.

example:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    for var = 1,10 do -- "var" stands for the variable of the two numbers (you can change the variable to others aswell), "1,10" means it's going to loop from 1 to 10 (10 loops in this case)
        print(var) -- will print "1 2 3 4 5 6 7 8 9 10"
    end
    return true
end
each for loop has to have it's own variable, you can't do it like this:
Code:
for var = -1,-10 and var = 1,10 do
correct version:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    for a = -1,-10 and b = 1,10 do -- numbers can either be negative or positive, that doesn't matter, you can also loop from negative to positive and vice versa.
        print(a ..', ' .. b ..'' || ') -- will print "-1, 1 || -2, 2 ||......"
    end
    return true
end
As you can see a for loop aint so hard to setup and use.

Let's go for another example to see how it works in a server based script.

Let's say we want to add the player a backpack and that backpack contains 3 times the same item.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local backpack = doPlayerAddItem(cid, 1988, 1)
    for a = 1,3 do
        doAddContainerItem(backpack, 2160, 100)
    end
    return true
end
There's not really much more to say about the for loops.
We'll get back to them later on.

This Part Is Too Hard Dude
 

Activity

Member
Joined
Apr 7, 2016
Messages
182
Best answers
0
Reaction score
21
Thanks for this contribution, May you continue please with others parts? :).
 
OP
Evil Hero

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,179
Best answers
15
Reaction score
553
Location
Germany
I would love to re write my entire guide, the problem however is, beeing limited to 10k characters each post is quite a hindrance.
I cannot even edit 2 of the posts because they give me the "exceeding post length error"
 

Lundrial

lundrial:getTitle()
Joined
Apr 15, 2014
Messages
134
Best answers
0
Reaction score
71
Location
Chile
I would love to re write my entire guide, the problem however is, beeing limited to 10k characters each post is quite a hindrance.
I cannot even edit 2 of the posts because they give me the "exceeding post length error"
You could try using a "paste" site or making it a pdf, I would love to read it since I'm getting into ots back and there's a lot to learn
 

Damon

Check my status to contact me :)
Joined
Mar 26, 2011
Messages
6,093
Best answers
1
Reaction score
1,853
Location
Germany
Got things solved out, mark enhanced text length to 25k, expect this guide to be re written once I have it completly sorted out
Great to hear you will be doin a re-work! Keep the good work up :) Heroland forever in my dreams btw^^
 

Santi

Theres no way im stopping
Joined
Aug 29, 2010
Messages
1,975
Best answers
0
Reaction score
149
Location
00
Still remember when I read this for the first time, my introduction to this world. Awesome guide.
 

Xikini

I whore myself out for likes
Joined
Nov 17, 2010
Messages
4,172
Best answers
174
Reaction score
2,234
I still use the function list in post #2, because it contains like 95% of the functions I use, and saves me the effort of looking through my source files for the simple lua functions. haha :oops:
I hope they aren't over-written with newer 1.2 stuff. :eek: :rolleyes:
 

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,118
Best answers
54
Reaction score
899
Location
Japan

CipsoftStinks

www.relicaria.com
Joined
Oct 1, 2016
Messages
906
Best answers
3
Reaction score
113
Location
Chile
Welcome to my Scripting Guide!

I hope you'll enjoy your stay and learn much from it :D

This guide is completly about lua related scripting, you'll learn here everything from basics up to advanced stuff.
If you think there's something missing then tell me what and it'll be added.

Please don't leave without commenting!! thanks :rolleyes:

This Thread is based on my old Tutorial

Thread History

I suggest that you go step by step, so nothing will stay unknown to you.
thanks by this tutorial men,it will be finished ?
 
Top