[0.4 lua] Timed based storage potion.

Discussion in 'Requests' started by elnelson, Aug 26, 2017.

  1. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    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: Sep 1, 2017
  2. Best Answer:
    Post #17 by elnelson, Oct 12, 2017
  3. Firulis

    Firulis Member

    Joined:
    Jan 3, 2017
    Messages:
    31
    Likes Received:
    0
    Best Answers:
    2
    so basically you want a potion with a 1 minute cooldown?
     
  4. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    And has storage for one minute, after that storage gets setPlayerStoragevalue(cid, getCreatureStorageValue-10)

    Bump
     
    Last edited by a moderator: Oct 4, 2017
  5. Marcus

    Marcus User.postCount++; Premium User

    Joined:
    Nov 14, 2015
    Messages:
    1,041
    Likes Received:
    345
    Best Answers:
    9
    Code (Lua):
    1. local config = {
    2.     storage = 12345,
    3.     removeValue = 10,
    4.     delay = 60
    5. }
    6.  
    7. function onUse(cid, item, fromPosition, itemEx, toPosition)
    8.     local storage = getPlayerStorageValue(cid, config.storage)
    9.     if storage >= 10 then
    10.         setPlayerStoragevalue(cid, config.storage, storage-config.removeValue)
    11.         addEvent(function(cid)
    12.             if getPlayerGuid(cid) > 0 then
    13.                 local storage = getPlayerStorageValue(cid, config.storage)
    14.                 setPlayerStoragevalue(cid, config.storage, storage+config.removeValue)
    15.             end
    16.         config.delay*1000, cid)
    17.     end
    18.     return true
    19. 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.
     
  6. jestem pro

    jestem pro Member

    Joined:
    Apr 20, 2013
    Messages:
    244
    Likes Received:
    12
    Best Answers:
    0
    but I think this remove the first time the storage and then it will add all the time. So this will not be variable.
     
  7. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    [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: Oct 7, 2017
  8. Xikini

    Xikini Titan Kingdoms

    Joined:
    Nov 17, 2010
    Messages:
    3,039
    Likes Received:
    1,554
    Best Answers:
    35
    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.
     
  9. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    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.
     
  10. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    Im trying to use this code but i got those bunch of errores
    Code (Lua):
    1.  
    2. [18:49:39.137] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:16: '=' expected near '*'
    3. [18:49:39.144] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
    4. [18:49:39.146] data/actions/scripts/liquids/water.lua:16: '='
    By the way i described better the situation in the last post
     
  11. WibbenZ

    WibbenZ Support Team Support Team

    Joined:
    Oct 16, 2008
    Messages:
    5,820
    Likes Received:
    1,002
    Best Answers:
    193
    Code (Lua):
    1. local config = {
    2.     storage = 12345,
    3.     removeValue = 10,
    4.     delay = 60
    5. }
    6.  
    7. function onUse(cid, item, fromPosition, target, toPosition)
    8.     local storage = getPlayerStorageValue(cid, config.storage)
    9.     if storage >= 10 then
    10.         setPlayerStoragevalue(cid, config.storage, storage - config.removeValue)
    11.         addEvent(function(cid)
    12.             if getPlayerGuid(cid) > 0 then
    13.                 setPlayerStoragevalue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
    14.             end,
    15.         config.delay * 1000, cid)
    16.     end
    17.  
    18.     return true
    19. end
     
  12. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    hello, i used your script and got this error
    Code (Lua):
    1.  
    2. [18:47:13.318] [Error - LuaInterface::loadFile] data/actions/scripts/liquids/water.lua:15: '=' expected near '*'
    3. [18:47:13.319] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/liquids/water.lua)
    4. [18:47:13.321] data/actions/scripts/liquids/water.lua:15: '=' expected near '*'
     
  13. WibbenZ

    WibbenZ Support Team Support Team

    Joined:
    Oct 16, 2008
    Messages:
    5,820
    Likes Received:
    1,002
    Best Answers:
    193
    Code (Lua):
    1. local config = {
    2.     storage = 12345,
    3.     removeValue = 10,
    4.     delay = 60
    5. }
    6.  
    7. function onUse(cid, item, fromPosition, target, toPosition)
    8.     local storage = getPlayerStorageValue(cid, config.storage)
    9.     if storage >= 10 then
    10.         setPlayerStoragevalue(cid, config.storage, storage - config.removeValue)
    11.         addEvent(function(cid)
    12.             if getPlayerGuid(cid) > 0 then
    13.                 setPlayerStoragevalue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
    14.             end
    15.         end, config.delay * 1000, cid)
    16.     end
    17.  
    18.     return true
    19. end
     
  14. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    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 (Text):
    1.  
    2. [10:28:01.416] [Error - Action Interface]
    3. [10:28:01.418] data/actions/scripts/liquids/water.lua:onUse
    4. [10:28:01.419] Description:
    5. [10:28:01.421] data/actions/scripts/liquids/water.lua:10: attempt to call global 'setPlayerStoragevalue' (a nil value)
    6. [10:28:01.422] stack traceback:
    7. [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: Oct 12, 2017
  15. WibbenZ

    WibbenZ Support Team Support Team

    Joined:
    Oct 16, 2008
    Messages:
    5,820
    Likes Received:
    1,002
    Best Answers:
    193
    Is it resolved or not?
     
  16. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    yeah
    yeah, sorry for the confusion, gote a bunch of lag spikes.

    problem solved, thank you Wibbenz
     
  17. WibbenZ

    WibbenZ Support Team Support Team

    Joined:
    Oct 16, 2008
    Messages:
    5,820
    Likes Received:
    1,002
    Best Answers:
    193
    Okay good, can you in that case upload the working script so I can mark your post as the best answer.
     
  18. elnelson

    elnelson Lunaria dev

    Joined:
    Jun 20, 2009
    Messages:
    214
    Likes Received:
    5
    Best Answers:
    1
    Best Answer
    here is it
    Code (Lua):
    1.  
    2. local config = {
    3.     storage = 121314,
    4.  storage2 = 3322,
    5.     removeValue = 10,
    6.     delay = 60
    7. }
    8. function onUse(cid, item, fromPosition, target, toPosition)
    9.     local storage = getPlayerStorageValue(cid, config.storage)
    10.   local storage2 = getPlayerStorageValue(cid, config.storage2)
    11.   local storage3 = getPlayerStorageValue(cid, 12345)
    12.   doPlayerSendCancel(cid, "You are full.")
    13.     if (storage3 >= 10) and (storage2 <= 0) then
    14.  -- doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "[Warning]: You are drinking water; current temperature "..storage3 - config.removeValue.." ")
    15.  doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
    16.  doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_MAGIC_BLUE)
    17.         setPlayerStorageValue(cid, config.storage, storage - config.removeValue)
    18.   setPlayerStorageValue(cid, config.storage2, 1)
    19.         addEvent(function(cid)
    20.             if getPlayerGUID(cid) > 0 then
    21.                 setPlayerStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage) + config.removeValue)
    22.     setPlayerStorageValue(cid, config.storage2, 0)
    23.     doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "[Warning]: You are dehydrated water; current temperature "..storage3.." ")
    24.             end
    25.         end, config.delay * 1*60*1000, cid)
    26.     end
    27.     return true
    28. end
    29.  
     

Share This Page

Loading...