Hi,
I'm attempting to write some simple util-plugins for my own server, as a web developer used to writing JavaScript and being able to log pretty much anything to console and read through it all I've hit my first stumbling point.
I'm guessing that using something like the following:
I can check if the args of OnEntitySpawned match the entity name of heli, then broadcast to chat that something has happened? How do I know what these args contain?Code:void OnEntitySpawned(BaseNetworkable entity) { if (BaseNetworkable === BaseHelicopter) rust.BroadcastChat("The Patrol Helicopter has spawned!); }
Sorry if this is a basic question, just starting out!
Cheers,
Myles
Solved Detecting when helicopter spawns?
Discussion in 'Rust Development' started by myles., Mar 20, 2017.
-
Wulf Community Admin
I'm not sure what args you are wanting to check/match, but you can check if it's a helicopter like below. If you'd like a working example, look at my Inbound plugin.
Code:void OnEntitySpawned(BaseNetworkable entity) { if (entity is BaseHelicopter) rust.BroadcastChat("The Patrol Helicopter has spawned!); }
Last edited: Mar 21, 2017 -
I suggest learning C#
However, to answer your question, I think a good place to start is to look at Oxide's GitHub.
Also, your code has some issues:
BaseNetworkable is a type. BaseHelicopter is also a type. They are not the same exact type (which you can deduce from the fact that they don't have the same exact name)
I think what you meant to check is if the parameter 'entity' is an instance of the type 'BaseHelicopter'.
Also, if you changed from 'BaseNetworkable === BaseHelicopter' to 'entity === BaseHelicopter', you would still be checking if an object is the same exact thing as a type. Instead, use 'typeof entity === BaseHelicopter'.
Good luck -
Fantastic - thank you both, got it working
-
Code:if (entity is BaseHelicopter) { // Entity is a helicopter, do stuff here }
-
-
-
-
There's no "===" operator in C#, but there is "==". I went with "is" anyway.