1. I'm new, forgive me.

    I'm trying to use OnHealingItemUse(HeldEntity item, BasePlayer target), but it's not working for me. I know I'm doing something wrong.

    I'm trying to do something like this:

    void OnCollectiblePickup(Item item, BasePlayer player) {
    executeQuery("INSERT INTO player_gather_resource (player, resource, count, date) VALUES (@0, @1, @2, @3)" +
    "ON DUPLICATE KEY UPDATE count = count + " + item.amount, player.userID, item.info.displayName.english, item.amount, getDateTime());
    }

    but for insert when food or meds are used.

    How would I achieve this for food? Is OnHealingItemUse the right hook to use? I'm looking to write to the database to show when meds of food is used.
     
  2. Try:
    Code:
    void OnConsumableUse(Item item)
    {
        Puts("OnConsumableUse works!");
    }
     
  3. Thank you.

    Now I'm trying to figure out how to limit the database writes to situations where players are interacting with food and meds.

    oid OnConsumableUse(Item item) {
    executeQuery("INSERT INTO player_consume (player_id, consumable, date) VALUES (@0, @1, @2)", item.info.displayName.english, getDateTime());
    }

    Anything I try to reference player it says "The name `player' does not exist in the current context" which I get. Apparently this hook doesn't work with the player, but there must be a way to get that info.

    How do I grab the current player info and link it to the hook?
     
  4. Wulf

    Wulf Community Admin

    object OnHealingItemUse(HeldEntity item, BasePlayer target) is valid and still being triggered. Keep in mind this is only used for the syringe and medical items, not food.

    object OnConsumeableUse(Item item) you can get the user from the item generally.
     
  5. Again, I'm new forgive me.

    I see item.info.displayName.english will give me the name of the item being consumed, but what are the other options for item? For instance, the person holding item. How do I find all of these variables like item.info.displayName.english? Are they listed somewhere I'm not seeing?
     
  6. Wulf

    Wulf Community Admin

    Well, the problem now is that items no longer have ownership as that was removed in one of the recent updates, so that may not work anymore. So back to the drawing board I guess!
     
  7. Is there any way in this situation to get information about the active player who is consuming the item?
     
  8. Wulf

    Wulf Community Admin

    I don't think there's any way with OnConsumableUse, at least where we hook it.
     
  9. Code:
    void OnHealingItemUse(MedicalTool tool, BasePlayer targetPlayer)
    {           
        BasePlayer player = tool.GetOwnerPlayer();     // The player who is holding the item          
    }       
    ^ Works fine for getting the player who is holding the item. I'd assume GetOwnerPlayer would work in OnConsumableUse also
     
  10. Thanks!

    So here's what I tried:

    void OnConsumableUse(Item item) {
    BasePlayer player = tool.GetOwnerPlayer(); // The player who is holding the item
    excuteQuery("INSERT INTO player_consume (player_id, consumable, date) VALUES (@0, @1, @2)", ((BasePlayer)entity).userID, item.info.displayName.english, getDateTime());
    }

    But it has an issue with ((BasePlayer)entity).userID

    I get:

    Error while compiling MStats.cs(229,108): error CS0103: The name `entity' does not exist in the current context

    Am I referencing BasePlayer correctly or is it not there to reference?
     
  11. Wulf

    Wulf Community Admin

    You can't pull a variable out of thin air, it has to be defined somewhere. ;)
     
  12. With all due respect, that seems like a smarty pants answer to me, but not smart enough to help me further killyou's answer.

    What I don't know yet, since I'm new, is what BasePlayer gives me back in this situation.

    ((BasePlayer)entity).userID doesn't exist as a variable - at least I deduce that's what you're suggesting. However, doesn't BasePlayer player = tool.GetOwnerPlayer(); declare the player as a variable and give me access to it's properties? or do I have to declare everything individually?

    If so, how might I declare the userID?

    Is there any documentation you can refer me to? I don't see anything on BasePlayer on this site, but maybe I missed it.
     
  13. Wulf

    Wulf Community Admin

    The error you had was: "The name `entity' does not exist in the current context" which means that you are trying to use a variable named "entity" that does not exist. If the BasePlayer is indeed validly defined with the player variable, then you'd need to use "player", not "entity" as the variable name.

    BasePlayer comes from Rust, as does BaseEntity, and Item; not Oxide. You can find information about those under Rust's Assembly-CSharp.dll using a .NET decompiler such as JustDecompile.
     
  14. Thank you Wulf. That is very helpful!