• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

RevScripts Making bread achievement BlackTek-Server

henkebenk

New Member
Joined
Feb 25, 2024
Messages
13
Reaction score
1
Hello,

Request: Bake bread Achievement
Server: BlackTek

I want it to register when the player drop dough on the oven.
Using Modalwindow to track the progress (13/200)
Revscript would be most optimal

I've tried for a couple of hours using ChatGPT but no success...

Thanks in advance!
 
I hope I understand it right

If someone drops a item on spot X(oven) it will receive 1+ then you can check with a command !test as example how many times the item has been droped on spot X? ( 1 / 200 ) right?
And what happens if he reached the 200?
 
Yes, that's correct!

So when the player hits 200/200 - they get an achievement, e.g. "Achievement Unlocked: Master of Crust".

Me & my friend have a server where we use Modalwindow. The command !a pops up a window that looks like this:

1754228453774.webp
1754228484902.webp
1754228500659.webp
What I now lack is a solution that makes the progress work.

I've made other achievement that works, such as killing X/100 rats & Fish X/100 that works all the way. But making bread where you drop doug on the oven seems harder for some reason...

Let me know if you have other questions!
 
Give me the id of
Yes, that's correct!

So when the player hits 200/200 - they get an achievement, e.g. "Achievement Unlocked: Master of Crust".

Me & my friend have a server where we use Modalwindow. The command !a pops up a window that looks like this:

View attachment 94093
View attachment 94094
View attachment 94095
What I now lack is a solution that makes the progress work.

I've made other achievement that works, such as killing X/100 rats & Fish X/100 that works all the way. But making bread where you drop doug on the oven seems harder for some reason...

Let me know if you have other questions!

Easy
I will help u in few hours when im back at home
 
I've made it work! (almost perfect) thanks to you Sorky, thanks!

What issue I have now is when I make bread on the oven, I have to stand next to it, I can't throw dough on it from a few sqm.

Another issue I have is if another player already stands next to the oven, that player gets credit and I don't...

Here is my script:


LUA:
local BREAD_COUNTER_STORAGE = 1700040
local BREAD_ACHIEVEMENT_STORAGE = 170004
local BREAD_GOAL = 200

function onAddItem(moveitem, tileitem, position)
    if moveitem:getId() == 2693 then
        moveitem:transform(2689)
        position:sendMagicEffect(CONST_ME_HITBYFIRE)

        -- Hitta spelaren som "troligen" la degen (den närmsta spelaren)
        local spectators = Game.getSpectators(position, false, true, 1, 1, 0, 0)
        local closestPlayer = nil
        local minDist = 2

        for _, player in ipairs(spectators) do
            if player:isPlayer() then
                local dist = math.max(math.abs(player:getPosition().x - position.x), math.abs(player:getPosition().y - position.y))
                if dist < minDist then
                    minDist = dist
                    closestPlayer = player
                end
            end
        end

        if closestPlayer then
            local count = closestPlayer:getStorageValue(BREAD_COUNTER_STORAGE)
            if count < 0 then count = 0 end
            count = count + 1
            closestPlayer:setStorageValue(BREAD_COUNTER_STORAGE, count)

            if count >= BREAD_GOAL and closestPlayer:getStorageValue(BREAD_ACHIEVEMENT_STORAGE) ~= 1 then
                closestPlayer:setStorageValue(BREAD_ACHIEVEMENT_STORAGE, 1)
                closestPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Achievement Unlocked: Master of Crust!")
            end
        end

    elseif moveitem:getId() == 6277 then
        moveitem:transform(2687, 12)
        position:sendMagicEffect(CONST_ME_HITBYFIRE)
    end

    return true
end

Do you know if it's able to do? So the script knows what player throws the dough and also from a distance?
 
I've made it work! (almost perfect) thanks to you Sorky, thanks!

What issue I have now is when I make bread on the oven, I have to stand next to it, I can't throw dough on it from a few sqm.

Another issue I have is if another player already stands next to the oven, that player gets credit and I don't...

Here is my script:


LUA:
local BREAD_COUNTER_STORAGE = 1700040
local BREAD_ACHIEVEMENT_STORAGE = 170004
local BREAD_GOAL = 200

function onAddItem(moveitem, tileitem, position)
    if moveitem:getId() == 2693 then
        moveitem:transform(2689)
        position:sendMagicEffect(CONST_ME_HITBYFIRE)

        -- Hitta spelaren som "troligen" la degen (den närmsta spelaren)
        local spectators = Game.getSpectators(position, false, true, 1, 1, 0, 0)
        local closestPlayer = nil
        local minDist = 2

        for _, player in ipairs(spectators) do
            if player:isPlayer() then
                local dist = math.max(math.abs(player:getPosition().x - position.x), math.abs(player:getPosition().y - position.y))
                if dist < minDist then
                    minDist = dist
                    closestPlayer = player
                end
            end
        end

        if closestPlayer then
            local count = closestPlayer:getStorageValue(BREAD_COUNTER_STORAGE)
            if count < 0 then count = 0 end
            count = count + 1
            closestPlayer:setStorageValue(BREAD_COUNTER_STORAGE, count)

            if count >= BREAD_GOAL and closestPlayer:getStorageValue(BREAD_ACHIEVEMENT_STORAGE) ~= 1 then
                closestPlayer:setStorageValue(BREAD_ACHIEVEMENT_STORAGE, 1)
                closestPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Achievement Unlocked: Master of Crust!")
            end
        end

    elseif moveitem:getId() == 6277 then
        moveitem:transform(2687, 12)
        position:sendMagicEffect(CONST_ME_HITBYFIRE)
    end

    return true
end

Do you know if it's able to do? So the script knows what player throws the dough and also from a distance?

Use the onItemMoved eventcallback. You have everything you need: The player who moved the item, the item itself and toPosition, which you can check for the oven item id (and make sure its the top item).

You can move the dough script into revscript, and then have both the moveevent and onItemMoved eventcallback all in one script.

(Don't forgot to enable onItemMoved in events.xml...)
 
Last edited:
I can't make it work... I might do something wrong, since Im pretty new into this. Can you guide me step by step?

In events.xml I have this:

LUA:
    <event class="Player" method="onTradeRequest" enabled="1" />

data\scripts\master_of_crust.lua
Code:
local BREAD_COUNTER_STORAGE = 1700040
local BREAD_ACHIEVEMENT_STORAGE = 170004
local BREAD_GOAL = 200

local ovenIds = {
    [1786] = true,
    [1788] = true,
    [1790] = true,
    [1792] = true
}

function Player:onItemMoved(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- Se till att degen placeras på en ugn
    if item:getId() == 2693 and toCylinder and toCylinder:isItem() and ovenIds[toCylinder:getId()] then
        toCylinder:transform(2689)
        toCylinder:getPosition():sendMagicEffect(CONST_ME_HITBYFIRE)

        -- Räkna upp spelarens counter
        local counter = self:getStorageValue(BREAD_COUNTER_STORAGE)
        if counter < 0 then counter = 0 end
        counter = counter + 1
        self:setStorageValue(BREAD_COUNTER_STORAGE, counter)

        -- Unlocka achievement om klart
        if counter >= BREAD_GOAL and self:getStorageValue(BREAD_ACHIEVEMENT_STORAGE) ~= 1 then
            self:setStorageValue(BREAD_ACHIEVEMENT_STORAGE, 1)
            self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Achievement Unlocked: Master of Crust!")
        end
    end
end
 
Back
Top