Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a key fob for the personal vehicle menu. #158

Merged
merged 4 commits into from
Mar 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions vMenu/menus/PersonalVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private void CreateMenu()

if (item == toggleLights)
{
PressKeyFob(Game.Player);
if (itemIndex == 0)
{
SetVehicleLights(CurrentPersonalVehicle.Handle, 3);
Expand Down Expand Up @@ -267,22 +268,26 @@ private void CreateMenu()

if (item == toggleEngine)
{
PressKeyFob(Game.Player);
SetVehicleEngineOn(CurrentPersonalVehicle.Handle, !CurrentPersonalVehicle.IsEngineRunning, true, true);
}

else if (item == lockDoors || item == unlockDoors)
{
PressKeyFob(Game.Player);
bool _lock = item == lockDoors;
LockOrUnlockDoors(CurrentPersonalVehicle, _lock);
}

else if (item == soundHorn)
{
PressKeyFob(Game.Player);
SoundHorn(CurrentPersonalVehicle);
}

else if (item == toggleAlarm)
{
PressKeyFob(Game.Player);
ToggleVehicleAlarm(CurrentPersonalVehicle);
}
}
Expand All @@ -294,6 +299,50 @@ private void CreateMenu()
};
}

private async void PressKeyFob(Player player)
{
if(player != null && !player.IsDead && !player.Character.IsInVehicle())
{
uint KeyFobHashKey = (uint)GetHashKey("p_car_keys_01");
RequestModel(KeyFobHashKey);
while(!HasModelLoaded(KeyFobHashKey))
{
await Delay(0);
}

int KeyFobObject = CreateObject((int)KeyFobHashKey, 0, 0, 0, true, true, true);
AttachEntityToEntity(KeyFobObject, player.Character.Handle, GetPedBoneIndex(player.Character.Handle, 57005), 0.09f, 0.03f, -0.02f, -76f, 13f, 28f, false, true, true, true, 0, true);
SetModelAsNoLongerNeeded(KeyFobHashKey); // cleanup model from memory

ClearPedTasks(player.Character.Handle);
if(player.Character.Weapons.Current.Hash != WeaponHash.Unarmed)
{
player.Character.Weapons.Give(WeaponHash.Unarmed, 1, true, true);
}

if (!HasEntityClearLosToEntityInFront(player.Character.Handle, CurrentPersonalVehicle.Handle))
{
TaskTurnPedToFaceEntity(player.Character.Handle, CurrentPersonalVehicle.Handle, 1000);
}

TomGrobbe marked this conversation as resolved.
Show resolved Hide resolved
string animDict = "anim@mp_player_intmenu@key_fob@";
RequestAnimDict(animDict);
while (!HasAnimDictLoaded(animDict)) {
await Delay(0);
}
player.Character.Task.PlayAnimation(animDict, "fob_click", 3f, 1000, AnimationFlags.UpperBodyOnly);
PlaySoundFromEntity(-1, "Remote_Control_Fob", player.Character.Handle, "PI_Menu_Sounds", true, 0);
TomGrobbe marked this conversation as resolved.
Show resolved Hide resolved


await Delay(1250);
DetachEntity(KeyFobObject, false, false);
DeleteObject(ref KeyFobObject);
RemoveAnimDict(animDict); // cleanup anim dict from memory
}

await Delay(0);
}

private async void SoundHorn(Vehicle veh)
{
if (veh != null && veh.Exists())
Expand Down