Add AnimationSync
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import { IGame } from './game';
|
||||
import RageGame from './core/rage-mp/game';
|
||||
|
||||
|
||||
var inMenu: boolean = false;
|
||||
|
||||
let globalData: IGlobalData = {
|
||||
@@ -224,7 +223,6 @@ refuseCollector();
|
||||
import PedCreator from './Ped/PedCreator';
|
||||
PedCreator();
|
||||
|
||||
|
||||
import attachmentManager from './util/attachmentMngr';
|
||||
attachmentManager(game);
|
||||
|
||||
@@ -235,14 +233,12 @@ import bankMenuHandle from './Interaction/bankmenu';
|
||||
import InputHelper from './inputhelper';
|
||||
bankMenuHandle(globalData);
|
||||
|
||||
|
||||
import ahelp from './Gui/ahelp';
|
||||
ahelp(globalData);
|
||||
|
||||
import Introduction from './Gui/introduction';
|
||||
Introduction(globalData);
|
||||
|
||||
|
||||
import userhelp from './Gui/userhelp';
|
||||
userhelp(globalData);
|
||||
|
||||
@@ -252,6 +248,9 @@ drivingschool(globalData);
|
||||
import gangwarHandle from './util/Gangwar';
|
||||
gangwarHandle(globalData);
|
||||
|
||||
import animationSync from './util/animationSync';
|
||||
animationSync();
|
||||
|
||||
require('./Gui/policedepartment');
|
||||
require('./Gui/helptext');
|
||||
|
||||
@@ -263,5 +262,3 @@ interface VehicleData {
|
||||
export {
|
||||
VehicleData
|
||||
}
|
||||
|
||||
|
||||
|
||||
85
ReallifeGamemode.Client/util/animationSync.ts
Normal file
85
ReallifeGamemode.Client/util/animationSync.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
export default function animationSync() {
|
||||
mp.events.add("SERVER:LoadAnimations", () => {
|
||||
animationSync.register("Cuffed", "mp_arresting", "idle", true, true, 0);
|
||||
animationSync.register("ArrestCop", "mp_arrest_paired", "cop_p2_back_right", false, false, 0);
|
||||
animationSync.register("ArrestCrook", "mp_arrest_paired", "crook_p2_back_right", false, false, 0);
|
||||
});
|
||||
|
||||
const animationSync =
|
||||
{
|
||||
animations: [],
|
||||
|
||||
playAnim: function (entity, _id) {
|
||||
if (this.animations.hasOwnProperty(_id)) {
|
||||
let currentAnim = this.animations[_id];
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = currentAnim;
|
||||
|
||||
loadAnimDict(animDict, function () {
|
||||
mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, -1, parseInt(flag), 1, !1, !1, !1)
|
||||
});
|
||||
entity.animationData = { name: name, playOnStream: playOnStream };
|
||||
}
|
||||
},
|
||||
stopAnim: function (entity: PlayerMp) {
|
||||
if (!entity.animationData)
|
||||
return;
|
||||
|
||||
var currAnim = this.animations.find(anim => anim.name == entity.animationData.name);
|
||||
if (currAnim) {
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = currAnim;
|
||||
|
||||
entity.stopAnimTask(animDict, animName, 3);
|
||||
entity.animationData = null;
|
||||
}
|
||||
},
|
||||
|
||||
register: function (name, animDict, animName, playOnStream, loop, flag) {
|
||||
let id = mp.game.joaat(name);
|
||||
|
||||
if (!this.animations.hasOwnProperty(id)) {
|
||||
this.animations[id] =
|
||||
{
|
||||
id: id,
|
||||
name: name,
|
||||
animDict: animDict,
|
||||
animName: animName,
|
||||
playOnStream: playOnStream,
|
||||
loop: loop,
|
||||
flag: flag
|
||||
};
|
||||
} else {
|
||||
mp.game.graphics.notify("Animation Sync Error: ~r~Duplicate Entry");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mp.events.add("entityStreamIn", (entity) => {
|
||||
if (entity.type === "player" && entity.animationData) {
|
||||
if (!entity.animationData.playOnStream)
|
||||
return;
|
||||
animationSync.playAnim(entity, entity.animationData.name);
|
||||
}
|
||||
});
|
||||
|
||||
mp.events.addDataHandler("AnimationData", (entity: PlayerMp, string) => {
|
||||
let data = string ? string : "";
|
||||
|
||||
animationSync.stopAnim(entity);
|
||||
|
||||
let animData = animationSync.animations.find(anim => anim.name == data);
|
||||
if (!animData)
|
||||
return;
|
||||
|
||||
let { id, name, animDict, animName, playOnStream, loop, flag } = animData;
|
||||
entity.animationData = { name: name, playOnStream: playOnStream };
|
||||
animationSync.playAnim(entity, id)
|
||||
});
|
||||
|
||||
function loadAnimDict(animDict, callback) {
|
||||
if (mp.game.streaming.hasAnimDictLoaded(animDict)) return void callback();
|
||||
mp.game.streaming.requestAnimDict(animDict);
|
||||
let c = setInterval(function () {
|
||||
mp.game.streaming.hasAnimDictLoaded(animDict) && (clearInterval(c), callback())
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,17 @@ namespace ReallifeGamemode.Server.Commands
|
||||
{
|
||||
#region Todo
|
||||
|
||||
[Command("syncanim", "~m~Benutzung: ~s~/anim [animName]")]
|
||||
public void CmdSncAnim(Player player, string animName)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.SUPPORTER) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
player.PlaySyncAnimation(animName);
|
||||
}
|
||||
|
||||
[Command("anim", "~m~Benutzung: ~s~/anim [animDict] [animName]")]
|
||||
public void CmdAnim(Player player, string animDict, string animName)
|
||||
{
|
||||
@@ -43,11 +54,8 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
NAPI.Player.PlayPlayerAnimation(player, (int)(AnimationFlags.Loop | AnimationFlags.AllowPlayerControl | AnimationFlags.Cancellable), animDict, animName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Command("eat", "~m~Benutzung: ~s~/eat [Item]")]
|
||||
public void CmdAdminEat(Player player, string item)
|
||||
{
|
||||
@@ -144,36 +152,38 @@ namespace ReallifeGamemode.Server.Commands
|
||||
|
||||
#region ahelp
|
||||
|
||||
/* [Command("ahelp", "~m~Benutzung: ~s~/ahelp")]
|
||||
public void CmdAdminHelp(Player player)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.MAPPING) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (player.GetUser().AdminLevel)
|
||||
{
|
||||
case AdminLevel.MAPPING:
|
||||
ChatService.SendMessage(player, "~b~ " + "/team, /tc, /position");
|
||||
break;
|
||||
/* [Command("ahelp", "~m~Benutzung: ~s~/ahelp")]
|
||||
public void CmdAdminHelp(Player player)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.MAPPING) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (player.GetUser().AdminLevel)
|
||||
{
|
||||
case AdminLevel.MAPPING:
|
||||
ChatService.SendMessage(player, "~b~ " + "/team, /tc, /position");
|
||||
break;
|
||||
|
||||
case AdminLevel.SUPPORTER:
|
||||
player.TriggerEvent("showShelp");
|
||||
break;
|
||||
case AdminLevel.SUPPORTER:
|
||||
player.TriggerEvent("showShelp");
|
||||
break;
|
||||
|
||||
case AdminLevel.ADMIN:
|
||||
player.TriggerEvent("showAhelp");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
case AdminLevel.ADMIN:
|
||||
player.TriggerEvent("showAhelp");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
#endregion ahelp
|
||||
|
||||
#region Mapping / Entwicklung
|
||||
|
||||
[Command("team", "~m~Benutzung: ~s~/team")]
|
||||
public void CmdAdminTeam(Player player)
|
||||
{
|
||||
@@ -234,7 +244,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
switch (typ.ToLower())
|
||||
{
|
||||
case "ip":
|
||||
if(player.HasData("togip"))
|
||||
if (player.HasData("togip"))
|
||||
{
|
||||
player.ResetData("togip");
|
||||
player.SendNotification("~g~[Info]~w~ Ip´s werden nun ausgeblendet.");
|
||||
@@ -258,6 +268,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.SendNotification("~g~[Info]~w~ Deathlogs werden nun angezeigt.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "lc":
|
||||
if (player.HasData("toglc"))
|
||||
{
|
||||
@@ -299,6 +310,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
user.SetBlipAndNametagColor();
|
||||
}
|
||||
|
||||
[Command("aduty", "~m~Benutzung: ~s~/aduty")]
|
||||
public void CmdAdminAduty(Player player)
|
||||
{
|
||||
@@ -314,11 +326,10 @@ namespace ReallifeGamemode.Server.Commands
|
||||
ChatService.Broadcast("~g~[SUPPORT] " + player.Name + " hat sich zum Support angemeldet");
|
||||
|
||||
player.TriggerEvent("toggleADutyMode", true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(player.GetData<bool>("SAdminduty"))
|
||||
if (player.GetData<bool>("SAdminduty"))
|
||||
{
|
||||
CmdAdminTSupport(player);
|
||||
}
|
||||
@@ -467,8 +478,6 @@ namespace ReallifeGamemode.Server.Commands
|
||||
target.Kick();
|
||||
|
||||
ChatService.BroadcastAdmin("~y~SKICK: ~w~" + targetPlayername + " wurde von " + player.GetUser().AdminLevel.GetName() + " " + adminPlayername + " gekickt: " + reason, AdminLevel.SUPPORTER);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Command("clearchat", "~m~Benutzung: ~s~/clearchat")]
|
||||
@@ -784,8 +793,6 @@ namespace ReallifeGamemode.Server.Commands
|
||||
target.Kick();
|
||||
|
||||
ChatService.Broadcast("~y~INFO: ~w~" + targetPlayername + " wurde von " + player.GetUser().AdminLevel.GetName() + " " + adminPlayername + " gekickt: " + reason);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Command("warn", "~m~Benutzung: ~s~/warn [Player] [Grund]", GreedyArg = true)]
|
||||
@@ -811,7 +818,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
{
|
||||
User userwarn = player.GetUser(dbContext);
|
||||
|
||||
userwarn.warn ++;
|
||||
userwarn.warn++;
|
||||
dbContext.SaveChanges();
|
||||
if (userwarn.warn >= 3)
|
||||
{
|
||||
@@ -949,6 +956,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
else player.Position = new Vector3(p.X, p.Y, p.Z);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("destroyped", "~m~Benutzung: ~s~/destroyped [PedNr]")]
|
||||
public void CmdAdminAddPPed(Player player, int PedNr)
|
||||
{
|
||||
@@ -960,6 +968,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.TriggerEvent("CLIENT:DestroyPed", PedNr);
|
||||
//NAPI.Ped.CreatePed(PedHash.Bankman, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), player.Heading, dimension);
|
||||
}
|
||||
|
||||
[Command("addpped", "~m~Benutzung: ~s~/addpped [PedNr] [model] [dimension] [Dynamic] [Freezed] [Collision(0-3)] [Weapon] [AttackProof] [Fire/Explosion-Proof] [DrownProof]")]
|
||||
public void CmdAdminAddPPed(Player player, Array PedNr, string model, uint dimension = 0, bool dynamic = false, bool freeze = false, int collision = 0, string weapon = "none", bool attackproof = false, bool fireexplosionproof = false, bool drownproof = false)
|
||||
{
|
||||
@@ -971,6 +980,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.TriggerEvent("CLIENT:AddPed", PedNr, model, player.Position.X, player.Position.Y, player.Position.Z, player.Heading, dimension, dynamic, freeze, collision, weapon, attackproof, fireexplosionproof, drownproof);
|
||||
//NAPI.Ped.CreatePed(PedHash.Bankman, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), player.Heading, dimension);
|
||||
}
|
||||
|
||||
[Command("addmped", "~m~Benutzung: ~s~/addmped [model] [dimension]")]
|
||||
public void CmdAdminAddMPed(Player player, int model, uint dimension = 0)
|
||||
{
|
||||
@@ -982,6 +992,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.TriggerEvent("CLIENT:AddPedModel", model, player.Position.X, player.Position.Y, player.Position.Z, player.Heading, dimension);
|
||||
//NAPI.Ped.CreatePed(PedHash.Bankman, new Vector3(player.Position.X, player.Position.Y, player.Position.Z), player.Heading, dimension);
|
||||
}
|
||||
|
||||
[Command("addgped", "~m~Benutzung: ~s~/addgped")]
|
||||
public void CmdAdminAddGPed(Player player, int model, uint dimension = 0)
|
||||
{
|
||||
@@ -995,6 +1006,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
|
||||
//Peter.freezePosition(true);
|
||||
}
|
||||
|
||||
[Command("addgpedmore", "~m~Benutzung: ~s~/addgpedMore")]
|
||||
public void CmdAdminAddGPedMore(Player player, int model, uint dimension = 0)
|
||||
{
|
||||
@@ -1256,7 +1268,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
foreach (Vehicle v in vehiclesInRange)
|
||||
{
|
||||
ServerVehicle serverVehicle = VehicleManager.GetServerVehicleFromVehicle(v);
|
||||
if(serverVehicle == null)
|
||||
if (serverVehicle == null)
|
||||
{
|
||||
VehicleManager.DeleteVehicle(v);
|
||||
v.Trailer?.Delete();
|
||||
@@ -1687,6 +1699,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
#endregion Admin
|
||||
|
||||
#region ALevel1337
|
||||
|
||||
/*NUR ZUM TESTEN
|
||||
[Command("fakedeath", "~m~Benutzung:~s~ /fakedeath")]
|
||||
public void CmdAdmFakeDeath(Player player)
|
||||
@@ -1718,7 +1731,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
player.SetSharedData("blipColor", blipId);
|
||||
player.SetSharedData("blipColor", blipId);
|
||||
}
|
||||
|
||||
[Command("setsvar", "~m~Benutzung:~s~ /setsvar [ID] [WERT]")]
|
||||
@@ -2130,12 +2143,14 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.SendChatMessage("Modifier steht auf" + modifier);
|
||||
player.TriggerEvent("SERVER:WeaponModifier2", player, modifier, 1);
|
||||
}
|
||||
|
||||
[Command("wepmmod", "~m~Benutzung: ~s~/wepmmod [Variable]")]
|
||||
public void CmdWeaponMeeleModifier(Player player, float modifier)
|
||||
{
|
||||
player.SendChatMessage("MeeleModifier steht auf" + modifier);
|
||||
player.TriggerEvent("SERVER:WeaponModifier2", player, 1, modifier);
|
||||
}
|
||||
|
||||
[Command("gotocp", "~m~Benutzung: ~s~/gotocp")]
|
||||
public void CmdAdminGotocp(Player admin)
|
||||
{
|
||||
@@ -2454,8 +2469,8 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
|
||||
if (f == null)
|
||||
{
|
||||
@@ -2663,6 +2678,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.SetIntoVehicle(vehicle, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case "noobvehicle":
|
||||
if (player.IsInVehicle)
|
||||
{
|
||||
@@ -3056,6 +3072,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
player.TriggerEvent("manageFactionRanks", json);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("setdoor", "~m~Benutzung: ~s~/setdoor [open/shut] [Tür] [Boolean:Permanet] [Boolean:Lose]")]
|
||||
public void CmdAdminSetDoorOpen(Player player, string status, int door, bool permanent = false, bool lose = true)
|
||||
{
|
||||
@@ -3080,6 +3097,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command("aplaysound", "~m~Benutzung: ~s~/aplaysound [Dateiname] [mp3/wav] [volume 0.0 - 100.0]", Alias = "aps")]
|
||||
public void CmdAdminPlaySound(Player player, string sound, string typ, double volume = 100)
|
||||
{
|
||||
@@ -3090,6 +3108,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
player.TriggerEvent("CLIENT:PlaySound", sound, typ, volume);
|
||||
}
|
||||
|
||||
[Command("astopsound", "~m~Benutzung: ~s~/astopsound", Alias = "ass")]
|
||||
public void CmdAdminStopSound(Player player)
|
||||
{
|
||||
@@ -3100,6 +3119,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
player.TriggerEvent("CLIENT:StopSound");
|
||||
}
|
||||
|
||||
[Command("aspeed", "~m~Benutzung: ~s~/aspeed [Modifier1] [Modifier2]")] //TODO: Überarbeiten ?? SetPlayerVelocity ??
|
||||
public void CmdAdminAspeed(Player player, int modifier, int modifier2 = 1)
|
||||
{
|
||||
@@ -3521,13 +3541,13 @@ namespace ReallifeGamemode.Server.Commands
|
||||
public void CmdAdminCheckStats(Player player, string nameOrId)
|
||||
{
|
||||
User user = player.GetUser();
|
||||
if(!user.IsAdmin(AdminLevel.SUPPORTER))
|
||||
if (!user.IsAdmin(AdminLevel.SUPPORTER))
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
}
|
||||
|
||||
Player target = PlayerService.GetPlayerByNameOrId(nameOrId);
|
||||
if(target == null || !target.IsLoggedIn())
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
@@ -3543,7 +3563,6 @@ namespace ReallifeGamemode.Server.Commands
|
||||
ChatService.SendMessage(player, $"Stats von {target.Name} - HandMoney: {handmoney.ToMoneyString()}, BankMoney: {bankmoney.ToMoneyString()}, DriverLicense: {driverLicense.ToString()}, BikeLicense: {bikeLicense.ToString()}, FlyingLicense: {flyingLicense.ToString()}, WeaponLicense: {weaponLicense.ToString()}");
|
||||
}
|
||||
|
||||
|
||||
#endregion ALevel1337
|
||||
|
||||
#region ALevel1338
|
||||
@@ -3662,9 +3681,8 @@ namespace ReallifeGamemode.Server.Commands
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(player.HasData("Adminduty") && player.GetData<bool>("Adminduty"))
|
||||
player.TriggerEvent("ADMIN:NoClip");
|
||||
if (player.HasData("Adminduty") && player.GetData<bool>("Adminduty"))
|
||||
player.TriggerEvent("ADMIN:NoClip");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
34
ReallifeGamemode.Server/Util/AnimationSync.cs
Normal file
34
ReallifeGamemode.Server/Util/AnimationSync.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace ReallifeGamemode.Server.Util
|
||||
{
|
||||
public static class AnimationSync
|
||||
{
|
||||
public static void PlaySyncAnimation(this Player player, string animationName)
|
||||
{
|
||||
if (!player.HasData("Animation"))
|
||||
player.SetData("Animation", String.Empty);
|
||||
|
||||
string currentAnimation = player.GetData<string>("Animation");
|
||||
string newAnimation = animationName;
|
||||
|
||||
if (currentAnimation.Equals(newAnimation))
|
||||
return;
|
||||
|
||||
player.SetSharedData("AnimationData", newAnimation);
|
||||
}
|
||||
|
||||
public static void ClearAnimation(this Player player)
|
||||
{
|
||||
if (!player.HasData("Animation"))
|
||||
return;
|
||||
|
||||
player.ResetData("Animation");
|
||||
player.ResetSharedData("AnimationData");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user