Solved Storage Issue (Max HP) [OTX3]

Discussion in 'Support' started by Crevasse, Mar 20, 2017.

  1. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    I encountered an interesting problem when changing a player's max HP with equipment. I set Knight armor and Knight legs to increase the wearer's max HP by 20% (each) by adding the maxhitpointspercent attribute and then changing movements.xml. This works just fine, the issue comes when the player wearing the equipment relogs (or dies). Example:

    My test character's base max HP is 100. I put on knight armor and knight legs, the max HP is now 140. I heal up with exura to get full HP. Then, I relog. When I log back in, the max HP is 140 (the bonus is still there) which is fine, but I'm not at full HP anymore, I'm at 120.

    Something is wrong with storage somewhere and it isn't "saving" that the player has healed up to their new max HP. Wearing just one of the two (only K-legs or K-armor) doesn't have a problem. It's when I wear more than 1 item that modifies max HP that the problem arises.

    Any help is greatly appreciated.
     
    Last edited: Mar 20, 2017
  2. Best Answer:
    Post #25 by Il Knight, Mar 21, 2017
  3. Itutorial

    Itutorial Active Member

    Joined:
    Dec 23, 2014
    Messages:
    865
    Likes Received:
    134
    Best Answers:
    6
    add

    player:save()

    in your logout.lua file. check if that fixes it.
     
  4. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,264
    Likes Received:
    870
    Best Answers:
    90
    players already get saved whenever they log out

    otx3 and tfs 1.2 are not the same, so say which one you actually use, they probably changed something with movements in otx
     
    Crevasse likes this.
  5. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    K I will check that. Just curious, why would it save for 1 piece of equipment but not 2? xD
    Thanks for letting me know Xeraphus, I changed the title! I knew OTX3 was based off 1.2 but I didn't know how different it was :p
     
    Last edited: Mar 20, 2017
  6. Xeraphus

    Xeraphus Support Team Support Team Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,264
    Likes Received:
    870
    Best Answers:
    90
    it might save only the last piece of eq that you equipped, rather than your whole set.
    if you can check that somehow it would be a good start (change the hp% values on 2 pieces and see which saves)
     
  7. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    You should post the script you used to equip the items this would better than everyone guessing what the problem could be.
     
  8. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    Code (Text):
    1. <movevent event="Equip" itemid="2476" slot="armor" function="onEquipItem" />
    2.    <movevent event="DeEquip" itemid="2476" slot="armor" function="onDeEquipItem" />
    3.    <movevent event="Equip" itemid="2477" slot="legs" function="onEquipItem" />
    4.    <movevent event="DeEquip" itemid="2477" slot="legs" function="onDeEquipItem" />
    @Makalo Since you asked. Now the whole world can finally stop guessing what the problem could be LOL
     
  9. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    Can you post the entries in items.xml as well?
     
  10. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    @Xeraphus I think you're on to something, it seems to be only saving the HP for the most recent one.
    @Makalo
    Code (Text):
    1. <item id="2476" article="a" name="knight armor">
    2.         <attribute key="weight" value="12000"/>
    3.         <attribute key="armor" value="12"/>
    4.         <attribute key="slotType" value="body"/>
    5.          <attribute key="maxHitPointsPercent" value="120"/>
    6.     </item>
    7.  
    8. <item id="2477" name="knight legs">
    9.        <attribute key="weight" value="7000"/>
    10.        <attribute key="armor" value="8"/>
    11.        <attribute key="slotType" value="legs"/>
    12.        <attribute key="maxHitPointsPercent" value="110"/>
    13.    </item>
    I changed the % so they weren't the same in order to see which one wasn't saving
     
    Last edited: Mar 20, 2017
  11. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    Why not use a script and apply a different subid for each type of slot, after all you can't wear more than one pair of boots right?
    If you do it through a script the server will treat the bonus hp as a condition which can be removed by just removing the item. Even if the player logs out they will still retain the bonus when they log back in and it might even update as the player levels up.
     
  12. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    You're very correct, I could do that. I am just more familiar with doing the attribute key and movements (because it is simpler). Would I just need to create a creaturescript for the movement?

    Could I still make it so different armors do different bonuses though? Yeah I know I can only wear 1 pair of boots but I don't want Knight, Crown and Magic Plate armors to all give the exact same bonus.
     
    Last edited: Mar 20, 2017
  13. SN4KY

    SN4KY Member

    Joined:
    Mar 19, 2015
    Messages:
    48
    Likes Received:
    10
    Best Answers:
    0
  14. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    Yes, you don't really need a complicated script to assign items attributes such as the ones SN4KY linked to. I think it would be a great idea if you started small and just assigned a few attributes to a few items until you become familiar with how it all works together then if you aren't satisfied with your own creativity move on to something more complex.
     
  15. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    Yeah I've seen those ones that SN4KY linked but I thought they were a bit too complicated for what I was going for (although they look cool), just some simple health boost attributes. Well I'll work on making one and I'll check back if I need help, I'll also wait to see if Xeraphus can discover anything with the info I gave him about the order of the items affecting which bonus is retained
     
    Makalo likes this.
  16. Il Knight

    Il Knight Active Member

    Joined:
    Dec 1, 2014
    Messages:
    461
    Likes Received:
    217
    Best Answers:
    6
    on logout do this

    Code (Text):
    1. function onLogout(player)
    2.     local playerId = player:getId()
    3.     if nextUseStaminaTime[playerId] ~= nil then
    4.         nextUseStaminaTime[playerId] = nil
    5.     end
    6. local hp = player:getHealth()
    7. player:setStorageValue(5678, hp)
    8.     return true
    9. end
    10.  
    at the end of Login above the last return true
    do this

    Code (Text):
    1. local hp = player:getStorageValue(5678)
    2. local chp = player:getHealth()
    3. player:addHealth(hp - chp)
    not tested
     
    Last edited: Mar 20, 2017
  17. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    As soon as I login:
    You lose 260 hitpoints.
    You are dead.

    That one doesn't work xD
     
  18. Il Knight

    Il Knight Active Member

    Joined:
    Dec 1, 2014
    Messages:
    461
    Likes Received:
    217
    Best Answers:
    6
    the idea is storage the Hp when you logout, use print instead of player:addHealth(hp - chp)
    remove the player:addHealth(hp - chp)
    and use this
    print(hp)
    print(chp)
    to see the values first
     
    Crevasse likes this.
  19. Crevasse

    Crevasse 惡名昭彰

    Joined:
    Jan 13, 2017
    Messages:
    50
    Likes Received:
    8
    Best Answers:
    2
    @Il Knight hey man thanks for the response but I don't think I understand exactly what you mean. Maybe I'm just not experienced enough but I don't know what "print" means or what it does or why I need to use it. Could you explain it in more detail? Thank you!
     
  20. Makalo

    Makalo Banned User

    Joined:
    Mar 20, 2017
    Messages:
    20
    Likes Received:
    6
    Best Answers:
    0
    the print function allows you to see in the console what value is passed to it.
    Code (Lua):
    1.  
    2. local a = "Hello"
    3. print(a)
    4. -- prints Hello to the server console
    5.  
    When you write scripts you will use print quite often to test specific values executing in the scripts.
    If you want to test more than one value you would place a comma after the initial value.
    Code (Lua):
    1.  
    2. local a = "Hello"
    3. local b = "World"
    4. print(a, b)
    5. -- prints Hello    World in the server console
    6.  
     
  21. cbrm

    cbrm Just another mod Staff Member Global Moderator

    Joined:
    Jan 6, 2009
    Messages:
    6,520
    Likes Received:
    787
    Best Answers:
    0
    Guys, don't argue with Codex, it's proven it is bad for your sanity.
     

Share This Page

Loading...