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

[LUA] Party camping + cooking + sleeping + other

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
583
Solutions
2
Reaction score
60
Location
México
Hello otlanders, i played an Indie RPG Game that has an interesting system so i had an idea implementing to open-tibia.
Here are some functions the system could have there is a situation: Your hunt ends and you have 50% stamina, so your character is tired. so i need some scripts working together (could be a mod also)
-Characters below 50% stamina has some difficulties like:
--Lower HP regeneration
--Lower mana regeneration
--Lower base speed
--Lower attack speed
--Lower attack (physical and magical) and defense (physical and magical)

So, here is the real question. ¿How will script work?
-You must find a camp-able zone (like Imgur: The most awesome images on the Internet)
-Have 100 soul (no soul for premiums)
-Use 'Straw mat' and player change newtype to dead human (like sleeping in mat) and cant move until rest end or player cancel
-Players resting could be killed. (cancel animation and resting)
-Rest might have a duration of 5 minutes (configurable)
-Restore 10% stamina each 5 minutes (configurable)
-Script might contain hp,mana,speed and attack penalties

The rev version im using is TFS 0.4 Thanks for Reading long post and helping me out :)!
 
Last edited:
1st part is easy and you can do this by onStatsChange in creaturescripts.
2nd part i don't get this one: -Script might contain hp,mana,speed and attack penalties (describe it better or give an example)

I could made some mistakes in code, check if it works:
actions.xml:
Code:
<action itemid="5500-5503" event="script" value="resting.lua"/>
resting.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local config = {
       soul = 100, -- amount of souls to start
       timer = 5, -- time in minutes
       rateStamina = 10, -- percent
   }
   
   if getPlayerSoul(cid) >= config.soul then
       local myOutfit, cstamina, secondPos, changeType, changeStraw, straw = getCreatureOutfit(cid), getPlayerStamina(cid), toPosition, 0, 0, 0
       local clookType = myOutfit.lookType
       if itemEx.itemid == 5501 then
           toPosition = toPosition.x - 1
           straw = 5500
       elseif itemEx.itemid == 5503 then
           toPosition = toPosition.y - 1
           straw = 5502
       elseif itemEx.itemid == 5500 then
           secondPos = secondPos.x + 1
           straw = itemEx.itemid
       elseif itemEx.itemid == 5502 then
           secondPos = secondPos.y + 1
           straw = itemEx.itemid
       end
       if itemEx.itemid == 5500 or 5501 then
           if getPlayerSex(cid) == PLAYERSEX_FEMALE then
               changeType = 7841
               changeStraw = 7842
           else
               changeType = 5496
               changeStraw = 5497
           end
       elseif itemEx.itemid == 5502 or 5503 then
           if getPlayerSex(cid) == PLAYERSEX_FEMALE then
               changeType = 7843
               changeStraw = 7844
           else
               changeType = 5498
               changeStraw = 5499
           end
       end
       doTeleportThing(cid, toPosition, false)
       doCreatureChangeOutfit(cid, {lookTypeEx = changeType})
       doCreatureSetNoMove(cid, true)   
       doTransformItem(getTileItemById(secondPos, straw).uid, changeStraw)   
       doSendAnimatedText(toPosition, "RESTING", TEXTCOLOR_ORANGE)
       addEvent(function()
           if isPlayer(cid) then
               doPlayerSetStamina(cid, cstamina + cstamina * config.rateStamina)
               doCreatureChangeOutfit(cid, {lookType = clookType})
               doRemoveItem(getTileItemById(secondPos, changeStraw).uid, 1)
               doCreateItem(straw, 1, secondPos)
               doCreatureSetNoMove(cid, false)
               doSendAnimatedText(toPosition, "RESTED", TEXTCOLOR_GREEN)
           end
       end, config.timer * 60 * 1000)
   end
   return true
end
 
1st part is easy and you can do this by onStatsChange in creaturescripts.
2nd part i don't get this one: -Script might contain hp,mana,speed and attack penalties (describe it better or give an example)

I could made some mistakes in code, check if it works:
actions.xml:
Code:
<action itemid="5500-5503" event="script" value="resting.lua"/>
resting.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local config = {
       soul = 100, -- amount of souls to start
       timer = 5, -- time in minutes
       rateStamina = 10, -- percent
   }
 
   if getPlayerSoul(cid) >= config.soul then
       local myOutfit, cstamina, secondPos, changeType, changeStraw, straw = getCreatureOutfit(cid), getPlayerStamina(cid), toPosition, 0, 0, 0
       local clookType = myOutfit.lookType
       if itemEx.itemid == 5501 then
           toPosition = toPosition.x - 1
           straw = 5500
       elseif itemEx.itemid == 5503 then
           toPosition = toPosition.y - 1
           straw = 5502
       elseif itemEx.itemid == 5500 then
           secondPos = secondPos.x + 1
           straw = itemEx.itemid
       elseif itemEx.itemid == 5502 then
           secondPos = secondPos.y + 1
           straw = itemEx.itemid
       end
       if itemEx.itemid == 5500 or 5501 then
           if getPlayerSex(cid) == PLAYERSEX_FEMALE then
               changeType = 7841
               changeStraw = 7842
           else
               changeType = 5496
               changeStraw = 5497
           end
       elseif itemEx.itemid == 5502 or 5503 then
           if getPlayerSex(cid) == PLAYERSEX_FEMALE then
               changeType = 7843
               changeStraw = 7844
           else
               changeType = 5498
               changeStraw = 5499
           end
       end
       doTeleportThing(cid, toPosition, false)
       doCreatureChangeOutfit(cid, {lookTypeEx = changeType})
       doCreatureSetNoMove(cid, true)
       doTransformItem(getTileItemById(secondPos, straw).uid, changeStraw)
       doSendAnimatedText(toPosition, "RESTING", TEXTCOLOR_ORANGE)
       addEvent(function()
           if isPlayer(cid) then
               doPlayerSetStamina(cid, cstamina + cstamina * config.rateStamina)
               doCreatureChangeOutfit(cid, {lookType = clookType})
               doRemoveItem(getTileItemById(secondPos, changeStraw).uid, 1)
               doCreateItem(straw, 1, secondPos)
               doCreatureSetNoMove(cid, false)
               doSendAnimatedText(toPosition, "RESTED", TEXTCOLOR_GREEN)
           end
       end, config.timer * 60 * 1000)
   end
   return true
end
Thank you sir, im gonna try describe better.

-If player runs out of stamina. The player will have only 80% base damage, speed, hp mana regen
If player gets more than 80% stamina, those penalties might remove.

-Player regenerates at sleep or camping and gets 20% more damage, 20%+ attack speed, 20%+ hp mana regen and 20%+ base speed for 20 minutes.

Btw. i got these errors
Code:
[17:52:07.767] [Error - Action Interface]
[17:52:07.773] data/actions/scripts/resting.lua:onUse
[17:52:07.775] Description:
[17:52:07.778] attempt to index a number value
[17:52:07.783] stack traceback:
[17:52:07.785]  [C]: in function 'getTileItemById'
[17:52:07.788]  data/actions/scripts/resting.lua:44: in function <data/actions/scripts/resting.lua:1>
[17:52:13.080] [Error - Action Interface]
[17:52:13.098] data/actions/scripts/resting.lua:onUse
[17:52:13.118] Description:
[17:52:13.140] attempt to index a number value
[17:52:13.143] stack traceback:
[17:52:13.145]  [C]: in function 'doTeleportThing'
[17:52:13.156]  data/actions/scripts/resting.lua:41: in function <data/actions/scripts/resting.lua:1>
 
Last edited:
Back
Top