Skip to content

Commit

Permalink
Merge pull request #158 from attributeerror/master
Browse files Browse the repository at this point in the history
Add a key fob for the personal vehicle menu.
  • Loading branch information
TomGrobbe authored Mar 13, 2019
2 parents 76b71e8 + 4148aeb commit b13fc5e
Showing 1 changed file with 49 additions and 0 deletions.
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);
}

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);


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

0 comments on commit b13fc5e

Please sign in to comment.