vehicle sync OHNE FEHLER
This commit is contained in:
@@ -38,6 +38,8 @@ export default function speedometer(globalData: IGlobalData) {
|
||||
var lockG = 255;
|
||||
var lockB = 255;
|
||||
|
||||
lockStatus = player.vehicle.getDoorLockStatus() != 1;
|
||||
|
||||
if (lockStatus) {
|
||||
lockR = 104;
|
||||
lockG = 212;
|
||||
|
||||
@@ -91,6 +91,14 @@ class RageVehicle extends RageEntity implements IVehicle {
|
||||
setDoorsLocked(state: boolean) {
|
||||
this.vehicle.setDoorsLocked(state ? 2 : 1);
|
||||
}
|
||||
|
||||
setDoorOpen(door: number, loose: boolean, instantly: boolean) {
|
||||
this.vehicle.setDoorOpen(door, loose, instantly);
|
||||
}
|
||||
|
||||
setDoorShut(door: number, instantly: boolean) {
|
||||
this.vehicle.setDoorShut(door, instantly);
|
||||
}
|
||||
}
|
||||
|
||||
class RageVehiclePool implements IVehiclePool {
|
||||
|
||||
@@ -56,6 +56,8 @@ interface IVehicle extends IEntity {
|
||||
setEngineStatus(status: boolean, instantly: boolean, otherwise: boolean);
|
||||
setUndriveable(status: boolean);
|
||||
setDoorsLocked(state: boolean);
|
||||
setDoorShut(door: number, instantly: boolean);
|
||||
setDoorOpen(door: number, loose: boolean, instantly: boolean);
|
||||
}
|
||||
|
||||
interface IEntityPool<TEntity> {
|
||||
@@ -88,6 +90,14 @@ interface AccountData {
|
||||
interface VehicleData {
|
||||
EngineState: boolean;
|
||||
Locked: boolean;
|
||||
|
||||
Doors: { [door: number]: number };
|
||||
}
|
||||
|
||||
enum DoorState {
|
||||
DoorClosed,
|
||||
DoorOpen,
|
||||
DoorBroken,
|
||||
}
|
||||
|
||||
enum EventName {
|
||||
@@ -133,5 +143,6 @@ export {
|
||||
VehicleSeat,
|
||||
EntityType,
|
||||
AccountData,
|
||||
VehicleData
|
||||
VehicleData,
|
||||
DoorState
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import game, { VehicleData } from '../index';
|
||||
import { IVehicle, EntityType, IEntity, VehicleSeat } from '../game';
|
||||
import game from '../index';
|
||||
import { IVehicle, EntityType, IEntity, VehicleSeat, DoorState } from '../game';
|
||||
import { parseJson } from '../util';
|
||||
import { VehicleData } from '../game';
|
||||
|
||||
game.events.add('SERVER:Vehicle:UpdateData', (vehId, dataStr) => {
|
||||
var data: VehicleData = parseJson(dataStr);
|
||||
@@ -48,10 +49,11 @@ function setVehicleData(veh: IVehicle, data: VehicleData): void {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data === null) {
|
||||
if (!data) {
|
||||
data = {
|
||||
EngineState: false,
|
||||
Locked: false
|
||||
Locked: false,
|
||||
Doors: {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,6 +66,19 @@ function setVehicleData(veh: IVehicle, data: VehicleData): void {
|
||||
veh.setUndriveable(!engineState);
|
||||
}
|
||||
|
||||
var doors = Object.keys(data.Doors);
|
||||
|
||||
doors.forEach(door => {
|
||||
var doorNumber = parseInt(door);
|
||||
var doorState = <number>data.Doors[doorNumber];
|
||||
|
||||
if (doorState === DoorState.DoorOpen.valueOf()) {
|
||||
veh.setDoorOpen(doorNumber, false, false);
|
||||
} else if (doorState === DoorState.DoorClosed.valueOf()) {
|
||||
veh.setDoorShut(doorNumber, false);
|
||||
}
|
||||
});
|
||||
|
||||
var locked: boolean = data.Locked;
|
||||
veh.setDoorsLocked(locked);
|
||||
}
|
||||
@@ -9,5 +9,62 @@ namespace ReallifeGamemode.Server.Types
|
||||
public bool EngineState { get; set; }
|
||||
|
||||
public bool Locked { get; set; }
|
||||
|
||||
public Dictionary<int, int> Doors { get; set; } = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
public enum WindowID
|
||||
{
|
||||
WindowFrontRight,
|
||||
WindowFrontLeft,
|
||||
WindowRearRight,
|
||||
WindowRearLeft
|
||||
}
|
||||
|
||||
public enum WindowState
|
||||
{
|
||||
WindowFixed,
|
||||
WindowDown,
|
||||
WindowBroken
|
||||
}
|
||||
|
||||
public enum DoorID
|
||||
{
|
||||
DoorFrontLeft,
|
||||
DoorFrontRight,
|
||||
DoorRearLeft,
|
||||
DoorRearRight,
|
||||
DoorHood,
|
||||
DoorTrunk,
|
||||
DoorBack,
|
||||
DoorBack2
|
||||
}
|
||||
|
||||
public enum DoorState
|
||||
{
|
||||
DoorClosed,
|
||||
DoorOpen,
|
||||
DoorBroken,
|
||||
}
|
||||
|
||||
public enum WheelID
|
||||
{
|
||||
Wheel0,
|
||||
Wheel1,
|
||||
Wheel2,
|
||||
Wheel3,
|
||||
Wheel4,
|
||||
Wheel5,
|
||||
Wheel6,
|
||||
Wheel7,
|
||||
Wheel8,
|
||||
Wheel9
|
||||
}
|
||||
|
||||
public enum WheelState
|
||||
{
|
||||
WheelFixed,
|
||||
WheelBurst,
|
||||
WheelOnRim,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -10,6 +10,7 @@ using ReallifeGamemode.Server.Inventory.Interfaces;
|
||||
using ReallifeGamemode.Server.Managers;
|
||||
using ReallifeGamemode.Server.Util;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
|
||||
bool unloadedWeaponPackage = false;
|
||||
|
||||
List<UserItem> fItem = context.UserItems.Where(u => u.UserId == user.Id).ToList();
|
||||
foreach (var item in fItem)
|
||||
@@ -309,6 +309,11 @@ namespace ReallifeGamemode.Server.Events
|
||||
}
|
||||
context.SaveChanges();
|
||||
|
||||
if (unloadedWeaponPackage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<FactionWeapon> weapons = context.FactionWeapons.Where(w => w.FactionId == user.FactionId).ToList();
|
||||
Database.Entities.Faction faction = context.Factions.Where(fac => fac.Id == user.FactionId).FirstOrDefault();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Services;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Managers InventoryManager (InventoryManager.cs)
|
||||
|
||||
@@ -749,6 +749,11 @@ namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
NAPI.Pools.GetAllVehicles().ForEach(v =>
|
||||
{
|
||||
if (v.Handle.Value == 0 || v.Handle == default)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 lastPosition = v.Position;
|
||||
if (lastPositions.ContainsKey(v.Handle)) lastPosition = lastPositions[v.Handle];
|
||||
lastPositions[v.Handle] = v.Position;
|
||||
|
||||
@@ -1,459 +1,81 @@
|
||||
using System;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using ReallifeGamemode.Server.Common;
|
||||
|
||||
namespace ReallifeGamemode.Server.Util
|
||||
{
|
||||
//Enums for ease of use
|
||||
public enum WindowID
|
||||
{
|
||||
WindowFrontRight,
|
||||
WindowFrontLeft,
|
||||
WindowRearRight,
|
||||
WindowRearLeft
|
||||
}
|
||||
|
||||
public enum WindowState
|
||||
{
|
||||
WindowFixed,
|
||||
WindowDown,
|
||||
WindowBroken
|
||||
}
|
||||
|
||||
public enum DoorID
|
||||
{
|
||||
DoorFrontLeft,
|
||||
DoorFrontRight,
|
||||
DoorRearLeft,
|
||||
DoorRearRight,
|
||||
DoorHood,
|
||||
DoorTrunk
|
||||
}
|
||||
|
||||
public enum DoorState
|
||||
{
|
||||
DoorClosed,
|
||||
DoorOpen,
|
||||
DoorBroken,
|
||||
}
|
||||
|
||||
public enum WheelID
|
||||
{
|
||||
Wheel0,
|
||||
Wheel1,
|
||||
Wheel2,
|
||||
Wheel3,
|
||||
Wheel4,
|
||||
Wheel5,
|
||||
Wheel6,
|
||||
Wheel7,
|
||||
Wheel8,
|
||||
Wheel9
|
||||
}
|
||||
|
||||
public enum WheelState
|
||||
{
|
||||
WheelFixed,
|
||||
WheelBurst,
|
||||
WheelOnRim,
|
||||
}
|
||||
|
||||
public class VehicleStreaming : Script
|
||||
{
|
||||
//This is the data object which will be synced to vehicles
|
||||
public class VehicleSyncData
|
||||
private const string DataKey = "VehicleData";
|
||||
|
||||
public static void SetEngineState(Vehicle veh, bool state)
|
||||
{
|
||||
//Used to bypass some streaming bugs
|
||||
public Vector3 Position { get; set; } = new Vector3();
|
||||
public Vector3 Rotation { get; set; } = new Vector3();
|
||||
|
||||
//Basics
|
||||
public float Dirt { get; set; } = 0.0f;
|
||||
public bool Locked { get; set; } = true;
|
||||
public bool Engine { get; set; } = false;
|
||||
|
||||
//(Not synced)
|
||||
//public float BodyHealth { get; set; } = 1000.0f;
|
||||
//public float EngineHealth { get; set; } = 1000.0f;
|
||||
|
||||
//Doors 0-7 (0 = closed, 1 = open, 2 = broken) (This uses enums so don't worry about it)
|
||||
public int[] Door { get; set; } = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
//Windows (0 = up, 1 = down, 2 = smashed) (This uses enums so don't worry about it)
|
||||
public int[] Window { get; set; } = new int[4] { 0, 0, 0, 0 };
|
||||
|
||||
//Wheels 0-7, 45/47 (0 = fixed, 1 = flat, 2 = missing) (This uses enums so don't worry about it)
|
||||
public int[] Wheel { get; set; } = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
//API functions for people to use
|
||||
public static void SetVehicleWindowState(Vehicle veh, WindowID window, WindowState state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData)) //If data doesn't exist create a new one. This is the process for all API functions
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Window[(int)window] = (int)state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWindowStatus_Single", veh.Handle, (int)window, (int)state);
|
||||
}
|
||||
|
||||
public static WindowState GetVehicleWindowState(Vehicle veh, WindowID window)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return (WindowState)data.Window[(int)window];
|
||||
}
|
||||
|
||||
public static void SetVehicleWheelState(Vehicle veh, WheelID wheel, WheelState state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Wheel[(int)wheel] = (int)state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWheelStatus_Single", veh.Handle, (int)wheel, (int)state);
|
||||
}
|
||||
|
||||
public static WheelState GetVehicleWheelState(Vehicle veh, WheelID wheel)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return (WheelState)data.Wheel[(int)wheel];
|
||||
}
|
||||
|
||||
public static void SetVehicleDirt(Vehicle veh, float dirt)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Dirt = dirt;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
|
||||
}
|
||||
|
||||
public static float GetVehicleDirt(Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return data.Dirt;
|
||||
}
|
||||
|
||||
public static void SetDoorState(Vehicle veh, DoorID door, DoorState state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Door[(int)door] = (int)state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus_Single", veh, (int)door, (int)state);
|
||||
}
|
||||
|
||||
public static DoorState GetDoorState(Vehicle veh, DoorID door)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return (DoorState)data.Door[(int)door];
|
||||
}
|
||||
|
||||
public static void SetEngineState(Vehicle veh, bool status)
|
||||
{
|
||||
veh.EngineStatus = status;
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Engine = status;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetEngineStatus", veh, status);
|
||||
var data = GetData(veh);
|
||||
data.EngineState = state;
|
||||
SetData(veh, data);
|
||||
}
|
||||
|
||||
public static bool GetEngineState(Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return veh.EngineStatus;
|
||||
return GetData(veh).EngineState;
|
||||
}
|
||||
|
||||
public static void SetLockStatus(Vehicle veh, bool status)
|
||||
public static void SetLockStatus(Vehicle veh, bool state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Locked = status;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetLockStatus", veh, status);
|
||||
NAPI.Pools.GetAllPlayers().ForEach(p =>
|
||||
{
|
||||
if (p.IsInVehicle && p.Vehicle.Handle == veh.Handle)
|
||||
{
|
||||
p.TriggerEvent("Vehicle_setLockStatus", status);
|
||||
}
|
||||
});
|
||||
var data = GetData(veh);
|
||||
data.Locked = state;
|
||||
SetData(veh, data);
|
||||
}
|
||||
|
||||
public static bool GetLockState(Vehicle veh)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
{
|
||||
data = new VehicleSyncData();
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
}
|
||||
return data.Locked;
|
||||
return GetData(veh).Locked;
|
||||
}
|
||||
|
||||
//Used internally only but publicly available in case any of you need it
|
||||
public static VehicleSyncData GetVehicleSyncData(Vehicle veh)
|
||||
public static void SetDoorState(Vehicle veh, DoorID door, DoorState state)
|
||||
{
|
||||
if (veh != null)
|
||||
{
|
||||
if (NAPI.Entity.DoesEntityExist(veh))
|
||||
{
|
||||
if (NAPI.Data.HasEntitySharedData(veh, "VehicleSyncData"))
|
||||
{
|
||||
try
|
||||
{
|
||||
//API converts class objects to JObject so we have to change it back
|
||||
JObject obj = (JObject)NAPI.Data.GetEntitySharedData(veh, "VehicleSyncData");
|
||||
return obj.ToObject<VehicleSyncData>();
|
||||
}
|
||||
catch (Exception) { return null; }
|
||||
}
|
||||
}
|
||||
VehicleData data = GetData(veh);
|
||||
|
||||
data.Doors[(int)door] = (int)state;
|
||||
|
||||
SetData(veh, data);
|
||||
}
|
||||
|
||||
return default; //null
|
||||
public static DoorState GetDoorState(Vehicle veh, DoorID door)
|
||||
{
|
||||
VehicleData data = GetData(veh);
|
||||
|
||||
if (!data.Doors.ContainsKey((int)door))
|
||||
{
|
||||
return DoorState.DoorClosed;
|
||||
}
|
||||
|
||||
//Used internally only but publicly available in case any of you need it
|
||||
public static bool UpdateVehicleSyncData(Vehicle veh, VehicleSyncData data)
|
||||
{
|
||||
if (veh != null)
|
||||
{
|
||||
if (NAPI.Entity.DoesEntityExist(veh))
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
data.Position = veh.Position;
|
||||
data.Rotation = veh.Rotation;
|
||||
NAPI.Data.SetEntitySharedData(veh, "VehicleSyncData", data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return (DoorState)data.Doors[(int)door];
|
||||
}
|
||||
|
||||
public static void SetVehicleRotation(Vehicle veh, VehicleSyncData data, Vector3 rot)
|
||||
public static VehicleData GetData(Vehicle veh)
|
||||
{
|
||||
if (veh != null)
|
||||
if (!veh.HasSharedData(DataKey))
|
||||
{
|
||||
if (NAPI.Entity.DoesEntityExist(veh))
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
data.Rotation = rot;
|
||||
NAPI.Data.SetEntitySharedData(veh, "VehicleSyncData", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new VehicleData();
|
||||
}
|
||||
|
||||
//Called from the client to sync dirt level
|
||||
[RemoteEvent("VehStream_SetDirtLevel")]
|
||||
public void VehStreamSetDirtLevel(Player player, Vehicle veh, float dirt)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Dirt = dirt;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDirtLevel", veh.Handle, dirt);
|
||||
return veh.GetSharedData<string>(DataKey).DeserializeJson<VehicleData>();
|
||||
}
|
||||
|
||||
//Called from the client to sync door data
|
||||
[RemoteEvent("VehStream_SetDoorData")]
|
||||
public void VehStreamSetDoorData(Player player, Vehicle veh, int door1state, int door2state, int door3state, int door4state, int door5state, int door6state, int door7state, int door8state)
|
||||
public static void SetData(Vehicle veh, VehicleData data)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Door[0] = door1state;
|
||||
data.Door[1] = door2state;
|
||||
data.Door[2] = door3state;
|
||||
data.Door[3] = door4state;
|
||||
data.Door[4] = door5state;
|
||||
data.Door[5] = door6state;
|
||||
data.Door[6] = door7state;
|
||||
data.Door[7] = door8state;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus", veh.Handle, door1state, door2state, door3state, door4state, door5state, door6state, door7state, door8state);
|
||||
if (data is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
|
||||
//Called from the client to sync window data
|
||||
[RemoteEvent("VehStream_SetWindowData")]
|
||||
public void VehStreamSetWindowData(Player player, Vehicle veh, int window1state, int window2state, int window3state, int window4state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
var dataStr = data.SerializeJson();
|
||||
|
||||
data.Window[0] = window1state;
|
||||
data.Window[1] = window2state;
|
||||
data.Window[2] = window3state;
|
||||
data.Window[3] = window4state;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWindowStatus", veh.Handle, window1state, window2state, window3state, window4state);
|
||||
}
|
||||
|
||||
//Called from the client to sync wheel data
|
||||
[RemoteEvent("VehStream_SetWheelData")]
|
||||
public void VehStreamSetWheelData(Player player, Vehicle veh, int wheel1state, int wheel2state, int wheel3state, int wheel4state, int wheel5state, int wheel6state, int wheel7state, int wheel8state, int wheel9state, int wheel10state)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Wheel[0] = wheel1state;
|
||||
data.Wheel[1] = wheel2state;
|
||||
data.Wheel[2] = wheel3state;
|
||||
data.Wheel[3] = wheel4state;
|
||||
data.Wheel[4] = wheel5state;
|
||||
data.Wheel[5] = wheel6state;
|
||||
data.Wheel[6] = wheel7state;
|
||||
data.Wheel[7] = wheel8state;
|
||||
data.Wheel[8] = wheel9state;
|
||||
data.Wheel[9] = wheel10state;
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
//Re-distribute the goods
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleWheelStatus", veh.Handle, wheel1state, wheel2state, wheel3state, wheel4state, wheel5state, wheel6state, wheel7state, wheel8state, wheel9state, wheel10state);
|
||||
}
|
||||
|
||||
//Other events
|
||||
[ServerEvent(Event.PlayerEnterVehicleAttempt)]
|
||||
public void VehStreamEnterAttempt(Player player, Vehicle veh, sbyte seat)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerEnterVehicleAttempt", veh.Handle.Value, seat);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerExitVehicleAttempt)]
|
||||
public void VehStreamExitAttempt(Player player, Vehicle veh)
|
||||
{
|
||||
|
||||
if (player.HasData("isDead") && player.GetData<bool>("isDead"))
|
||||
return;
|
||||
|
||||
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Position = veh.Position;
|
||||
data.Rotation = veh.Rotation;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerExitVehicleAttempt", veh);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerExitVehicle)]
|
||||
public void VehStreamExit(Player player, Vehicle veh)
|
||||
{
|
||||
if (player.HasData("isDead") && player.GetData<bool>("isDead"))
|
||||
return;
|
||||
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Position = veh.Position;
|
||||
data.Rotation = veh.Rotation;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerExitVehicle", veh.Handle.Value);
|
||||
}
|
||||
|
||||
[ServerEvent(Event.PlayerEnterVehicle)]
|
||||
public void VehStreamEnter(Player player, Vehicle veh, sbyte seat)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
NAPI.ClientEvent.TriggerClientEvent(player, "VehStream_PlayerEnterVehicle", veh, seat);
|
||||
player.TriggerEvent("Vehicle_setLockStatus", data.Locked);
|
||||
}
|
||||
|
||||
//[ServerEvent(Event.VehicleDamage)]
|
||||
//public void VehDamage(Vehicle veh, float bodyHealthLoss, float engineHealthLoss)
|
||||
//{
|
||||
// VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
// if (data == default(VehicleSyncData))
|
||||
// data = new VehicleSyncData();
|
||||
|
||||
// data.BodyHealth -= bodyHealthLoss;
|
||||
// data.EngineHealth -= engineHealthLoss;
|
||||
|
||||
// UpdateVehicleSyncData(veh, data);
|
||||
|
||||
// if (NAPI.Vehicle.GetVehicleDriver(veh) != default(Player)) //Doesn't work?
|
||||
// NAPI.ClientEvent.TriggerClientEvent(NAPI.Vehicle.GetVehicleDriver(veh), "VehStream_PlayerExitVehicleAttempt", veh);
|
||||
//}
|
||||
|
||||
[ServerEvent(Event.VehicleDoorBreak)]
|
||||
public void VehDoorBreak(Vehicle veh, int index)
|
||||
{
|
||||
VehicleSyncData data = GetVehicleSyncData(veh);
|
||||
if (data == default(VehicleSyncData))
|
||||
data = new VehicleSyncData();
|
||||
|
||||
data.Door[index] = 2;
|
||||
|
||||
UpdateVehicleSyncData(veh, data);
|
||||
|
||||
NAPI.ClientEvent.TriggerClientEventInDimension(veh.Dimension, "VehStream_SetVehicleDoorStatus", veh.Handle, data.Door[0], data.Door[1], data.Door[2], data.Door[3], data.Door[4], data.Door[5], data.Door[6], data.Door[7]);
|
||||
veh.SetSharedData(DataKey, dataStr);
|
||||
NAPI.ClientEvent.TriggerClientEventForAll("SERVER:Vehicle:UpdateData", veh.Handle.Value, dataStr);
|
||||
}
|
||||
|
||||
// INDICATORS
|
||||
|
||||
@@ -86,13 +86,20 @@ namespace ReallifeGamemode.Server.WeaponDeal
|
||||
User user = client.GetUser();
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
FactionVehicle factionVehicle = context.FactionVehicles.ToList().Where(f => f.GetOwners().Contains(user.FactionId ?? 0) && f.Model == VehicleHash.Burrito3).FirstOrDefault();
|
||||
FactionVehicle factionVehicle = context.FactionVehicles
|
||||
.Where(f => f.Model == VehicleHash.Burrito3 || f.Model == VehicleHash.Policet)
|
||||
.ToList()
|
||||
.Where(f => f.GetOwners().Contains(user.FactionId ?? 0))
|
||||
.FirstOrDefault();
|
||||
|
||||
Vehicle fVeh = VehicleManager.GetVehicleFromServerVehicle(factionVehicle);
|
||||
fVeh.SetData("weaponDeal", false);
|
||||
fVeh.SetData("WeaponDealLoad", true);
|
||||
InventoryManager.RemoveAllItemsfromVehicleInventory(fVeh);
|
||||
Random rnd = new Random();
|
||||
if (factionVehicle.GetOwners().Contains(8) || factionVehicle.GetOwners().Contains(7))
|
||||
var owners = factionVehicle.GetOwners();
|
||||
|
||||
if (owners.Contains(8) || owners.Contains(7))
|
||||
{
|
||||
VehicleItem item = new VehicleItem() { ItemId = 11, VehicleId = factionVehicle.Id, Amount = rnd.Next(45, 75) }; //pistole
|
||||
InventoryManager.AddItemToVehicleInventory(client, item, fVeh);
|
||||
|
||||
Reference in New Issue
Block a user