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.
Can't get OnHealingItemUse hook to work
Discussion in 'Rust Development' started by Tunnleram, Feb 11, 2017.
-
Try:
Code:void OnConsumableUse(Item item) { Puts("OnConsumableUse works!"); }
-
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? -
Wulf Community Admin
object OnConsumeableUse(Item item) you can get the user from the item generally. -
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? -
Wulf Community Admin
-
Is there any way in this situation to get information about the active player who is consuming the item?
-
Wulf Community Admin
-
Code:
void OnHealingItemUse(MedicalTool tool, BasePlayer targetPlayer) { BasePlayer player = tool.GetOwnerPlayer(); // The player who is holding the item }
-
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? -
Wulf Community Admin
-
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. -
Wulf Community Admin
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. -
Thank you Wulf. That is very helpful!