Ok, so here I am - I'm working on my Building Blocker And I've run into something I can't do.
What I'm trying to achive - check the position of the block, and see if it in range of the tool cupboard. If so - block placment.
I was able to do it using OnEntityBuilt - in this hook we are getting GameObject that already exist in the world, so we can easly use it's position. But the problem with this hook is, that it's called AFTER block is placed, so I have to remove it and refund the player it's cost.
I'm trying to do the same thing, but with CanBuild hook, but there is a problem - this hook is called with Construction class as a var, and I'm unable to get the location where the player is trying to place it.
So - can anybody help me? What I need is to get the world position of enity that is not created yet. =(
Solved Getting prefab position from Construction class?
Discussion in 'Rust Development' started by Vlad-00003, May 12, 2017.
-
Why you can't just get owner from Planner?
-
Right now I'm checking player position, but that's not what I need.
Player can stay out of range of tool cupboard and at the same time - he may try to build something in the range.
Checking player position is not an option - I need to know the place, where he trying to build.
I need to check if the block he trying to place is in range, not the player himself... -
for the rotation, you can use player.eyes.headrotation -
That main problem is - that I don't know the distance....
Also - I didn't work much with raycasts, so I can't say that I'm good at it =) -
Code:// Initialisation of the ray Ray ray = new Ray(player.ServerPosition, player.eyes.headRotation.eulerAngles);// Return true if it hits a collider at 1000 Unity units (or less) in front of the player if (Physics.Raycast(ray, 1000)) { // Send a message to the player player.ChatMessage("You can't place a building here !"); }
my advice is to test with a distance, then change it and reload the plugin to test, and so on .... -
Okay, I'm has opened my eyes and found it.
Use this hook with Vector3 parameter.
void CanBuild(Planner plan, Construction prefab, Vector3 position) {}
But it works if prefab without socketsLast edited by a moderator: May 12, 2017 -
Also - where this hooks are ejected? I was unable to find anything related in oxide source.... -
-
Also - what if the players tries to place a wall? The wall would be in the air, and even if I'll manage to make raycast to work - if the player would try to place a wall he would be looking in the sky, so there would be nothing to hit for raycast... Still looking for a solution. -
But still - the problem with the sockets. It's impossible(as I can see) to get the position of block player are attaching new one.... -
Well - I guess it solved. Now, thanks to @nivex the way was found.
Code://Getting player position var pos = player.ServerPosition; //Incementig Y by player height pos.y += player.GetHeight(); //Adding player view point to it. var buildPos = pos + (player.eyes.BodyForward() * 4f);