Hey guys, I’m having issues getting an objects ID on other clients.
So everything works perfect for the person who executes the command. But for other clients, the object ID returns as 0 like 70% of the time.
If anyone has any ideas, id really appreciate the help.
Client Script
readonly static string hookModel = "prop_hoist_hook"; //Model for hook
static int rope;
public Client()
{
EventHandlers["clientAttachHoistRope"] += new Action<int, int>(AttachHoistRope);
API.RegisterCommand("stuff", new Action<int, List<object>, string>((src, args, raw) =>
{
SpawnHookEvent();
}), false);
}
void SpawnHookEvent()
{
int _vehicle = API.GetVehiclePedIsUsing(API.PlayerPedId());
Vector3 vehiclePos = API.GetEntityCoords(_vehicle, false);
int vehicle = API.ObjToNet(_vehicle);
int hook = API.ObjToNet(API.CreateObject(API.GetHashKey(hookModel), vehiclePos.X - 1f, vehiclePos.Y - 1f, vehiclePos.Z - 1f, true, false, false));
TriggerServerEvent("serverGetHook", hook, vehicle);
}
void AttachHoistRope(int hook, int vehicle)
{
Vector3 hookPos = API.GetEntityCoords(hook, false);
int ropeAttachBone = API.GetEntityBoneIndexByName(vehicle, "rope_attach_a");
Vector3 ropePos = API.GetWorldPositionOfEntityBone(vehicle, ropeAttachBone);
Screen.ShowNotification($"hook {hook}");
int unkPtr = 0;
rope = API.AddRope(0, 0, 0, 0, 0, 0, 100f, 3, 1000f, 0f, 0f, false, false, false, 0f, false, ref unkPtr);
API.AttachEntitiesToRope(rope, hook, vehicle, hookPos.X, hookPos.Y, hookPos.Z, ropePos.X, ropePos.Y, ropePos.Z, 1000f, false, false, "root", "root");
}
Server Script
static int hook;
static int vehicle;
public Server()
{
EventHandlers["serverGetHook"] += new Action<Player, int, int>(ServerGetHook);
}
static void ServerGetHook([FromSource] Player source, int _hook, int _vehicle)
{
hook = API.NetworkGetEntityFromNetworkId(_hook);
vehicle = API.NetworkGetEntityFromNetworkId(_vehicle);
TriggerClientEvent("clientAttachHoistRope", hook, vehicle);
}