How do i spawn prop with absolute coordinates?
-
I would love to RTFM but I'm still looking for the FM.
So with lots of googling and some trial and error I managed to take what some docs did in 50 lines and condense it to one working line. Just to add a prop. In this case an addon i created by changing a GTA V prop.var model = World.CreateProp("v_ilev_trev_pictureframe3", Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0)), true, true);
Now I would really appreciate some help on how to position this model, a picture frame, with 6 parameters - to place inside a custom map i created.
The parameters are x, y, z, pitch, yaw, and roll.
<X>-1634.17505</X>
<Y>252.716187</Y>
<Z>62.3505287</Z>
<Pitch>-0.999996006</Pitch>
<Roll>-1.25417102e-06</Roll>
<Yaw>-65.7215347</Yaw>How would i do this?
And part 2 of my question.
Now that this object is created, how would i delete it at a later time, same session. model.delete?
The reason for the delete is to then replace it with another picture, in exactly the same 6 coordinate spot.
Thanks!
-
Update. Haven't figured out placement. Tried this for delete, but it didn't work.
if (e.KeyCode == Keys.NumPad5)
{
var model = World.CreateProp("v_ilev_trev_pictureframe3", Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0)), true, true);
}
if (e.KeyCode == Keys.NumPad6)
{
model.delete();
}
-
var prop = World.CreateProp("v_ilev_trev_pictureframe3", new Vector3(-1634.17505f, 252.716187f, 62.3505287f), new Vector3(-0.999996006f, 0f, -65.7215347f), true, true);
P.S. The variable name shouldn't be
model
like you had it, because it is Prop not a Model. The model is"v_ilev_trev_pictureframe3"
To delete the prop you will have to save the variable in the class. Variables are destroyed when you go outside of scope (a scope is everything between
{ }
), so when you create the variable within theif (...) { }
it is not available outside of that.public class YourScript : Script { Prop myProp = null; public YourScript() { OnKeyDown += YourScript_OnKeyDown; } private void YourScript_OnKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.NumPad5) { myProp = World.CreateProp("v_ilev_trev_pictureframe3", new Vector3(-1634.17505f, 252.716187f, 62.3505287f), new Vector3(-0.999996006f, 0f, -65.7215347f), true, true); } else if (e.KeyCode == Keys.NumPad6) { if (myProp != null && myProp.Exists()) { myProp.Delete(); myProp = null; } } } }
-
That's fantastic. You made my day. Unfortunately there is still a problem which I hope you can solve if it's not too much to ask.
I added your code to my own script and it compiled perfectly on the first run. Went into my saved map file, pressed numkey but nothing happened. Pressed other keys and they did what they were supposed to do. Realized it might be an issue with the interior of the building, that the prop might be falling through the floor. So I changed the coordinates to outside the building.
This time the prop appeared but on the ground. It ignored it's z coordinate.
Can the code be modified so the object stays frozen according to the z position?Also, I was thinking, rather than deleting the object, is it possible to just toggle the visibility to true or false. This would allow me to superimpose objects and then turn all off except one...etc.
Anyway I really appreciate your help. I hope this can be a simple fix. I would also love to know how to write code without proper documentation. I had no idea you could combine the vector3 to have all 6 coordinates and I don't know what the f (float?) means after the numbers. I understand the code but would not be able to write it from scratch without a manual.
-
The last parameter of
CreateProp
is a boolean for whether to place the object on the ground or not. Change thetrue
tofalse
.
If the object falls, try changing the second to last parameter fromtrue
tofalse
. The second to last parameter is for whether the object is dynamic or not. You can also useprop.FreezePosition = true;
to freeze the prop entirely.Use
prop.IsVisible = false;
to make the prop invisible. Change to true to make it visible again.Writing code without proper documentation really just requires a good understanding of C#, then just lots of research and trial and error.
The
CreateProp
function has multiple overloads, meaning there are multipleCreateProp
functions with different parameters. One of them allows you to specify a Vector3 for rotation. You can see that here: https://github.com/crosire/scripthookvdotnet/blob/main/source/scripting_v2/GTA/World.cs#L425The f after a number denotes that the number is of the Float type. Without the f, a decimal number would be of the Double type, and a whole number would be of the Integer type.
-
Thank you so much. Changing the argument to false fixed the problem.
I'll try the invisibility tomorrow.
One point which i found strange though.
The prop coordinates were based on an identical prop placed with Menyoo's Object Spooner.
From my saved XML file, i used those coordinates for the prop spawned by the script.
I was happy to see it spawn, and stay frozen in place, but the location was off just a little.This was easily fixed by changing the coordinates in the script.
Still it is interesting that the coordinates given by manual placement of the object, which were identical to those in the map's xml file, were not reproduced properly by the script.
Again, no big deal.
So once again THANK YOU!
and thanks for the great link as well.
-
This just curiosity at this point.
I checked a my spawned prop, which is now a school greenboard placed against a wall vs the same prop placed on the same wall and then saved as an xml map with menyoo.
I was expecting exactly the same placement but the spawned by script board is lower than the values assigned for it as Y.
The placement on the X and Y is fine. Just the Y (height) is off.Very strange.
Fix is very simple, change the z coordinate in the script until it lines up perfectly with the one placed on the map (i.e. saved in xml).
map value <Z>62.97</Z>
Script value: 62.3f is required to match the map value of 69.97
so roughly off by 0.67 - again, the x and y line up visually perfectly.
-
Checking the Menyoo source code, the only difference I see is that after spawning the prop, Menyoo sets the position again, mentioning that it is more accurate. Basically it does this:
Vector3 myPos = new Vector3(-1634.17505f, 252.716187f, 62.3505287f); myProp = World.CreateProp("v_ilev_trev_pictureframe3", myPos, new Vector3(-0.999996006f, 0f, -65.7215347f), true, false); myProp.PositionNoOffset = myPos;
-
@Jitnaught I'll check this out tomorrow, it's late and my brain is shutting down.
Interesting that issue is just with the z coordinate.
At first it was falling right through (if not on solid ground). That was fixed using your first suggestion.
Now this minor placement issue is again only with the Z axis.So something to look into tomorrow but the great news is that I have an excellent workaround, I can just adjust the coordinates in the script so they end up where they should.
I'm going to create my textures now for the boards and then create addons. That's one thing I've learned to do in the past 2 weeks, using PS, Texture Toolkit, Prop Editor, and ofc OpenIV.
I've done the proof of concept. Start with a blank board in map, spawn a new board with text, delete that one or just visibility, spawn the next one, and so on.
This would be a good way to simulate a PowerPoint presentation as well.So I'm off to bed but not without saying you really solved a huge part of what I'm trying to do. So many many thanks!
Cheers
John
P.S. I have extensive experience creating dashboards and automating processes with Excel VBA - so I'm very tempted to go the VB.Net route.
Presently I have two hurdles, the object model which is by far the biggest hurdle for my needs, and the 2nd is learning the basics of C#.
Maybe I'm fooling myself, but going the VB route might make the scripting part easier but ofc will not help one iota with the object model - including methods, properties, etc.
Once more, I'm not a programmer. Lol.
-
@Jitnaught Once more your code solved the problem, once more thank you.
I would like to learn how to be able to interact with entities that are already in the entity database.
For example, if I have a prop saved with my map, how would i identify that prop so i could change its visibility or change its position, etc.With its handle? I guess that would be the unique identifier?
<ModelHash>0x9217c007</ModelHash>
<Type>3</Type>
<Dynamic>false</Dynamic>
<FrozenPos>true</FrozenPos>
<HashName>prop_b_board_blank8</HashName>
<InitialHandle>376322</InitialHandle>
-
InitialHandle is used only within Menyoo, it is not something you can access outside of Menyoo.
There really isn't a great way I can think of to identify a prop that is in the Menyoo database. The only thing Menyoo changes about the prop is setting it to be a mission entity.
If this will be a completely unique prop, different model and everything, you could identify it using a raycast to "select" the prop.
If you know something about the prop will be constant, like the model or something, you could check for that in your script.
-
@Jitnaught thank you. I think I can workaround this, would've been a nice to have.