Skip to content

Instantly share code, notes, and snippets.

@ejb1123
Last active June 3, 2017 20:11
Show Gist options
  • Save ejb1123/c82714e254788a8b7accce7a5d205a10 to your computer and use it in GitHub Desktop.
Save ejb1123/c82714e254788a8b7accce7a5d205a10 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using CitizenFX.Core.UI;
namespace test
{
public class Class1 : BaseScript
{
public Class1()
{
this.Tick += OnTick;
Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, Game.GenerateHash("stats_controller"));
}
private async Task OnTick()
{
//BaseScript.RegisterScript();
if (Game.IsControlJustPressed(0, Control.MultiplayerInfo))
{
var str = await Game.GetUserInput(9);
//var playerModelString = Function.Call<int>(Hash.PLAYER_PED_ID);
//Screen.ShowNotification(playerModelString.ToString());
//Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, Game.GenerateHash("stats_controller"));
//Function.Call(Hash.STAT_SET_INT,Game.GenerateHash($"MP{playerModelString}_TOTAL_CASH"),99);
//Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, Game.GenerateHash("stats_controller"));
if (int.TryParse(str, out int num))
{
if (!Function.Call<bool>(Hash.NETWORK_DOES_NETWORK_ID_EXIST, num))
{
Screen.ShowNotification($"Error validating the existance of NET_ID {num}");
return;
}
else
{
if (Function.Call<bool>(Hash.NETWORK_HAS_CONTROL_OF_NETWORK_ID, num))
{
Screen.ShowNotification($"You have control of entity NET_ID {num}");
}
else
{
Screen.ShowNotification($"You do not have control of entity NET_ID {num}\n" +
$"Trying to request control");
if (Function.Call<bool>(Hash.NETWORK_REQUEST_CONTROL_OF_NETWORK_ID, num))
{
Screen.ShowNotification($"We think you have control will check");
if (Function.Call<bool>(Hash.NETWORK_HAS_CONTROL_OF_NETWORK_ID, num))
{
Screen.ShowNotification($"Yup you have control continueing");
}
else
{
Screen.ShowNotification($"Yup you do not control continueing");
}
}
else
{
Screen.ShowNotification($"Well, shit it failed to get control");
//return;
}
}
if (!Function.Call<bool>(Hash.NETWORK_DOES_ENTITY_EXIST_WITH_NETWORK_ID, num))
{
Screen.ShowNotification($"Error validating the existance of a entity with a NET_ID of {num}");
//return;
}
Function.Call((Hash)0x06FAACD625D80CAA, new Vehicle(Function.Call<int>(Hash.NETWORK_GET_ENTITY_FROM_NETWORK_ID, num)));
var veh = new Vehicle(Function.Call<int>(Hash.NETWORK_GET_ENTITY_FROM_NETWORK_ID, num));
if (!WarpToVehicle(veh))
{
Screen.ShowNotification("warp failed");
}
}
}
else
{
Screen.ShowNotification($"Error pasring \"{str}\" to a interger");
}
}
if (Game.IsControlJustPressed(0, Control.Cover))
{
if (LocalPlayer.Character.IsInVehicle())
{
Function.Call((Hash)0x06FAACD625D80CAA, LocalPlayer.Character.CurrentVehicle.Handle);
var netidd = Function.Call<int>(Hash.NETWORK_GET_NETWORK_ID_FROM_ENTITY, LocalPlayer.Character.CurrentVehicle.Handle);
Function.Call(Hash.SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES, netidd, true);
Screen.ShowNotification($"Tell the other user to use the \"Z\" key and to enter \"{netidd}\"");
return;
}
var k = new Model(VehicleHash.Police2);
await k.Request(-1);
//var veh = await World.CreateVehicle(VehicleHash.Police2, LocalPlayer.Character.Position);
var veh =new Vehicle( Function.Call<int>(Hash.CREATE_VEHICLE,
VehicleHash.Police2,
LocalPlayer.Character.Position.X,
LocalPlayer.Character.Position.Y,
LocalPlayer.Character.Position.Z,
LocalPlayer.Character.Heading,
true,
true));
//veh.MarkAsNoLongerNeeded();
k.MarkAsNoLongerNeeded();
LocalPlayer.Character.SetIntoVehicle(veh, VehicleSeat.Driver);
//Function.Call((Hash)0x06FAACD625D80CAA, veh);
var netid = Function.Call<int>(Hash.NETWORK_GET_NETWORK_ID_FROM_ENTITY, veh.Handle);
Function.Call(Hash.SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES, netid, true);
Screen.ShowNotification($"Tell the other user to use the \"Z\" key and to enter \"{netid}\"");
}
}
private bool WarpToVehicle(Vehicle veh)
{
if (NextFreeSeat(veh) != (VehicleSeat)55)
{
LocalPlayer.Character.SetIntoVehicle(veh, NextFreeSeat(veh));
return true;
}
else
{
Screen.ShowNotification("No open seats are avalible");
return false;
}
}
//GAMEPLAY::TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME(GAMEPLAY::GET_HASH_KEY("stats_controller"))
//natives.STATS.STAT_SET_INT(natives.GAMEPLAY.GET_HA SH_KEY("MP" .. playerPedId[i] .. "_CHAR_ARMOUR_1_COUNT"), 1, true)
private VehicleSeat NextFreeSeat(Vehicle veh)
{
for (int x = -1; x <= 14; x++)
{
if (veh.IsSeatFree((VehicleSeat)x))
{
return (VehicleSeat)x;
}
}
return (VehicleSeat)55;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment