1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

itemTable:SetData

Discussion in 'Development' started by grafikerror, Aug 19, 2015.

  1. grafikerror

    grafikerror Clockwork Customer

    Hi guys,
    I would like to create a durability system for the armors but i dont find a working method to modify the new itemdata.
    I mean i would like to lose some durability each time that the guy with the armor get struck.
    Here is the code :
    Code:
    function Schema:PlayerTakeDamage(player, inflictor, attacker, hitGroup, damageInfo)
        local clothes = player:GetCharacterData("clothes");
      
        if (clothes) then
            local itemTable = Clockwork.item:FindByID(clothes);  
            if (itemTable and itemTable.protection) then
                local durability = itemTable:GetData("Durability");
                local test itemTable:GetData("Durability")
                itemTable:SetData("Durability", 0);
                Clockwork.player:Notify(player,"XXX "..durability.." XXX ");
            end;
        end;
    end;
    The notify is fine but the Durability still not modified, any ideas ?
     
  2. Downey Detergent

    Downey Detergent hi Clockwork Customer

    This may or may not want to be put into Support Desk, due to you asking for....Support

    Anyway, I have no idea how to fix this, but I suggest asking an Forum Mod to move this to Support Desk, if you'd like. You may get more responses there as I myself check 'Support Desk' more than 'Development'.

    (Don't repost this issue you're having. Just ask a Forum to move it over via PM or something.)
     
  3. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    Try something like this:

    Code:
    function Schema:PlayerTakeDamage(player, inflictor, attacker, hitGroup, damageInfo)
      local clothes = player:GetCharacterData("clothes");
    
      if (clothes) then
      local itemTable = Clockwork.item:FindByID(clothes);
       
      if (itemTable and itemTable.protection) then
      local durability = itemTable:GetData("Durability", 100);
      local newDurability = math.Clamp(durability - (damageInfo:GetDamage() * 0.01), 0, 100);
       
      itemTable:SetData("Durability", newDurability);
       
      Clockwork.player:Notify(player,"XXX "..newDurability.." XXX ");
      end;
      end;
    end;
    
     
  4. grafikerror

    grafikerror Clockwork Customer

    Hi, your code seems to be a bit better than mine, because it shows the new itemdata, but it still not saving the new itemdata. I mean, i made it loosing 5 durability each time the player get struck for testing purpuses. First notify is 100, it's fine, second one is 95, like it should be, but the durability don't change. And if the player get struck a second time. Same thing, 100 and 95.
    Same for your unmodifyed code.
    Code:
    function Schema:PlayerTakeDamage(player, inflictor, attacker, hitGroup, damageInfo)
        local clothes = player:GetCharacterData("clothes");
    
        if (clothes) then
            local itemTable = Clockwork.item:FindByID(clothes);
     
            if (itemTable and itemTable.protection) then
                local durability = itemTable:GetData("Durability", 100);
                --local durability = itemTable:GetData("Durability");
                Clockwork.player:Notify(player,"XXX "..durability.." XXXXX ");
                local newDurability = math.Clamp(durability - 5, 0, 100);
                --Clockwork.player:Notify(player,"XXX "..newDurability.." XXX ");
                itemTable:SetData("Durability", newDurability);
     
                Clockwork.player:Notify(player,"XXX "..newDurability.." XXX ");
            end;
        end;
    end;
    It still not working but it's sightly better.
     
  5. NightAngel

    NightAngel Fuck off Lev

    Have it print itemTable.name just to test. Though I doubt the issue is you have the wrong item. I don't know what to tell you, it might be a CW bug. I'll have to look into it.
     
  6. grafikerror

    grafikerror Clockwork Customer

    I tried with the itemTable.name. The itemtable is the right one ! I really don't know what to do right now ! If it's a Clockwork issue, when do you think that a fix will be available ?
     
  7. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    Can you try this? I think it's because you're using Clockwork.item:FindByID which I believe will return the core item data. If you use player:GetClothesItem() it will return the item instance.

    Code:
    function Schema:PlayerTakeDamage(player, inflictor, attacker, hitGroup, damageInfo)
      local itemTable = player:GetClothesItem();
    
      if (itemTable and itemTable and itemTable.protection) then
         local durability = itemTable:GetData("Durability", 100);
         --local durability = itemTable:GetData("Durability");
         Clockwork.player:Notify(player,"XXX "..durability.." XXXXX ");
         local newDurability = math.Clamp(durability - 5, 0, 100);
         --Clockwork.player:Notify(player,"XXX "..newDurability.." XXX ");
         itemTable:SetData("Durability", newDurability);
    
         Clockwork.player:Notify(player,"XXX "..newDurability.." XXX ");
      end;
    end;
    
     
  8. grafikerror

    grafikerror Clockwork Customer

    This new player:GetClothesItem() does not seems to be working, i mean, there is not even the notify, no errors.
    I dont think that's a normal thing ! Is player:GetClothesItem() a new function added in CW 0.93 ?
     
  9. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    Hey, GetClothesItem isn't particularly new. Infact, it's in the version of Clockwork that is downloadable via the Store in your My Gamemodes area. And as long as your clothing item is using the sh_clothes_base.lua including with Clockwork, then you're fine.
     
    • Informative Informative x 1
  10. grafikerror

    grafikerror Clockwork Customer

    I still did not find a fix !
    Any suggestion still welcome here !
     
  11. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    What's the error you're getting with this now?
     
    • Good Coder Good Coder x 2
  12. grafikerror

    grafikerror Clockwork Customer

    Fixed by using :
    Code:
    local itemTable = player:FindItemByID(clothes)
    instead of
    Code:
    local itemTable = Clockwork.item:FindByID(clothes);
     
    • Winner Winner x 1
  13. SireElite

    SireElite what's the big fucking deal?

    you still had this problem after 2 years?
     
    • Funny Funny x 6
  14. grafikerror

    grafikerror Clockwork Customer

    Yes ..............:D #Perseverance
     
    • Funny Funny x 2
    • Winner Winner x 1
  15. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    jesus
     
  16. Now that's what I call dedication! Am I right?
     
    • Agree Agree x 1

Previous Readers (Total: 0)