So I was trying to make a script using the whole new server side C# scripting that is so amazing, and I see myself as a decent C# developer. When I made my script, it was working fine when I was by myself in the server and even when it was me and my friend. The only problem is that it seems like if there are 3 or more people in the server invoking the command crashes the entire resource and I need to restart it and it still crashes. I honestly have no idea what is going on and I can’t even read the stack trace. Can someone help me with the topic please!
stack trace:
Error invoking callback for event chatMessage: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Remoting.RemotingException: Server for uri '94f00adc_6926_464e_8368_4c8b38abf5a2/5767589_2.rem' not found
Server stack trace:
at System.Runtime.Remoting.Proxies.RealProxy.GetAppDomainTarget () [0x00031] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (object,byte[]&,byte[]&)
Exception rethrown at [0]:
at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)
at CitizenFX.Core.ScriptContext.InvokeInternal (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x0000c] in /src/code/client/clrcore/ScriptContext.cs:163
at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in /src/code/client/clrcore/ScriptContext.cs:156
at CitizenFX.Core.Native.Function.InvokeInternal (CitizenFX.Core.Native.Hash nativeHash, System.Type returnType, CitizenFX.Core.Native.InputArgument[] args) [0x00026] in /src/code/client/clrcore/Native.cs:28
at CitizenFX.Core.Native.Function.Call (CitizenFX.Core.Native.Hash hash, CitizenFX.Core.Native.InputArgument[] arguments) [0x00000] in /src/code/client/clrcore/Native.cs:16
at RagdollCMD.Server.RagdollCMD.OnChatMessage (System.Int32 source, System.String n, System.String message) [0x00032] in <9f53b56ab4b64d528622fca586365056>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <d7e663f2f7cd4ab6929018ec5233f09d>:0
at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00122] in /src/code/client/clrcore/EventHandlerDictionary.cs:144
Command 'ragdoll' entered..
server side:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.Native;
namespace RagdollCMD.Server
{
public class RagdollCMD : BaseScript
{
public RagdollCMD()
{
Debug.WriteLine("Ragdoll script by BlockBa5her started");
this.EventHandlers["chatMessage"] += new Action<int, string, string>(this.OnChatMessage);
}
public void OnChatMessage(int source, string n, string message)
{
string[] args = message.Split(' ');
Player p = this.Players[source];
if (args[0] == "/ragdoll")
{
TriggerClientEvent(p, "rcmd:Ragdoll");
}
else if (args[0] == "/cancelragdoll")
{
TriggerClientEvent(p, "rcmd:CancelRagdoll");
}
}
}
}
client side:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
namespace RagdollCMD.Client
{
public class RagdollCMD : BaseScript
{
bool isPedRagdoll = false;
bool cancelRagdoll = true;
Ped Char => this.LocalPlayer.Character;
public RagdollCMD()
{
this.EventHandlers.Add("rcmd:Ragdoll", new Action(() =>
{
isPedRagdoll = !isPedRagdoll;
if (isPedRagdoll)
TriggerEvent("chatMessage", "RagdollCMD", new[] { 0, 0, 0 }, "^2Now ragdolling");
else
{
TriggerEvent("rcmd:CancelRagdoll");
TriggerEvent("chatMessage", "RagdollCMD", new[] { 0, 0, 0 }, "^8No longer ragdolling");
}
}));
this.EventHandlers.Add("rcmd:CancelRagdoll", new Action(() =>
{
if (isPedRagdoll)
cancelRagdoll = true;
}));
this.Tick += this.OnTick;
}
private async Task OnTick()
{
if (this.isPedRagdoll && this.Char.IsInVehicle())
this.Char.Task.LeaveVehicle(LeaveVehicleFlags.LeaveDoorOpen);
if (this.isPedRagdoll)
if (this.Char.CanRagdoll)
this.Char.Ragdoll(1000, RagdollType.Normal);
if (this.cancelRagdoll)
{
this.isPedRagdoll = false;
this.cancelRagdoll = false;
this.Char.CancelRagdoll();
}
await Delay(5);
}
}
}