Hello there, I am starting to make plugins for Rust, I've got some experience in coding, but, not enough I would say.
How could I detect if the player is hitting a resource node? I though about using
I've also got an idea on how to do it, but I would mostly need to get some examples just to be sure about what I am doing.Code:function PLUGIN:OnEntityTakeDamage(entity, info)
I would also need a list of functions/methods which can be used in plugin-development, using LUA, if someone can get me one, I would appreciate it.
OBS: Already checked the documentation, aint what I am looking for.
Solved Detecting if a player is hitting a resource node?
Discussion in 'Rust Development' started by Uncle One D., Feb 23, 2016.
-
I've found most people who ask for a list of classes and their methods are asked to download a disassembler for the Rust, Unity and Oxide libraries. Since you're using LUA and not C# I'd recommend IL Disassembler, which is free.
Although this is C# I think you're looking along the lines of this, say if you wanted to detect whether a stone rock was hit:
Code:void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (entity.LookupPrefabName() == "assets/prefabs/resource/stone/stone.worldmodel.prefab") { // Stone resource was hit } }
UPDATE: Actually, hitting a stone rock doesn't seem to trigger the OnEntityTakeDamage hook so I'm not sure how this would be achieved. The idea seems simple enough...
Using OnDispenserGather might be way to go.Last edited by a moderator: Feb 23, 2016 -
Mmh, I guess C# is better for scripting plugins for Oxide/Rust, aint it? I think I will just move to C# as it is similar to PAWN which is the language I am used to scripting.
Also, what do you mean with add conditions for tree and stones? -
I mean add if statements to allow you to check if any resource type was hit, not just a rock. C# is nice and convenient when using visual studio but apart from that there's not much difference, apart from the small overhead other languages would have over the native C#.
What is it that you want to achieve by the way?Last edited by a moderator: Feb 23, 2016 -
Nothing much, just trying to make a basic skill-script, basically to train with oxide/rust.
ATM downloading VS2015 to start scripting in C#. -
Ok cool. When you have VS installed add the library references and then you can view all the classes and methods in the object explorer.
-
What would I need to do to use
Code:SendReply(player, "You hit a stone");
I've tried adding //BasePlayer player// to the void, won't get me any error messages on the console but wont also send the player a message.
My actual piece of code, mostly by FunNFriendly:
Code:void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info, BasePlayer player) { if (entity.LookupPrefabName() == "assets/prefabs/resource/stone/stone.worldmodel.prefab") { SendReply(player, "You hit a stone"); } }
Last edited by a moderator: Feb 23, 2016 -
I thought gathering rocks was in
Code:void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) { Puts("OnDispenserGather works!"); }
Also adding parameters to existing hooks won't work, in the case of OnEntityTakeDamage entity is the player/object taking damage and the attacker is info.initiator. But that is unrelated to what you are doing anyway
Try the above piece of code directly and see if it prints that message when you hit a rock -
mmh, yes! It does print, and I guess this void is better for me to use.
But still, how would I send a message to the player which is hitting the rock and only him, not to everyone/console? -
Like what you had before (SendReply) but you will have to find where the player information is stored in the available parameters. It should be easy enough to find if you are using VS. If you haven't found a solution by the time I get home I will have a look for you
-
Yeah that would be great, I am still trying to find a way to check who is the player, but I am still pretty lost with Oxide.
Edit: I got it from ZLevels, the way to get the playerID is:
Code:BasePlayer player = entity as BasePlayer; if (player == null) return;
Last edited by a moderator: Feb 24, 2016 -
You can also use the BaseEntity.ToPlayer method as well, which might be safer as if the entity is not a player object it will throw an exception.