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

[0.4 lua] Timed based storage potion.

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
579
Solutions
2
Reaction score
58
Location
México
Hello otlanders, im trying to do this script but i keep failing.

I need a potion that with this conditions.
-OnUse reduce current storage 12345 == 31 after use gets to ==21 (-10 current storage)
-After 1 minute of usage the -10 storage resets (so get back from 21 to 31)
-Potion has 1 minute cooldown
-Must be -10 from current storage, not overwrite.

I am using tfs 0.4 :) thanks

Bump
 
Last edited by a moderator:
Solution
here is it
Lua:
local config = {
    storage = 121314,
 storage2 = 3322,
    removeValue = 10,
    delay = 60
}
function onUse(cid, item, fromPosition, target, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
  local storage2 = getPlayerStorageValue(cid, config.storage2)
  local storage3 = getPlayerStorageValue(cid, 12345)
  doPlayerSendCancel(cid, "You are full.")
    if (storage3 >= 10) and (storage2 <= 0) then
 -- doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "[Warning]: You are drinking water; current temperature "..storage3 - config.removeValue.." ")
 doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
 doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_MAGIC_BLUE)...
Lua:
local config = {
    storage = 12345,
    removeValue = 10,
    delay = 60
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
    if storage >= 10 then
        setPlayerStoragevalue(cid, config.storage, storage-config.removeValue)
        addEvent(function(cid)
            if getPlayerGuid(cid) > 0 then
                local storage = getPlayerStorageValue(cid, config.storage)
                setPlayerStoragevalue(cid, config.storage, storage+config.removeValue)
            end
        config.delay*1000, cid)
    end
    return true
end
Something like this maybe?
You'll need to modify the code for your usage thou.

If you could share your script + more info how you want it I could do it for you.
 
but I think this remove the first time the storage and then it will add all the time. So this will not be variable.
 
[18:49:39.137] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:16: '=' expected near '*'
[18:49:39.144] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
[18:49:39.146] data/actions/scripts/liquids/water.lua:16: '=' expected near '*'

bump please?
 
Last edited by a moderator:
Honestly we need more information about this other storage.
If the player is removed from the game before the storage can be reset, that storage will not be reset.

The rest of the code is easy.
 
Honestly we need more information about this other storage.
If the player is removed from the game before the storage can be reset, that storage will not be reset.

The rest of the code is easy.

I have a temperatura script that has a storage value (temperatura), when a player reach a desert tile, the player's temperatura will raise (+20 storage), and i need a wáter script like a "hydratant" script.
After player reach desert he can drink a wáter and downgrade temperature (storage) to -20 for 5 minutes.

-wáter drinks cannot stack (drinks two waterts and get -40 storage for 10 min)
-players can take wáter from rivers, sea, etc
-players can break it vial (% chance)

by the way, thanks for your attention and your help :) sorry for my bad english writing.
 
Lua:
local config = {
    storage = 12345,
    removeValue = 10,
    delay = 60
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
    if storage >= 10'
[code]then
        setPlayerStoragevalue(cid, config.storage, storage-config.removeValue)
        addEvent(function(cid)
            if getPlayerGuid(cid) > 0 then
                local storage = getPlayerStorageValue(cid, config.storage)
                setPlayerStoragevalue(cid, config.storage, storage+config.removeValue)
            end
        config.delay*1000, cid)
    end
    return true
end
Something like this maybe?
You'll need to modify the code for your usage thou.

If you could share your script + more info how you want it I could do it for you.
Im trying to use this code but i got those bunch of errores
Lua:
[18:49:39.137] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:16: '=' expected near '*'
[18:49:39.144] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
[18:49:39.146] data/actions/scripts/liquids/water.lua:16: '='

By the way i described better the situation in the last post
 
Im trying to use this code but i got those bunch of errores
Lua:
[18:49:39.137] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:16: '=' expected near '*'
[18:49:39.144] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
[18:49:39.146] data/actions/scripts/liquids/water.lua:16: '='

By the way i described better the situation in the last post

Lua:
local config = {
    storage = 12345,
    removeValue = 10,
    delay = 60
}

function onUse(cid, item, fromPosition, target, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
    if storage >= 10 then
        setPlayerStoragevalue(cid, config.storage, storage - config.removeValue)
        addEvent(function(cid)
            if getPlayerGuid(cid) > 0 then
                setPlayerStoragevalue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
            end,
        config.delay * 1000, cid)
    end

    return true
end
 
Lua:
local config = {
    storage = 12345,
    removeValue = 10,
    delay = 60
}

function onUse(cid, item, fromPosition, target, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
    if storage >= 10 then
        setPlayerStoragevalue(cid, config.storage, storage - config.removeValue)
        addEvent(function(cid)
            if getPlayerGuid(cid) > 0 then
                setPlayerStoragevalue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
            end,
        config.delay * 1000, cid)
    end

    return true
end
hello, i used your script and got this error
Lua:
[18:47:13.318] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:15: '=' expected near '*'
[18:47:13.319] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
[18:47:13.321] data/actions/scripts/liquids/water.lua:15: '=' expected near '*'
 
hello, i used your script and got this error
Lua:
[18:47:13.318] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:15: '=' expected near '*'
[18:47:13.319] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
[18:47:13.321] data/actions/scripts/liquids/water.lua:15: '=' expected near '*'

Lua:
local config = {
    storage = 12345,
    removeValue = 10,
    delay = 60
}

function onUse(cid, item, fromPosition, target, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
    if storage >= 10 then
        setPlayerStoragevalue(cid, config.storage, storage - config.removeValue)
        addEvent(function(cid)
            if getPlayerGuid(cid) > 0 then
                setPlayerStoragevalue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
            end
        end, config.delay * 1000, cid)
    end

    return true
end
 
Lua:
local config = {
    storage = 12345,
    removeValue = 10,
    delay = 60
}

function onUse(cid, item, fromPosition, target, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
    if storage >= 10 then
        setPlayerStoragevalue(cid, config.storage, storage - config.removeValue)
        addEvent(function(cid)
            if getPlayerGuid(cid) > 0 then
                setPlayerStoragevalue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
            end
        end, config.delay * 1000, cid)
    end

    return true
end
spot another error; on run server wont appear error message but using wáter wont do anything and print this error in console.

fixed: change getPlayerStoragevalue to getPlayerStorageValue and getPlayerGuid to getPlayerGUID

Code:
[10:28:01.416] [Error - Action Interface]
[10:28:01.418] data/actions/scripts/liquids/water.lua:onUse
[10:28:01.419] Description:
[10:28:01.421] data/actions/scripts/liquids/water.lua:10: attempt to call global 'setPlayerStoragevalue' (a nil value)
[10:28:01.422] stack traceback:
[10:28:01.423]  data/actions/scripts/liquids/water.lua:10: in function <data/actions/scripts/liquids/water.lua:7>


PS: thank your you help, Wibbenz :)

player can abuse from drinking 3+ waters and get -30 or more stacks, i need just only 1 drink and cooldown of use also, seems storage wont get back to +10
 
Last edited by a moderator:
spot another error; on run server wont appear error message but using wáter wont do anything and print this error in console.

fixed: change getPlayerStoragevalue to getPlayerStorageValue and getPlayerGuid to getPlayerGUID

Code:
[10:28:01.416] [Error - Action Interface]
[10:28:01.418] data/actions/scripts/liquids/water.lua:onUse
[10:28:01.419] Description:
[10:28:01.421] data/actions/scripts/liquids/water.lua:10: attempt to call global 'setPlayerStoragevalue' (a nil value)
[10:28:01.422] stack traceback:
[10:28:01.423]  data/actions/scripts/liquids/water.lua:10: in function <data/actions/scripts/liquids/water.lua:7>


PS: thank your you help, Wibbenz :)

player can abuse from drinking 3+ waters and get -30 or more stacks, i need just only 1 drink and cooldown of use also, seems storage wont get back to +10

Is it resolved or not?
its already solved
fixed: change getPlayerStoragevalue to getPlayerStorageValue and getPlayerGuid to getPlayerGUID
 
here is it
Lua:
local config = {
    storage = 121314,
 storage2 = 3322,
    removeValue = 10,
    delay = 60
}
function onUse(cid, item, fromPosition, target, toPosition)
    local storage = getPlayerStorageValue(cid, config.storage)
  local storage2 = getPlayerStorageValue(cid, config.storage2)
  local storage3 = getPlayerStorageValue(cid, 12345)
  doPlayerSendCancel(cid, "You are full.")
    if (storage3 >= 10) and (storage2 <= 0) then
 -- doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "[Warning]: You are drinking water; current temperature "..storage3 - config.removeValue.." ")
 doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
 doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_MAGIC_BLUE)
        setPlayerStorageValue(cid, config.storage, storage - config.removeValue)
  setPlayerStorageValue(cid, config.storage2, 1)
        addEvent(function(cid)
            if getPlayerGUID(cid) > 0 then
                setPlayerStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
    setPlayerStorageValue(cid, config.storage2, 0)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "[Warning]: You are dehydrated water; current temperature "..storage3.." ")
            end
        end, config.delay * 1*60*1000, cid)
    end
    return true
end
 
Solution
Back
Top