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

CreatureEvent Reward On Reaching a Certain level

Havocbringer

Well-Known Member
Joined
Apr 28, 2010
Messages
1,687
Reaction score
90
Location
Ireland
Hey guys~ This is a pretty Simple script and what it does is gives the player a reward and a message on reaching a certain level
It can be edited easily
Make a new File called Reward ( a lua file )
Code:
local prizes = {
    [60001] = {level = 50000, reward = {9653, 1}},
    [60002] = {level = 80000, reward = {{7958, 1},  {2157, 100}}},
}

function onAdvance(cid, skill, oldlevel, newlevel)
    if(skill ~= SKILL__LEVEL)then    return TRUE end
    for i,t in ipairs(prizes) do
        if not(getPlayerStorageValue(cid, i)) and t.level <= newlevel then
            if type(t.reward[1] ~= "table") then
                local add = doPlayerAddItem(cid, t.reward[1], t.reward[2])
                if add then
                    doPlayerSendTextMessage(cid, 19, "You have received ".t.reward[2]." ".getItemNameById(t.reward[2])." due to reaching level ".t.level.".")
                    setPlayerStorageValue(cid, i, true)
                end
            else    
                local bp = doCreateItemEx(1988, 1)
                for _,item in ipairs(t.reward) do
                    doAddContainerItem(bp, item[1], item[2])
                end
                local add = doPlayerAddItemEx(cid, bp)
                if add then
                    doPlayerSendTextMessage(cid, 19, "You have received backpack with items due to reaching level ".t.level.".")
                    setPlayerStorageValue(cid, i, true)
                end
            end
        end
    end
    return TRUE
end
And Add this to creaturescripts.xml
Code:
<event type="advance" name="reward" event="script" value="reward.lua"/>
Enjoy guys =)
Rep++ if u liked it OR it helped!
 
Last edited:
no bumps before 24h
 
@Cyberm Oh thaught u could do it RIght after thread was created =) Sorry and thanks for the verbal warning!
 
[21/07/2011 07:49:39] [Error - LuaScriptInterface::loadFile] data/creaturescripts/scripts/reward.lua:6: '}' expected (to close '{' at line 1) near 'function'
[21/07/2011 07:49:39] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/reward.lua)
[21/07/2011 07:49:39] data/creaturescripts/scripts/reward.lua:6: '}' expected (to close '{' at line 1) near 'function'

Using TFS 0.3.6pl1
 
Code:
local prizes = {
    [60001] = {level = 50000, reward = {9653, 1}},
    [60002] = {level = 80000, reward = {{7958, 1},  {2157, 100}}} --<<<
}

The first one doesn't need it because the reward is just one table, the second one is a table with other tables inside, and it was missing the closing }
 
Yes, that too, but we were just talking about the error he was recieving

@Undefeatable
Its missing on your own code too, check it out :)
 
[21/07/2011 15:29:20] [Error - LuaScriptInterface::loadFile] data/creaturescripts/scripts/reward.lua:4: unexpected symbol near '}'
[21/07/2011 15:29:20] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/reward.lua)
[21/07/2011 15:29:20] data/creaturescripts/scripts/reward.lua:4: unexpected symbol near '}'

That popped out after adding the 3rd '}' on the second line.
 
did you added it like Undefeatable did in the first post?
if you did, then please post your code so we can take a better look at it
 
Alright, here is the code.

CODE
local prizes = {
[60001] = {level = 50000, reward = {9653, 1}},
[60002] = {level = 80000, reward = {{7958, 1}, {2157, 100}}},
}

function onAdvance(cid, skill, oldlevel, newlevel)
if(skill ~= SKILL__LEVEL)then return TRUE end
for i,t in ipairs(prizes) do
if not(getPlayerStorageValue(cid, i)) and t.level <= newlevel then
if type(t.reward[1] ~= "table") then
local add = doPlayerAddItem(cid, t.reward[1], t.reward[2])
if add then
doPlayerSendTextMessage(cid, 19, "You have received ".t.reward[2]." ".getItemNameById(t.reward[2])." due to reaching level ".t.level.".")
setPlayerStorageValue(cid, i, true)
end
else
local bp = doCreateItemEx(1988, 1)
for _,item in ipairs(t.reward) do
doAddContainerItem(bp, item[1], item[2])
end
local add = doPlayerAddItemEx(cid, bp)
if add then
doPlayerSendTextMessage(cid, 19, "You have received backpack with items due to reaching level ".t.level.".")
setPlayerStorageValue(cid, i, true)
end
end
end
end
return TRUE
end

ERROR
[21/07/2011 15:55:25] [Error - LuaScriptInterface::loadFile] data/creaturescripts/scripts/reward.lua:13: ')' expected near '.'
[21/07/2011 15:55:25] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/reward.lua)
[21/07/2011 15:55:25] data/creaturescripts/scripts/reward.lua:13: ')' expected near '.'
 
When you want to merge a string and a variable in a text, you have to use ..

also, use the code or the lua tags next time :)

Code:
local prizes = {
    [60001] = {level = 50000, reward = {9653, 1}},
    [60002] = {level = 80000, reward = {{7958, 1}, {2157, 100}}},
}

function onAdvance(cid, skill, oldlevel, newlevel)
    if(skill ~= SKILL__LEVEL)then return TRUE end
    for i,t in ipairs(prizes) do
        if not(getPlayerStorageValue(cid, i)) and t.level <= newlevel then
            if type(t.reward[1]) ~= "table" then
                local add = doPlayerAddItem(cid, t.reward[1], t.reward[2])
                if add then
                    doPlayerSendTextMessage(cid, 19, "You have received " .. t.reward[2] .. " " .. getItemNameById(t.reward[2]) .. " due to reaching level " .. t.level .. ".")
                    setPlayerStorageValue(cid, i, true)
                end
            else 
                local bp = doCreateItemEx(1988, 1)
                for _,item in ipairs(t.reward) do
                    doAddContainerItem(bp, item[1], item[2])
                end
                local add = doPlayerAddItemEx(cid, bp)
                if add then
                    doPlayerSendTextMessage(cid, 19, "You have received backpack with items due to reaching level " .. t.level .. ".")
                    setPlayerStorageValue(cid, i, true)
                end
            end
        end
    end
    return TRUE
end
much better, don't you think? :)

I also took the liberty of fixing another error you had when you are checking the type of t.reward[1]
 
Hmm, weird it doesn't give out the backpack when the certain level is reached, and there is no errors coming out...
 
I have the same problem, Erros don't appears but the player don't get any items.
TFS 4.0
 
do you guys recieve the messages saying "You have recieved backpack with ..." ??

I have the same problem, Erros don't appears but the player don't get any items.
TFS 4.0
Cheater, you aren't premium, how can you have 0.4? lol
Oh, and dont say "I had it and my premium ended" because you registered this month and the minimum VIP membership is 3 months :p
 
Back
Top