1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
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!

Other Issues with a plugin of mine.

Discussion in 'Plugins' started by Oliver, Mar 12, 2019.

  1. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    Greetings folks,

    While I'm not that proficient with code yet, I've ran into an issue that I found I couldn't solve alone. None of the contacts I've got knows how to fix it.

    The issue is as follows;

    For a server I'm planning, I'm creating a furniture crafting plugin utilizing the crafting library provided by CW. Furthermore - as usual - some of the furniture (regular containers if spawned through prop spawn) also utilize container code.

    There are two issues with the plugin currently.

    Issue #1:
    Picking up the container with items in them will delete the items inside upon next drop, practically starting it from scratch. Ideally, I would like the option to pick it up disabled if items or money are present in the container, or to drop them on the floor.

    Issue #2:
    The container can be opened in the inventory, causing errors to be spammed in the console. It can be fixed by dropping and opening it then anew, but preferably the "Open" option should be disabled/removed if it is within a player's inventory.

    I hope someone can help me.

    Plugin item code utilizing the referenced code: https://pastebin.com/Cp5aKAf4
     
  2. Rhenz

    Rhenz Who needs a map? Staff Member Moderator Crusader Veteran Active Member

    While I am not all that familiar with Lua (more so C++), but I had a poke around to see if I could assist in any way. I couldn't find any method of validating if a user's inventory is open, but Vortix did suggest a method of doing so, but he and I were more interested in how you were opening the container. Are you getting an open button while in the user's inventory? Or are you getting it while opening it in the entities inventory, and if so, how?

    And as a preliminary answer to your first issue: I'm sure you could have something like 'if the container is being moved, then empty inventory contents' or something similar. It might require you to make your own function but I'm almost certain there is some Clockwork function that can remove an entities inventory (see shipments of books or vials, for instance).
     
    • Informative Informative x 2
  3. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    Howdy Rhenz.

    Thanks for replying!

    Yes, the "Open" button is usual (ITEM.usetext) for containers in this case (the actual naming convention is different depending on the furniture type to be more immersive, but it's an aesthetic change), which appears both while dropped and in inventory. So on Inventory, the options you have in the context menu is Open, Examine and Drop. Whereas when dropped, will be Open, Examine and Take.

    As for the second issue. Thanks for giving me some pointers, I'll look into shipment code and find, because as you said - and it was hilariously easy that I overlooked - if you delete a shipment, items inside the shipment are chucked into the world. I'll take a look and get back to you on this if I manage to fix it, or with additional information if I don't.
     
  4. Vortix

    Vortix Legend Clockwork Customer Active Member

    Thanks for the report. The issues you've identified lie with Clockwork, rather than with your implementation. As such, I've opened two issues on the repository, and added them to the to-do:
    https://github.com/CloudSixteen/Clockwork/issues/464
    https://github.com/CloudSixteen/Clockwork/issues/465
    In the mean time, until this issue is resolved properly in development, you can perform a non-ideal partial patch:
    • The ITEM:OnUse(player, itemEntity) function call provides the spawned entity for a given item as the second parameter, so you can simply check if itemEntity is a valid entity. If it is, you continue to execute self:OpenFor(player, itemEntity). Otherwise, you don't execute that line. This would mean that the "Open" button would still appear in the inventory, but it wouldn't do anything.
    • Regarding your second issue, I was going to recommend the use of ITEM.CanPickup, but looking at it it seems that this is more accurately described as "ITEM.CanPickupAndUse", and as such these behaviours cannot seemingly be controlled individually at the moment. I have opened an issue for this as well: https://github.com/CloudSixteen/Clockwork/issues/466. As such, my recommendation is to advise users of the issue until it is fixed in development.
    On a separate note, your item code can be simplified. You needn't copy the container base code into your own, but rather you can call upon that code via Clockwork.item.New, as follows:
    Code:
    local ITEM = Clockwork.item:New("container_base");
    
    ITEM.name = "Tall Drawers";
    ITEM.uniqueID = "talldrawers3";
    ITEM.model = "models/props_c17/FurnitureDrawer003a.mdl";
    ITEM.plural = "Tall Drawers";
    ITEM.weight = 4;
    ITEM.category = "Furniture";
    ITEM.batch = 1;
    ITEM.useText = "Open";
    ITEM.description = "Tall drawers. I wouldn't put anything heavy in here as it looks like it might collapse out of misery alone.";
    ITEM.storageSpace = 6;
    
    ITEM:Register();
    
    By passing "container_base" to Clockwork.item.New, it will base your item off of the container base.

    EDIT: Working this in with the OnUse patch, the following should work:
    Code:
    local ITEM = Clockwork.item:New("container_base");
    
    ITEM.name = "Tall Drawers";
    ITEM.uniqueID = "talldrawers3";
    ITEM.model = "models/props_c17/FurnitureDrawer003a.mdl";
    ITEM.plural = "Tall Drawers";
    ITEM.weight = 4;
    ITEM.category = "Furniture";
    ITEM.batch = 1;
    ITEM.useText = "Open";
    ITEM.description = "Tall drawers. I wouldn't put anything heavy in here as it looks like it might collapse out of misery alone.";
    ITEM.storageSpace = 6;
    
    function ITEM:OnUse(player, itemEntity)
        if (IsValid(itemEntity)) then
            self:OpenFor(player, itemEntity);
        end;
    
        return false;
    end;
    
    ITEM:Register();
    
     
    • Informative Informative x 2
    • Like Like x 1
    Last edited: Mar 14, 2019
  5. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    Hey, @Vortix

    Thanks for getting back to me on this.

    With that said, how long do you expect this should take to be implemented into Clockwork? The reason I'm asking is I'm yet to update to the GitHub version of Clockwork, and would rather await actual implementation rather than do a half-patch (as you put it) and have to undo that later down the line when updating anew.
     
  6. Vortix

    Vortix Legend Clockwork Customer Active Member

    Hard to say. As well as the storage issue, there are other user impacting issues I've yet to deal with. It depends on how much free time I get. Additionally, I've yet to look too deeply into the storage system, and so don't know how much time it would take if I were to rework it to make it item-based.
     
  7. Vortix

    Vortix Legend Clockwork Customer Active Member

    The issue of containers being openable in the inventory is now resolved in the v0.100.0 branch. On the pickup issue, is it just me or does the item not seem to retain any items at all? i.e. not just when picked up and dropped.
     
  8. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    You mean post-restart?
     
  9. Vortix

    Vortix Legend Clockwork Customer Active Member

    No: if I deposit an item in the drawers, and close it, the item is gone after re-opening.
     
  10. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    I don't have that. Strange.
     
  11. Vortix

    Vortix Legend Clockwork Customer Active Member

    What version of Clockwork are you using? I tested with v0.100.0-dev and v0.96.3.
     
  12. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    Store version. Let me do a test again.

    Edit:

    Okay, you're right. NO idea what could cause that.
     
  13. Vortix

    Vortix Legend Clockwork Customer Active Member

    I will take a look at that, I just wanted to confirm that you aren't experiencing different behaviour.
     
  14. Oliver

    Oliver O o f Veteran Clockwork Customer Active Member

    My bad, I updated to 0.99 a few days ago.