Crash on C# Native RequestModel, and LocalPlayer.ChangeModel

Latest build, Error is:

InvokeNative: execution failed: Error executing native 0x963d27a58df860ac at address 0x140ce627f.
[ 3557859] Unhandled exception: System.ArgumentException: Value does not fall within the expected range.

[ 3557859] at <0x00000 + 0x00000>
[ 3557859] GlobalError: Unhandled exception in Mono script environment: System.ArgumentException: Value does not fall within the expected range.

[ 3557859] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in :0 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in :0

Tried this using both the enum PedHash and GetHashKey(“a_m_m_bevhills_02”)

you can’t call natives from outside of the game’s thread context, what the hell are you doing (using await/similar on non-game objects?) that makes you end up on the threadpool?

ah, so that is why, how do you create a wait in c# that will work as the wait in lua then, i used a timer, bad idea i see now, but using thread.sleep in tick or a event locks the client until the wait is over. maybe im doing it wrong, i could not find a way to use the setautorespawn callback from C# so i basicly did the spawner in c#

await BaseScript.Delay(msec);

also, a random example of random spawns (in an onClientGameTypeStart event handler):

                // force navmesh to be loaded so we can get safe ped coords
                AddNavmeshRequiredRegion(1952.271f, 3887.118f, 1500.0f);

                while (!IsNavmeshLoadedInArea(1952.271f, 3887.118f, 0.0f, 2052.271f, 4287.118f, 100.0f))
                {
                    await Delay(0);
                }

                // set up spawning
                Exports["spawnmanager"].setAutoSpawn(true);
                Exports["spawnmanager"].setAutoSpawnCallback(new Action(() =>
                {
                    var rnd = new Random();

                    bool success = false;
                    Vector3 pos = Vector3.Zero;

                    int tries = 0;

                    do
                    {
                        var randX = rnd.Next(1142, 2117);
                        var randY = rnd.Next(3387, 4323);
                        var randZ = rnd.Next(10, 60);
                        success = GetSafeCoordForPed(randX, randY, randZ, false, ref pos, 16);

                        ++tries;

                        if (tries > 10)
                        {
                            pos = Vector3.Zero;
                            break;
                        }
                    } while (!success);

                    Exports["spawnmanager"].spawnPlayer(new
                    {
                        x = pos.X,
                        y = pos.Y,
                        z = pos.Z,
                        heading = 189.5f,
                        model = "mp_m_freemode_01"
                    }, new Action(() =>
                    {
                        PlayerSpawned?.Invoke();
                    }));
                }));

                Exports["spawnmanager"].forceRespawn();

Thank you :slight_smile: that explains everything i was confused about :smile:

I got one more question :slight_smile:

im trying to send over some data to the server to store it in the db, mostly the car mods installed so on, i dont send the class but a serialized string, the problem im getting is System.reflection equal function missing, im getting this when trying to deserialize on the client, everything works on the server, both serialize and deserialize. I also tried a 3rd party lib, Newtsoft.json with the same error.

Error invoking callback for event garage_setgarages: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.MethodAccessException: Error verifying System.Xml.Serialization.XmlSerializer:.ctor (System.Type,string): Method System.Reflection.Assembly:op_Equality (System.Reflection.Assembly,System.Reflection.Assembly) is not accessible at 0x008a

Got it working using a different Newtonsoft.Json, portable 4.0 sl5

Hello! I am just wondering what this refers to. Intellisense complains and gives me “The name ‘PlayerSpawned’ does not exist in the current context”. My code is the same as the example. Is this me missing something or intellisense being broken?

I second the previous post question…

PlayerSpawned?.Invoke();

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.