151 lines
6.2 KiB
C#
151 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using GrandTheftMultiplayer.Server;
|
|
using GrandTheftMultiplayer.Shared;
|
|
using GrandTheftMultiplayer.Server.API;
|
|
using GrandTheftMultiplayer.Shared.Math;
|
|
using GrandTheftMultiplayer.Server.Elements;
|
|
using GrandTheftMultiplayer.Server.Constant;
|
|
using GrandTheftMultiplayer.Server.Managers;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace Roleplay.RAPI
|
|
{
|
|
static class MainAPI
|
|
{
|
|
|
|
|
|
public static Vehicle getVehicleFromHandle(this API api, NetHandle handle)
|
|
{
|
|
return API.shared.getEntityFromHandle<Vehicle>(handle);
|
|
}
|
|
|
|
public static Vehicle createRolePlayVehicle(VehicleHash model, Vector3 pos, Vector3 rot, int r, int g, int b, int r2 = 0, int g2 = 0, int b2 = 0, string owner = "System")
|
|
{
|
|
Vehicle veh = API.shared.createVehicle(model, pos, rot, 0, 0, 0);
|
|
API.shared.setVehicleCustomPrimaryColor(veh, r, g, b);
|
|
API.shared.setVehicleCustomSecondaryColor(veh, r2, g2, b2);
|
|
API.shared.setEntitySyncedData(veh, "motor", false);
|
|
API.shared.setVehicleEngineStatus(veh, false);
|
|
API.shared.setEntityData(veh, "besitzer", owner);
|
|
API.shared.setEntitySyncedData(veh, "besitzer", owner);
|
|
API.shared.setEntitySyncedData(veh, "model", API.shared.getVehicleDisplayName(model));
|
|
|
|
if (owner != "System")
|
|
{
|
|
//API.shared.setVehicleLocked(veh, true);
|
|
API.shared.setEntitySyncedData(veh, "locked", true);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 2);
|
|
}
|
|
else
|
|
{
|
|
API.shared.setEntitySyncedData(veh, "locked", false);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 1);
|
|
}
|
|
return veh;
|
|
}
|
|
|
|
public static void show3Dmessage(Client player, string text)
|
|
{
|
|
TextLabel txt = API.shared.createTextLabel(text, player.position.Add(new Vector3(0, 0, 1)), 20, 0.7f, true, 0);
|
|
API.shared.setTextLabelColor(txt, 0, 0, 255, 255);
|
|
API.shared.attachEntityToEntity(txt, player, "IK_HEAD", new Vector3(0, 0, 0.4), new Vector3(0, 0, 0));
|
|
API.shared.delay(5000, true, () => { API.shared.deleteEntity(txt); });
|
|
}
|
|
|
|
public static string CalculateMD5Hash(string input)
|
|
{
|
|
MD5 md5 = System.Security.Cryptography.MD5.Create();
|
|
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
|
|
byte[] hash = md5.ComputeHash(inputBytes);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < hash.Length; i++)
|
|
{
|
|
sb.Append(hash[i].ToString("X2"));
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static void requestGhostMode(Vehicle veh, int seconds, API api)
|
|
{
|
|
API.shared.setEntityTransparency(veh,150);
|
|
API.shared.setEntityCollisionless(veh, true);
|
|
api.delay(1000 * seconds, true, () => {
|
|
API.shared.setEntityTransparency(veh, 255);
|
|
API.shared.setEntityCollisionless(veh, false);
|
|
});
|
|
}
|
|
|
|
public static Vehicle createAustellVehicle(VehicleHash model, Vector3 pos, Vector3 rot, string owner = "System",int color = 0)
|
|
{
|
|
Vehicle veh = API.shared.createVehicle(model,pos,rot,color,color,0);
|
|
API.shared.setEntityPositionFrozen(veh,true);
|
|
API.shared.setEntitySyncedData(veh, "motor", false);
|
|
API.shared.setVehicleEngineStatus(veh, false);
|
|
API.shared.setEntityData(veh, "besitzer", owner);
|
|
API.shared.setEntitySyncedData(veh, "besitzer", owner);
|
|
API.shared.setEntitySyncedData(veh, "model", API.shared.getVehicleDisplayName(model));
|
|
if (owner != "System")
|
|
{
|
|
//API.shared.setVehicleLocked(veh, true);
|
|
API.shared.setEntitySyncedData(veh, "locked", true);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 2);
|
|
}
|
|
else
|
|
{
|
|
API.shared.setEntitySyncedData(veh, "locked", false);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 1);
|
|
}
|
|
return veh;
|
|
}
|
|
|
|
public static Vehicle createRolePlayVehicleNonARGB(VehicleHash model, Vector3 pos, Vector3 rot, string owner = "System")
|
|
{
|
|
Vehicle veh = API.shared.createVehicle(model, pos, rot, 0, 0, 0);
|
|
API.shared.setEntitySyncedData(veh, "motor", false);
|
|
API.shared.setVehicleEngineStatus(veh, false);
|
|
API.shared.setEntityData(veh, "besitzer", owner);
|
|
API.shared.setEntitySyncedData(veh, "besitzer", owner);
|
|
API.shared.setEntitySyncedData(veh, "model", API.shared.getVehicleDisplayName(model));
|
|
if (owner != "System")
|
|
{
|
|
//API.shared.setVehicleLocked(veh, true);
|
|
API.shared.setEntitySyncedData(veh, "locked", true);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 2);
|
|
}
|
|
else
|
|
{
|
|
API.shared.setEntitySyncedData(veh, "locked", false);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 1);
|
|
}
|
|
return veh;
|
|
}
|
|
|
|
public static void createWaypoint(Client player, Vector3 pos, int sprite, int color)
|
|
{
|
|
float x = pos.X;
|
|
float y = pos.Y;
|
|
float z = pos.Z;
|
|
API.shared.triggerClientEvent(player, "createWayPoint",x,y,z);
|
|
}
|
|
|
|
public static float getDistanceBetween2Points(Vector3 pos, Vector3 pos2)
|
|
{
|
|
float distance = pos.DistanceTo2D(pos2);
|
|
return distance;
|
|
}
|
|
|
|
public static int getDifference(int number1, int number2)
|
|
{
|
|
int difference = Math.Abs(number1 - number2);
|
|
return difference;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|