Added new functions for javascript and small changes
This commit is contained in:
@ -64,33 +64,31 @@ namespace CoopClient
|
|||||||
{
|
{
|
||||||
foreach (string script in Directory.GetFiles("scripts\\resources\\" + serverAddress, "*.js"))
|
foreach (string script in Directory.GetFiles("scripts\\resources\\" + serverAddress, "*.js"))
|
||||||
{
|
{
|
||||||
V8ScriptEngine engine = new V8ScriptEngine()
|
|
||||||
{
|
|
||||||
AccessContext = typeof(ScriptContext)
|
|
||||||
};
|
|
||||||
|
|
||||||
engine.AddHostObject("API", new ScriptContext());
|
|
||||||
|
|
||||||
engine.AddHostType(typeof(Dictionary<,>));
|
|
||||||
|
|
||||||
// SHVDN
|
|
||||||
engine.AddHostType(typeof(Vector3));
|
|
||||||
engine.AddHostType(typeof(Quaternion));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
V8ScriptEngine engine = new V8ScriptEngine()
|
||||||
|
{
|
||||||
|
AccessContext = typeof(ScriptContext)
|
||||||
|
};
|
||||||
|
|
||||||
|
engine.AddHostObject("API", new ScriptContext());
|
||||||
|
|
||||||
|
engine.AddHostType(typeof(Dictionary<,>));
|
||||||
|
|
||||||
|
// SHVDN
|
||||||
|
engine.AddHostType(typeof(Vector3));
|
||||||
|
engine.AddHostType(typeof(Quaternion));
|
||||||
|
|
||||||
engine.Execute(File.ReadAllText(script));
|
engine.Execute(File.ReadAllText(script));
|
||||||
|
|
||||||
|
engine.Script.API.InvokeStart();
|
||||||
|
_scriptEngines.Add(engine);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
GTA.UI.Notification.Show("~r~~h~Javascript Error");
|
GTA.UI.Notification.Show("~r~~h~Javascript Error");
|
||||||
Logger.Write(ex.Message, Logger.LogLevel.Server);
|
Logger.Write(ex.Message, Logger.LogLevel.Server);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
engine.Script.API.InvokeStart();
|
|
||||||
_scriptEngines.Add(engine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,20 +251,20 @@ namespace CoopClient
|
|||||||
|
|
||||||
public bool IsPlayerInvincible()
|
public bool IsPlayerInvincible()
|
||||||
{
|
{
|
||||||
return Game.Player.Character.IsInvincible;
|
return Game.Player.Character?.IsInvincible ?? false;
|
||||||
}
|
}
|
||||||
public void SetPlayerInvincible(bool invincible)
|
public void SetPlayerInvincible(bool invincible)
|
||||||
{
|
{
|
||||||
Game.Player.Character.IsInvincible = invincible;
|
Game.Player.Character.IsInvincible = invincible;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 GetPlayerPosition()
|
public Vector3? GetPlayerPosition()
|
||||||
{
|
{
|
||||||
return Game.Player.Character.Position;
|
return Game.Player.Character?.Position;
|
||||||
}
|
}
|
||||||
public Vector3 GetPlayerRotation()
|
public Vector3? GetPlayerRotation()
|
||||||
{
|
{
|
||||||
return Game.Player.Character.Rotation;
|
return Game.Player.Character?.Rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPlayerPosition(Vector3 position)
|
public void SetPlayerPosition(Vector3 position)
|
||||||
@ -287,9 +285,32 @@ namespace CoopClient
|
|||||||
return Game.Player.Character.IsInVehicle();
|
return Game.Player.Character.IsInVehicle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetCharachterHandle()
|
public int? GetCharachterHandle()
|
||||||
{
|
{
|
||||||
return Game.Player.Character?.Handle ?? 0;
|
return Game.Player.Character?.Handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int? CreateVehicle(int hash, Vector3 position, Quaternion? Rotation = null)
|
||||||
|
{
|
||||||
|
Model model = hash.ModelRequest();
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vehicle veh = World.CreateVehicle(model, position);
|
||||||
|
model.MarkAsNoLongerNeeded();
|
||||||
|
if (veh == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Rotation != null)
|
||||||
|
{
|
||||||
|
veh.Quaternion = Rotation.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return veh.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3? GetVehiclePosition()
|
public Vector3? GetVehiclePosition()
|
||||||
@ -323,14 +344,14 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetVehicleHandle()
|
public int? GetVehicleHandle()
|
||||||
{
|
{
|
||||||
return Game.Player.Character?.CurrentVehicle?.Handle ?? 0;
|
return Game.Player.Character?.CurrentVehicle?.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetVehicleSeatIndex()
|
public int? GetVehicleSeatIndex()
|
||||||
{
|
{
|
||||||
return Game.Player.Character?.CurrentVehicle != null ? (int)Game.Player.Character?.SeatIndex : 0;
|
return (int)Game.Player.Character?.SeatIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVehicleEngineStatus(bool turnedOn)
|
public void SetVehicleEngineStatus(bool turnedOn)
|
||||||
@ -342,7 +363,23 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
public bool GetVehicleEngineStatus()
|
public bool GetVehicleEngineStatus()
|
||||||
{
|
{
|
||||||
return Game.Player.Character.IsInVehicle() ? Game.Player.Character.CurrentVehicle.IsEngineRunning : false;
|
return Game.Player.Character.CurrentVehicle?.IsEngineRunning ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float? GetVehicleHeightAboveGround()
|
||||||
|
{
|
||||||
|
return Game.Player.Character.CurrentVehicle?.HeightAboveGround;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetVehicleType()
|
||||||
|
{
|
||||||
|
Vehicle veh = Game.Player.Character?.CurrentVehicle;
|
||||||
|
if (veh == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Enum.GetName(typeof(VehicleType), veh.Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RepairVehicle()
|
public void RepairVehicle()
|
||||||
|
@ -26,7 +26,7 @@ namespace CoopServer
|
|||||||
private readonly Dictionary<string, object> _customData = new();
|
private readonly Dictionary<string, object> _customData = new();
|
||||||
private long _callbacksCount = 0;
|
private long _callbacksCount = 0;
|
||||||
internal readonly Dictionary<long, Action<object>> Callbacks = new();
|
internal readonly Dictionary<long, Action<object>> Callbacks = new();
|
||||||
internal bool FilesReceived = false;
|
public bool FilesReceived { get; internal set; } = false;
|
||||||
internal bool FilesSent = false;
|
internal bool FilesSent = false;
|
||||||
|
|
||||||
#region CUSTOMDATA FUNCTIONS
|
#region CUSTOMDATA FUNCTIONS
|
||||||
@ -229,6 +229,12 @@ namespace CoopServer
|
|||||||
|
|
||||||
public void SendTriggerEvent(string eventName, params object[] args)
|
public void SendTriggerEvent(string eventName, params object[] args)
|
||||||
{
|
{
|
||||||
|
if (!FilesReceived)
|
||||||
|
{
|
||||||
|
Logging.Warning($"Player \"{Player.Username}\" doesn't have all the files yet!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NetConnection userConnection = Server.MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == NetHandle);
|
NetConnection userConnection = Server.MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == NetHandle);
|
||||||
|
Reference in New Issue
Block a user