• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

[LUA] Kira's Scripts!

Alyhide

Banned User
Joined
Aug 21, 2010
Messages
1,945
Reaction score
55
Location
Switzerland
Hallo, I have been learning about LUA for a while now, and I decided to actually use it :) So, I will be posting my first scripts from time to time, and If i messed up on something, tell me, so I won't make the same mistake the time.

___________________________________________________________________________

1. When Player Steps On A Certain Tile, He Gets A Greeting Message :

PHP:
function onStepIn(cid, item, frompos, itemEx, topos)
                   doPlayerSendTextMessage(cid,21,"Welcome To Gynwing RPG!")        
end

___________________________________________________________________________

2. When Player Steps On A Certain Tile, He Gets Health/Mana Based On His Level :

PHP:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) then
        doCreatureAddMana(cid, getPlayerLevel(cid) < 50 and 250 or 500)
        doCreatureAddHealth(cid, getPlayerLevel(cid) < 50 and 250 or 500)
    end
    return true
end



"Will Add More Later On, After I Finish Reading Lua.org"
 
Last edited:
Code:
if isPlayer(cid) then

So, do I add it like,

PHP:
function onStepIn(cid, item, frompos, itemEx, topos)
        if isPlayer(cid) then
        elseif getPlayerLevel(cid) < 50 then
                   doCreatureAddMana(cid,250)
                   doCreatureAddHealth(cid,250)
        elseif getPlayerLevel(cid) >= 50 then
                   doCreatureAddMana(cid,500)
                   doCreatureAddHealth(cid,500)
        return TRUE
end


? because if requires an end?
 
yes, for each if an end is required, you open an if clause you must close it with an end
LUA:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) then
        if getPlayerLevel(cid) < 50 then
            doCreatureAddMana(cid,250)
            doCreatureAddHealth(cid,250)
        elseif getPlayerLevel(cid) >= 50 then
            doCreatureAddMana(cid,500)
            doCreatureAddHealth(cid,500)
        end
    end
    return true
end

same script:
LUA:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) then
        doCreatureAddMana(cid, getPlayerLevel(cid) < 50 and 250 or 500)
        doCreatureAddHealth(cid, getPlayerLevel(cid) < 50 and 250 or 500)
    end
    return true
end
 
yes, for each if an end is required, you open an if clause you must close it with an end
LUA:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) then
        if getPlayerLevel(cid) < 50 then
            doCreatureAddMana(cid,250)
            doCreatureAddHealth(cid,250)
        elseif getPlayerLevel(cid) >= 50 then
            doCreatureAddMana(cid,500)
            doCreatureAddHealth(cid,500)
        end
    end
    return true
end

same script:
LUA:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) then
        doCreatureAddMana(cid, getPlayerLevel(cid) < 50 and 250 or 500)
        doCreatureAddHealth(cid, getPlayerLevel(cid) < 50 and 250 or 500)
    end
    return true
end

Ok, thanks CyberM. :)

I'm just glad that people are not Flaming me :(
 
So, do I add it like,

PHP:
function onStepIn(cid, item, frompos, itemEx, topos)
        if isPlayer(cid) then
        elseif getPlayerLevel(cid) < 50 then
                   doCreatureAddMana(cid,250)
                   doCreatureAddHealth(cid,250)
        elseif getPlayerLevel(cid) >= 50 then
                   doCreatureAddMana(cid,500)
                   doCreatureAddHealth(cid,500)
        return TRUE
end
? because if requires an end?

like this
LUA:
function onStepIn(cid, item, frompos, itemEx, topos)
    if isPlayer(cid) then
        if getPlayerLevel(cid) < 50 then
            doCreatureAddMana(cid, 250)
            doCreatureAddHealth(cid, 250)
        elseif getPlayerLevel(cid) >= 50 then
            doCreatureAddMana(cid, 500)
            doCreatureAddHealth(cid, 500)
        end
    end
    return true
end

if you try use players functions on monster you going to get error in console nothing else but with the time become annoying
 
Nah, we're here to help. Need some people to learn this stuff so they don't spend all day on OtLand begging for shit.
 
Nah, we're here to help. Need some people to learn this stuff so they don't spend all day on OtLand begging for shit.

That's why I'm doing it, I don't feel like begging anymore. And I wanted to learn LUA for a while :)
 
That's why I'm doing it, I don't feel like begging anymore. And I wanted to learn LUA for a while :)

Well said, friend! OTland Community will be more than willing to help you learn LUA than to make a script for you!
Also have you read EvilHero's Scripting guide? if not look in the tutorial section under Scripting it's very helpful.
 
(if isPlayer(cid) then)

jano you know, this needed to prevent add something to monster... 8D
 
So, do I add it like,

PHP:
function onStepIn(cid, item, frompos, itemEx, topos)
        if isPlayer(cid) then
        elseif getPlayerLevel(cid) < 50 then
                   doCreatureAddMana(cid,250)
                   doCreatureAddHealth(cid,250)
        elseif getPlayerLevel(cid) >= 50 then
                   doCreatureAddMana(cid,500)
                   doCreatureAddHealth(cid,500)
        return TRUE
end

1# Why did you use PHP tags? Use lua tags.

2#:

LUA:
function onStepIn(cid, item, frompos, itemEx, topos)
        if isPlayer(cid) and getPlayerLevel(cid) < 50 then
                doPlayerSendCancel(cid, "Sorry, ,you're not there just yet."
                elseif getPlayerLevel(cid) > 50 then
        doPlayerAddItem(cid, 2160)
end
end

That's an example.. :P

every IF statement, has an action and after the action it has a "then"

If doSomething(cid) then

Every IF statement, adds one END. At the end of the script. Hope this helped

Also, the function itself, you need to end it. So there you must use 1 end. After the function, just count how many if statements you used and make an end for each one of them :P
 
Last edited:
Well said, friend! OTland Community will be more than willing to help you learn LUA than to make a script for you!
Also have you read EvilHero's Scripting guide? if not look in the tutorial section under Scripting it's very helpful.

Oki, i looked into EvilHero's it seems really good, thats how I started learning


Thanks, I have been looking for a tutorial from lua.org

1# Why did you use PHP tags? Use lua tags.

2#:

LUA:
function onStepIn(cid, item, frompos, itemEx, topos)
        if isPlayer(cid) and getPlayerLevel(cid) < 50 then
                doPlayerSendCancel(cid, "Sorry, ,you're not there just yet."
                elseif getPlayerLevel(cid) > 50 then
        doPlayerAddItem(cid, 2160)
end
end

That's an example.. :P

every IF statement, has an action and after the action it has a "then"

If doSomething(cid) then

Every IF statement, adds one END. At the end of the script. Hope this helped

Also, the function itself, you need to end it. So there you must use 1 end. After the function, just count how many if statements you used and make an end for each one of them :P

Ok, thanks :D
 
Back
Top