• 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!

Solved Selfmade ring script gives Error!

L

LordVissie

Guest
Hey, I've 2 problems

1. I tried to make a ring script that gives you 10000 hp and 10000 mana. I want to make the ring as reward when you have been rebirth on my server. So If you have been reborned you'll get this ring in your backpack. But I got 2 errors:
Code:
[06/09/2015 09:40:29] [Error - LuaScriptInterface::loadFile] data/actions/scripts/Reborn ring.lua:12: 'end' expected (to close 'function' at line 1) near '<eof>'
[06/09/2015 09:40:29] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/Reborn ring.lua)
[06/09/2015 09:40:29] data/actions/scripts/Reborn ring.lua:12: 'end' expected (to close 'function' at line 1) near '<eof>'

These are my scripts:
The ring as reward:

Code:
function onEquip(cid, item, slot)
local gain = 10000
    if item.itemid == 2357 then
        if getPlayerLevel(cid) >= 150 then -- Level 150 or higher
            doPlayerSendTextMessage(cid,19,"You now gained 10000 hp and mp!") -- Message onEquip you can also delete this line if you want to.
            doCreatureAddMana(cid,gain)
            doCreatureAddHealth(cid,gain)
            else
            doPlayerSendCancel(cid,"You need to be level 150 or higher to use this ring.") -- Cancel message when he is under level 150.
        end
return true
end

The error says something about there is supposed to be a end at line 12, and I'm like
babyrage.png
, There are 2 ends there. :confused:

2nd problem is that I also got a error with the reborn script I have.

The reborn system doesn't has the ring reward line yet.

Code:
[06/09/2015 09:40:29] [Error - LuaScriptInterface::loadFile] data/talkactions/scripts/rebornsystem.lua:35: '<eof>' expected near 'else'
[06/09/2015 09:40:29] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/rebornsystem.lua)
[06/09/2015 09:40:29] data/talkactions/scripts/rebornsystem.lua:35: '<eof>' expected near 'else'

I also don't understand this one error, what is <eof>?

Here is the reborn script:

Code:
config = {
            storage = 1234,
            minLv = 6500, -- minimum lvl to use reborn,
            newLv = 20, -- new level,
            resetmphp = false, --[[ reset hp/mp true or false ]]--,
            effect = 37, -- Effect to done reborn,
            maxreb = 5 -- maximum reborn
}
        
function onSay(cid, words, param, channel)
if(getPlayerStorageValue(cid, config.storage) < 0) then
doPlayerSetStorageValue(cid, config.storage, 0)
end
if(getPlayerStorageValue(cid, config.storage) == 5) then
doPlayerSendCancel(cid, "You have max reborn: "..config.maxreb.."")
return true
end
if(config.resetmphp) == false then
setCreatureMaxHealth(cid, getCreatureHealth(cid))
doCreatureAddHealth(cid, 1)
setCreatureMaxMana(cid, getCreatureMana(cid))
doCreatureAddMana(cid, 1)
elseif(config.resetmphp) == true then
doCreatureAddMana(cid, 40-getCreatureMana(cid))
setCreatureMaxMana(cid, 40)
doCreatureAddHealth(cid, 185-getCreatureHealth(cid))
setCreatureMaxHealth(cid, 185)
end
If(getPlayerLevel(cid) >= config.minLv)
doPlayerAddLevel(cid, -getPlayerLevel(cid)+config.newLv)
doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage)+1)
doPlayerSendTextMessage(cid, 21, "You advanced to reborn: "..getPlayerStorageValue(cid, config.storage).."")
doSendMagicEffect(cid, getCreaturePosition(cid),config.effect)
end
else <eof>
doPlayerSendCancel(cid, "You not have level:".. config.minLv.."")
doSendMagicEffect(cid, getCreaturePosition(cid), CONST_ME_POFF)
return true
end
end

If someone knows a solution please tell me :) I think they are pretty easy problems but I'm too noob to solve them. o_O

Using version 0.3.6.

Kind regards,

LordVissie :cool:
 
Code:
function onEquip(cid, item, slot)
     local gain = 10000
     if item.itemid == 2357 then
         if getPlayerLevel(cid) >= 150 then -- Level 150 or higher
             doPlayerSendTextMessage(cid,19,"You now gained 10000 hp and mp!") -- Message onEquip you can also delete this line if you want to.
             doCreatureAddMana(cid,gain)
             doCreatureAddHealth(cid,gain)
         else
             doPlayerSendCancel(cid,"You need to be level 150 or higher to use this ring.") -- Cancel message when he is under level 150.
         end
     -- ?
     return true
end
The end of the first if statement is missing.

Btw, if you only use the script for 1 item then you don't need to check for the itemid.
And you can do this: https://otland.net/threads/help-bp-give-extra-cap.235116/#post-2269107

Second script.
This is what the script looks like when it's tabbed.
Code:
local config = {
     storage = 1234,
     minLv = 6500, -- minimum lvl to use reborn,
     newLv = 20, -- new level,
     resetmphp = false, --[[ reset hp/mp true or false ]]--,
     effect = 37, -- Effect to done reborn,
     maxreb = 5 -- maximum reborn
}
 
function onSay(cid, words, param, channel)
     if(getPlayerStorageValue(cid, config.storage) < 0) then
         doPlayerSetStorageValue(cid, config.storage, 0)
     end
     if(getPlayerStorageValue(cid, config.storage) == 5) then
         doPlayerSendCancel(cid, "You have max reborn: "..config.maxreb.."")
         return true
     end
     if(config.resetmphp) == false then
         setCreatureMaxHealth(cid, getCreatureHealth(cid))
         doCreatureAddHealth(cid, 1)
         setCreatureMaxMana(cid, getCreatureMana(cid))
         doCreatureAddMana(cid, 1)
     elseif(config.resetmphp) == true then
         doCreatureAddMana(cid, 40-getCreatureMana(cid))
         setCreatureMaxMana(cid, 40)
         doCreatureAddHealth(cid, 185-getCreatureHealth(cid))
         setCreatureMaxHealth(cid, 185)
     end
     if(getPlayerLevel(cid) >= config.minLv)
         doPlayerAddLevel(cid, -getPlayerLevel(cid)+config.newLv)
         doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage)+1)
         doPlayerSendTextMessage(cid, 21, "You advanced to reborn: "..getPlayerStorageValue(cid, config.storage).."")
         doSendMagicEffect(cid, getCreaturePosition(cid),config.effect)
     end

   
     -- ?
     else <eof>
         doPlayerSendCancel(cid, "You not have level:".. config.minLv.."")
         doSendMagicEffect(cid, getCreaturePosition(cid), CONST_ME_POFF)
         return true
     end
end
As you can see now there is no if statement above the else.
Always good to tab/indent the scripts so you can easily find out what's wrong.
https://otland.net/threads/how-to-tab-lua-scripts.203763/
 
Last edited:
Ohh.. I understand but now I get this error:
Code:
[Warning - Event::loadScript] Event onUse not found (data/actions/scripts/Reborn ring.lua)
But I use onEquip and when I change the function to onUse it has no errors but then It only works when I right click and use the item lol :p

And actually I wanted to give 10000 on top off the players maximum hp and mp. I'll search for a "do" thingy :D

Thanks for the help guys :)
 
Action scripts are only for function onUse, so if you add a script in actions, it will look for that function.
function onEquip is from movements and should be added with type Equip in movements.xml same as other equip items but then with script instead of function.
 
Oh yeah, I tought action cuz you equip it. I was already wondering where all the other armors ect. were :p

Works, now but kinda buggy tho it says +10000 when I log in with the ring already equiped and when I login in without the ring equiped it says 20000 (no +) and also when I requip the ring it says 20000. Hm, and Does a "do" function exist that gives hp and mp on top of the normal hp and mp?

And that rebirth system script is really buggy I get plenty of these errors:
Code:
[Error - LuaScriptInterface::loadFile] data/talkactions/scripts/rebornsystem.lua:28: unexpected symbol near 'then'
[Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/rebornsystem.lua)
data/talkactions/scripts/rebornsystem.lua:28: unexpected symbol near 'then'

And I already fixed 8 of them but I'm stuck at this one :l
 
Not sure what you mean exactly, but if you want to set max health you can do this with a condition.
In data/lib/000-constant.lua you can find them. If you're not sure how to use them you can type them in search so you see an example.
Code:
CONDITION_PARAM_STAT_MAXHEALTHPERCENT
CONDITION_PARAM_STAT_MAXMANAPERCENT
https://otland.net/threads/bonus-hp.234634/#post-2263700
For CONDITION_PARAM_TICKS you can do -1 so doesn't go away after a certain time.

You can also add these attributes in items.xml btw if you use function onEquipItem in movements.xml instead of a lua script.
This will be 10%.
Code:
<attribute key="maxManaPointsPercent" value="110"/>
<attribute key="maxHitPointsPercent" value="110"/>

About the reborn script, can you post the script how it looks like now?
 
I meaned like when you have for example 5700 hp and 9300 mana if you equip the ring you'll have 6700 hp and 10300 mana. Oh and I added ur attributes and it worked :) I tought it I needed a script to do it but this works fine too :) A small thingy is when I unequip the ring I'll still have the 10% bonus mana and hp but if it's a lot of work I'll leave it how it is. It's not a biggy.

Here is the Reborn system script:

Code:
local config = {
     storage = 1234,
     minLv = 6500, -- minimum lvl to use reborn,
     newLv = 20, -- new level,
     resetmphp = false, --[[ reset hp/mp true or false ]]--,
     effect = 37, -- Effect to done reborn,
     maxreb = 5 -- maximum reborn
}
function onSay(cid, words, param, channel)
     if(getPlayerStorageValue(cid, config.storage) < 0) then
         doPlayerSetStorageValue(cid, config.storage, 0)
     end
     if(getPlayerStorageValue(cid, config.storage) == 5) then
         doPlayerSendCancel(cid, "You have max reborn: "..config.maxreb.."")
         return true
     end
     if(config.resetmphp) == false then
         setCreatureMaxHealth(cid, getCreatureHealth(cid))
         doCreatureAddHealth(cid, 1)
         setCreatureMaxMana(cid, getCreatureMana(cid))
         doCreatureAddMana(cid, 1)
     elseif(config.resetmphp) == true then
         doCreatureAddMana(cid, 40-getCreatureMana(cid))
         setCreatureMaxMana(cid, 40)
         doCreatureAddHealth(cid, 185-getCreatureHealth(cid))
         setCreatureMaxHealth(cid, 185)
    then (getPlayerLevel(cid) >= config.minLv)
         doPlayerAddLevel(cid, -getPlayerLevel(cid)+config.newLv)
         doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage)+1)
         doPlayerSendTextMessage(cid, 21, "You advanced to reborn: "..getPlayerStorageValue(cid, config.storage).."")
         doSendMagicEffect(cid, getCreaturePosition(cid),config.effect)
     end

 
     end
     else
         doPlayerSendCancel(cid, "You not have level:".. config.minLv.."")
         doSendMagicEffect(cid, getCreaturePosition(cid), CONST_ME_POFF)
         return true
     end
end

I didn't add the line that gives the ring to the player yet.
(I think I'll set max reborn to one cuz I don't know how to add to set a gift to the second rebirth)

Thanks for helping :)
 
You also need to add the DeEquip line in movements, so it goes away when you unequip it.

For the reborn script.
There is this.
Code:
then (getPlayerLevel(cid) >= config.minLv)
If statements should always be like this.
Code:
if ... then
     --
end
With else.
Code:
if ... then
     --
else
     --
end
With elseif.
Code:
if ... then
     --
elseif ... then
     --
end
With elseif and else.
Code:
if ... then
     --
elseif ... then
     --
elseif ... then
     --
else
     --
end
You can use elseif 1x or multiple times, but it should always be between if and else or simply under if if you don't use else.
Both if and elseif should always end with then and then should always be used as an end of an if or elseif statement.
You also can't use else without an if statement above it.

Here it's also a bit explained how if statements work.
https://otland.net/threads/npc-mission.211063/#post-2022374
 
Last edited:
Ah, I understand there are no errors atm I gonna do some tests brb.

13:00 You lose 88135 mana.
13:00 You lose 29402 hitpoints.
13:00 You were downgraded from Level 6686 to Level 403.
13:00 You advanced to reborn: 1

Okay, this isn't supposed to happen. Level only resets to 403, only and my hp is 1 and mana is 0. And when you'll endless die so when you spawn you'll die again like that.

Script:
Code:
local config = {
     storage = 1234,
     minLv = 6500, -- minimum lvl to use reborn,
     newLv = 20, -- new level,
     resetmphp = true, --[[ reset hp/mp true or false ]]--,
     effect = 37, -- Effect to done reborn,
     maxreb = 5 -- maximum reborn
}
function onSay(cid, words, param, channel)
     if(getPlayerStorageValue(cid, config.storage) < 0) then
         doPlayerSetStorageValue(cid, config.storage, 0)
     end
     if(getPlayerStorageValue(cid, config.storage) == 5) then
         doPlayerSendCancel(cid, "You have max reborn: "..config.maxreb.."")
         return true
     end
     if(config.resetmphp) == false then
         setCreatureMaxHealth(cid, getCreatureHealth(cid))
         doCreatureAddHealth(cid, 1)
         setCreatureMaxMana(cid, getCreatureMana(cid))
         doCreatureAddMana(cid, 1)
     elseif(config.resetmphp) == true then
         doCreatureAddMana(cid, 40-getCreatureMana(cid))
         setCreatureMaxMana(cid, 40)
         doCreatureAddHealth(cid, 185-getCreatureHealth(cid))
         setCreatureMaxHealth(cid, 185)
    if    (getPlayerLevel(cid) >= config.minLv) then
         doPlayerAddLevel(cid, -getPlayerLevel(cid)+config.newLv)
         doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage)+1)
         doPlayerSendTextMessage(cid, 21, "You advanced to reborn: "..getPlayerStorageValue(cid, config.storage).."")
         doSendMagicEffect(cid, getCreaturePosition(cid),config.effect)
     end

     else
         doPlayerSendCancel(cid, "You not have level:".. config.minLv.."")
         doSendMagicEffect(cid, getCreaturePosition(cid), CONST_ME_POFF)
         return true
     end
end

wtf :confused:

The guy who maked the script updated it I'll test it.


---- Edit ----

Same problem.
 
Last edited by a moderator:
Back
Top