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

Reward script edit

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
625
Reaction score
71
Hello so trying to add event points as a reward and items with chance to get it and without chance just a simple item give. So i will show what i got so far

TFS 1.2
LUA:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, v.pointsReward) -- So this is event points
                    player:addItem(v.itemReward) -- this is adds items dont know about amount
                    -- and dont know how to make to add item with 15% chance to get it
                    -- not even sure if my added code would work
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end

Usage is
pointsReward = 5,
itemReward = 14681,15 (dont know about this itemReward either it looks stupid)
in global.lua i would add these inside this table
LUA:
monsterSystem = {
    [1] = {name = "Worm Boss", pos = Position(228, 1043, 7), expReward = 1500, goldReward = 10,   msg = "Boss spawned. Test!"}
}
 
Solution
S
Code:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, v.pointsReward) -- So this is event points
                    if math.random(1,100) <= v.chance then...
Try use math.random, like:

LUA:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, 5) -- So this is event points
                    if math.random(1,100) <= 15 then
                        player:addItem(14681, 15) -- this is adds items dont know about amount
                    end
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end

And about event points there is no way for me to know for sure, bcos I don't know what is in your lib, but if it is just a "setStorageValue" it should work.
 
Last edited:
Try use math.random, like:

LUA:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, 5) -- So this is event points
                    if math.random(1,100) <= 15 then
                        player:addItem(14681, 15) -- this is adds items dont know about amount
                    end
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end

And about event points there is no way for me to know for sure, bcos I don't know what is in your lib, but if it is just a "setStorageValue" it should work.
It has to be used in global.lua because my table uses different monster names and different rewards so if we put specific number onDeath it will give same reward for every monster, because these functions are used like this and have to be used same
LUA:
monsterSystem = {
    [1] = {name = "Snake Boss", pos = Position(228, 1043, 7), expReward = 200000, goldReward = 5, msg = "TEST MSG!"},
    [2] = {name = "Wolf Boss", pos = Position(960, 937, 7), expReward = 600000, goldReward = 10, msg = "TEST MSG"},
    [3] = {name = "Dildo Boss", pos = Position(1408, 917, 8), expReward = 900000, goldReward = 15, msg = "TEST MSG"}
}

And this is event points
LUA:
function Player:getEventPoints(eventStorage)
    return self:getStorageValue(eventStorage)
end

function Player:addEventPoints(eventStorage, amount)
local points = self:getStorageValue(eventStorage)
    if points == -1 then
        self:setStorageValue(eventStorage, 0)
    end
    
    self:setStorageValue(eventStorage, points + amount)
end
 
Try use math.random, like:

LUA:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, 5) -- So this is event points
                    if math.random(1,100) <= 15 then
                        player:addItem(14681, 15) -- this is adds items dont know about amount
                    end
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end

And about event points there is no way for me to know for sure, bcos I don't know what is in your lib, but if it is just a "setStorageValue" it should work.

Did you try to use this? If yes, any errors / informations on console?
 
You would want to create a new database record and for example: if player won an event it will store +5 points into the database. The best way would be creating it the same way banker works. This way you can have them virtual in the database but also extract them as a new type of coins as example.
 
You would want to create a new database record and for example: if player won an event it will store +5 points into the database. The best way would be creating it the same way banker works. This way you can have them virtual in the database but also extract them as a new type of coins as example.
what you mean event points are storaged in storage
 
To make it a "better" system.
So you create a new column in the database and each time someone should get points you'll do a Lua db.query to store the points. This way you will have less chance to gain bugs. Of course you can obtain the same via storageValues. Just giving you a "better" idea.
 
To make it a "better" system.
So you create a new column in the database and each time someone should get points you'll do a Lua db.query to store the points. This way you will have less chance to gain bugs. Of course you can obtain the same via storageValues. Just giving you a "better" idea.
Well i have no idea how to do that then
 
To make it a "better" system.
So you create a new column in the database and each time someone should get points you'll do a Lua db.query to store the points. This way you will have less chance to gain bugs. Of course you can obtain the same via storageValues. Just giving you a "better" idea.
This way you will have extreme lags, congratulations.
 
if you clarified your needs i can help but its too messy to try to figure out what you need also you are not sure from your code so i won't bother tracing it why do you share something not sure from it while you are asking for "help" <-- something nobody forced to do it for you, keep in mind that i don't know you why would i help if you wasn't clear didn't help me know what you need so i can really help.
 
if you clarified your needs i can help but its too messy to try to figure out what you need also you are not sure from your code so i won't bother tracing it why do you share something not sure from it while you are asking for "help" <-- something nobody forced to do it for you, keep in mind that i don't know you why would i help if you wasn't clear didn't help me know what you need so i can really help.
Im sure that my overall mvp system works but im not sure that those lines i commented above is properly made or they work. To make it more clear what im trying to achieve is
player:addEventPoints() -- give points
player:addItem(v.itemReward) give any item
And give item with % chance to get it
And they should go on the table so rewards could be adjusted for each MVP i have. I though i stated kinda clear what im trying to achieve
 
Code:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, v.pointsReward) -- So this is event points
                    if math.random(1,100) <= v.chance then
                    player:addItem(v.itemReward, v.itemCount) -- this is adds items dont know about amount
                    end
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end
Code:
monsterSystem = {
    [1] = {name = "Snake Boss", pos = Position(228, 1043, 7), chance = 15, expReward = 200000, pointsReward = 10, goldReward = 5, itemReward = 9971, itemCount = 1, msg = "TEST MSG!"},
    [2] = {name = "Wolf Boss", pos = Position(960, 937, 7), chance = 15, expReward = 600000, pointsReward = 10, goldReward = 10, itemReward = 9971, itemCount = 1, msg = "TEST MSG"},
    [3] = {name = "Dildo Boss", pos = Position(1408, 917, 8), chance = 15, expReward = 900000, pointsReward = 10, goldReward = 15, itemReward = 9971, itemCount = 1, msg = "TEST MSG"}
}
 
Solution
Code:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local myEvent = 25335 -- event points storage
    local percent = creature:getMaxHealth() * 0.02
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addEventPoints(myEvent, v.pointsReward) -- So this is event points
                    if math.random(1,100) <= v.chance then
                    player:addItem(v.itemReward, v.itemCount) -- this is adds items dont know about amount
                    end
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end
Code:
monsterSystem = {
    [1] = {name = "Snake Boss", pos = Position(228, 1043, 7), chance = 15, expReward = 200000, pointsReward = 10, goldReward = 5, itemReward = 9971, itemCount = 1, msg = "TEST MSG!"},
    [2] = {name = "Wolf Boss", pos = Position(960, 937, 7), chance = 15, expReward = 600000, pointsReward = 10, goldReward = 10, itemReward = 9971, itemCount = 1, msg = "TEST MSG"},
    [3] = {name = "Dildo Boss", pos = Position(1408, 917, 8), chance = 15, expReward = 900000, pointsReward = 10, goldReward = 15, itemReward = 9971, itemCount = 1, msg = "TEST MSG"}
}
Didnt tested but i think it will work
Post automatically merged:

Shit umm i think you forgot extra one fucntion just a simple item give too
 
Last edited:
This function should be doing it
player:addItem(v.itemReward, v.itemCount) -- this is adds items dont know about amount
just change id in config from 9971(gold ingot) to any other thing
 

Similar threads

Back
Top