Log in to reply

Script as tool to position prop for ped

  • Not sure if any tools or mods exist to do this, position a prop on a ped properly, so I wrote a short script that works well.

    What the script does is provide the vector3 coordinates that can then be used in a movie or mod or script.

    The sensitivity for adjusting x,y,z, pitch, yaw, and roll can be modified depending on the prop. Keys are used to increase/decrease all 6 coordinates, the first 3 being close to 0 because the prop is attached to a bone. Menyoo saved files will give you coordinates in the xml but they don't map well at all for a script. The entity to entity native function drives the attachment itself.

    void ATTACH_ENTITY_TO_ENTITY(Entity entity1, Entity entity2, int boneIndex, float xPos, float yPos, float zPos, float xRot, float yRot, float zRot, BOOL p9, BOOL useSoftPinning, BOOL collision, BOOL isPed, int vertexIndex, BOOL fixedRot) //

  • @JohnFromGWN Once you have determined the best coordinates for the cup you can now have the ped sit in a chair or whatever. This requires a different approach, different script, in that ped is now the prop and obviously chairs don't have a bone structure, well not like peds do. Bone is set to 0 here. Sensitivity is also different allowing for bigger swings.

    Obviously this is much easier to do than attaching a prop to a ped but it eliminates the trial and error. In this video the cup is hard coded from previous tool, ped and chair are spawned thru a script which also allows fine tuning the best coordinates.
    Please note that that in both videos I didn't necessarily keep going to get the optimal position, just wanted a quick and dirty demo of both tools.

  • @JohnFromGWN
    I was watching some videos and was surprised by how many tutorials on youtube, using Menyoo, disable collision, gravity, freeze the ped, and/or disable dynamic when attaching a ped to a chair.

    There was no need to do any of this through scripting so I tried for fun to do this in Menyoo. Same result.

    Once ped is attached to chair you can use the manual placement option without any changes in any other settings. Of course dynamic can be disabled if you don't want ped to interact with other objects, but other than that the advice on youtube is false and just unnecessary.

  • Man this looks amazing! Where can we try your script? I tried to position a burger and a bottle to the ped's right hand in C++ but they all went into a mass :bear:

  • @specialDude Hi. I wrote the script in VB.net but you should be able to easily adapt to C# or C++.

    Initialize the script with this, starting coordinates are usually in the ball park of 0.
    PedPlayer = Game.Player.Character
    Ped4 = World.CreatePed(PedHash.Vagos01GFY, PedPlayer.Position + New Vector3(-2, -2, 0))
    MyCup = World.CreateProp("apa_prop_cs_plastic_cup_01", Ped4.GetOffsetInWorldCoords(New Vector3(0, 3, 0)), True, True)
    PosX1 = 0.01 : PosY1 = 0.06 : PosZ1 = -0.03 'X, Y, Z
    PosX = 4 : PosY = 36 : PosZ = 0 'Pitch/Yaw/Roll
    MyCup.AttachTo(Ped4, 60, New Vector3(PosX1, PosY1, PosZ1), New Vector3(PosX, PosY, PosZ))

    Then attach this to key binding to increment/decrement each of the 6 coordinates. The pitch, yaw, roll will need higher values, 4 or 5 instead of .005.
    PosX1 = PosX1 + 0.005
    MyCup.AttachTo(Ped4, 60, New Vector3(PosX1, PosY1, PosZ1), New Vector3(PosX, PosY, PosZ))
    Call DisplayCoords()

    Finally, note the coords with something like this:
    UI.ShowSubtitle("Final: X = " & PX1 & " Y = " & PY1& & " Z = " & PZ1 & "~n~ ~b~ X = " & PX & " Y = " & PY& & " Z = " & PZ, 28000)

    I used 12 key bindings, would be much easier to do with LemonUI or NativeUI. Will eventually rewrite this.
    The value 60 represents the bone for the hand. What I did was save it in Menyoo and then lookedup the value 60 in the xml file. But you can find these values with google as well.

  • I just realized, that changing the coordinates in the script could also be used to make it look like the character is actually moving the cup (or beer bottle) around in their hand - as it would happen in real life. Just small movements ofc.

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.