2022-06-22 14:18:20 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using RageCoop.Core.Scripting;
|
2022-07-02 17:14:56 +08:00
|
|
|
|
using RageCoop.Core;
|
2022-06-22 14:18:20 +08:00
|
|
|
|
|
|
|
|
|
namespace RageCoop.Server.Scripting
|
|
|
|
|
{
|
|
|
|
|
internal class BaseScript:ServerScript
|
|
|
|
|
{
|
2022-07-12 17:10:16 +08:00
|
|
|
|
private readonly Server Server;
|
|
|
|
|
public BaseScript(Server server) { Server=server; }
|
2022-06-22 14:18:20 +08:00
|
|
|
|
public override void OnStart()
|
|
|
|
|
{
|
2022-06-23 09:46:38 +08:00
|
|
|
|
API.RegisterCustomEventHandler(CustomEvents.NativeResponse, NativeResponse);
|
2022-07-01 19:02:38 +08:00
|
|
|
|
API.RegisterCustomEventHandler(CustomEvents.OnVehicleDeleted, (e) =>
|
|
|
|
|
{
|
|
|
|
|
API.Entities.RemoveVehicle((int)e.Args[0]);
|
|
|
|
|
});
|
|
|
|
|
API.RegisterCustomEventHandler(CustomEvents.OnPedDeleted, (e) =>
|
|
|
|
|
{
|
|
|
|
|
API.Entities.RemovePed((int)e.Args[0]);
|
|
|
|
|
});
|
2022-07-10 16:13:08 +08:00
|
|
|
|
API.RegisterCustomEventHandler(CustomEvents.WeatherTimeSync, (e) =>
|
|
|
|
|
{
|
2022-07-12 17:10:16 +08:00
|
|
|
|
if (Server.Settings.WeatherTimeSync)
|
2022-07-10 16:13:08 +08:00
|
|
|
|
{
|
2022-07-12 17:10:16 +08:00
|
|
|
|
foreach (var c in API.GetAllClients().Values)
|
2022-07-10 16:13:08 +08:00
|
|
|
|
{
|
2022-07-12 17:10:16 +08:00
|
|
|
|
if (c==e.Sender)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
c.SendCustomEventQueued(CustomEvents.WeatherTimeSync, e.Args);
|
2022-07-10 16:13:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-06-22 14:18:20 +08:00
|
|
|
|
}
|
|
|
|
|
public override void OnStop()
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-07-09 19:32:11 +08:00
|
|
|
|
public static void SetAutoRespawn(Client c,bool toggle)
|
2022-06-22 14:18:20 +08:00
|
|
|
|
{
|
2022-07-01 19:02:38 +08:00
|
|
|
|
c.SendCustomEvent(CustomEvents.SetAutoRespawn, toggle );
|
2022-06-22 14:18:20 +08:00
|
|
|
|
}
|
2022-07-03 10:46:24 +08:00
|
|
|
|
public void SetNameTag(Client c, bool toggle)
|
|
|
|
|
{
|
|
|
|
|
foreach(var other in API.GetAllClients().Values)
|
|
|
|
|
{
|
|
|
|
|
if (c==other) { continue; }
|
|
|
|
|
other.SendCustomEvent(CustomEvents.SetDisplayNameTag,c.Player.ID, toggle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void SendServerPropsTo(List<ServerProp> objects,List<Client> clients=null)
|
2022-07-02 17:14:56 +08:00
|
|
|
|
{
|
|
|
|
|
foreach(var obj in objects)
|
|
|
|
|
{
|
2022-07-05 11:18:26 +08:00
|
|
|
|
API.SendCustomEventQueued(clients, CustomEvents.ServerPropSync,obj.ID, obj.Model ,obj.Position,obj.Rotation );
|
2022-07-02 17:14:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-03 15:28:28 +08:00
|
|
|
|
public void SendServerBlipsTo(List<ServerBlip> objects, List<Client> clients = null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in objects)
|
|
|
|
|
{
|
2022-07-05 11:18:26 +08:00
|
|
|
|
API.SendCustomEventQueued(clients, CustomEvents.ServerBlipSync, obj.ID, (ushort)obj.Sprite, (byte)obj.Color, obj.Scale,obj.Position,obj.Rotation,obj.Name );
|
2022-07-03 15:28:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-23 09:46:38 +08:00
|
|
|
|
void NativeResponse(CustomEventReceivedArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = (int)e.Args[0];
|
|
|
|
|
Action<object> callback;
|
|
|
|
|
lock (e.Sender.Callbacks)
|
|
|
|
|
{
|
|
|
|
|
if (e.Sender.Callbacks.TryGetValue(id, out callback))
|
|
|
|
|
{
|
|
|
|
|
callback(e.Args[1]);
|
|
|
|
|
e.Sender.Callbacks.Remove(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-07-01 13:54:18 +08:00
|
|
|
|
API.Logger.Error("Failed to parse NativeResponse");
|
|
|
|
|
API.Logger.Error(ex);
|
2022-06-23 09:46:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-22 14:18:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|