Hi does anyone know how to use a variable in a function example:
vbone = vehiclebones[math.random(1, #vehiclebones )]
p = GetPlayerPed(-1)
v = GetVehiclePedIsIn(p)
damagecoords = GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, “vbone”))
print(vbone)
print(damagecoords)
The print edition of vbone is coming.
only the damagecoords not.
Output from the ingame debug using F8 See picture. Thanks for your help.
Here’s the array where something is randomly read: Defined Vehicle Bones - Definierte Teile von Autos - Pastebin.com
Derass
January 1, 2023, 11:46am
3
Remove the " around vbone
damagecoords = GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, vbone))
Also, don’t use GetPlayerPed(-1) but PlayerPedId()
If i using p = GetPlayerPedId()
The debug console says:
SCRIPT ERROR: @ai_towtruck /client.lua:266: attempt to call a nil value (global ‘GetPlayerPedId’)
Derass
January 1, 2023, 12:09pm
5
PlayerPedId() Not Get PlayerPedId()
oops Sry my fault i will try …
Hmm something happens but I’m not sure if that’s true shouldn’t there be something to read coordinate now?
Output from debugmode:
[ 1465156] [ GTAProcess] MainThrd/ table: 0000021464804E90
[ 1465156] [ GTAProcess] MainThrd/ vector3(0, 0, 0)
[ 1465953] [ GTAProcess] MainThrd/ table: 0000021464804250
[ 1465953] [ GTAProcess] MainThrd/ vector3(0, 0, 0)
[ 1466765] [ GTAProcess] MainThrd/ table: 0000021464805050
[ 1466765] [ GTAProcess] MainThrd/ vector3(0, 0, 0)
[ 1468687] [ GTAProcess] MainThrd/ table: 0000021464805110
[ 1468703] [ GTAProcess] MainThrd/ vector3(0, 0, 0)
I tested it using a command. My car is on a roof and vector3(0, 0, 0) is still displayed. Is that right? ok?
Derass
January 1, 2023, 12:24pm
8
With your code
You check on random vbone in your list.
Check on specific vbone
Yes, that’s how it should be.
i test it with damagecoords = GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, ““seat_dside_f””))
I tested it, I specify a specific bone e.g. “seat_dside_f” in GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, “seat_dside_f”))
Then coordinates are displayed to me but not when I
GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, vbone)), it always shows me 0 0 0…
The goal is to create an NPC that will repair a car at a random part.
Derass
January 1, 2023, 12:56pm
11
Ok, in the list you link, you have to change all elements like : {chassis}, by a string “chassis”
GetEntityBoneIndexByName - FiveM Natives @ Cfx.re Docs Need a string not an object
Without the {} also so “chassis” or so {“chassis”} ?
Derass
January 1, 2023, 2:04pm
13
without
vehiclebones = {
"chassis",
"windscreen",
"seat_pside_r",
"seat_dside_r",
...
for now it works good. But i have another problem.
The NPC takes a random part walks to it and makes the weelding anim. But he face in the wrong direction see at picture:
i try to get a heading of the part see code but its only wrong.
AddEventHandler(“knb:mechcreate”, function()
vbone = vehiclebones[math.random(1, #vehiclebones )]
p = PlayerPedId()
v = GetVehiclePedIsIn(p)
dcoords = GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, vbone))
print(vbone)
print(dcoords)
GetRepairDriver()
mechdriver = GetHashKey(RepairDriverPick.ped)
RequestModel(mechdriver)
Citizen.Wait(1000)
mechanic = CreatePed(4, mechdriver, dcoords.x+4, dcoords.y, dcoords.z, 90, false, false)
partheading = GetEntityHeading(vbone)
print(partheading)
TaskGoToCoordAnyMeans(mechanic, dcoords, 1.0, 0, 0, 786603, 0xbf800000)
TaskStartScenarioAtPosition(mechanic, ‘WORLD_HUMAN_WELDING’, dcoords, partheading, 0, true, false)
end)
How can i make that the anim works correctly for every part the takes random when i enter the command.
i have found the solution it 2 tasks see code.
AddEventHandler(“knb:mechcreate”, function()
vbone = vehiclebones[math.random(1, #vehiclebones )]
p = PlayerPedId()
v = GetVehiclePedIsIn(p)
dcoords = GetWorldPositionOfEntityBone(v, GetEntityBoneIndexByName(v, vbone))
vcoords = GetEntityCoords(v)
GetRepairDriver()
mechdriver = GetHashKey(RepairDriverPick.ped)
RequestModel(mechdriver)
Citizen.Wait(1000)
mechanic = CreatePed(4, mechdriver, dcoords.x+math.random(-10, 10), dcoords.y, dcoords.z, 90, false, false)
TaskGoToCoordAnyMeans(mechanic, dcoords, 1.3, 0, 0, 786603, 0xbf800000)
Citizen.Wait(6000)
TaskTurnPedToFaceCoord(mechanic, dcoords.x, dcoords.y, dcoords.z, 3000)
Citizen.Wait(3000)
TaskStartScenarioInPlace(mechanic, ‘WORLD_HUMAN_WELDING’, 0, false)
end)
Question: Existis this Anim WORLD_HUMAN_WELDING in a sitting position or only in standing ?