[C#] TriggerClientEvent 'player' does not exist

I’ve been following this tutorial, [How-to] Setting up C# and creating a basic resource however for some reason my project doesn’t find the “player” variable…

any suggestions? (adding [FromSource] to the argument doesn’t help)

Indeed, it doesn’t exist in that scope. Add the object Player to the playerSpawned Action.

Then in the parameters of the method add [FromSource]Player player.

The tutorial has only that one minor mistake.

the Vector3 looks incorrect as well, it compiles and the server registers the event, but apparently it fails to typecast into Vector3… what is the correct object for position? https://docs.fivem.net/events/client-events/ lists only “object”

Oh I just realized, of course there is no Player object because it’s a client sided code.

No need for any parameters. Although [FromSource]Vector3 pos I think does return the position that the spawnmanager spawned the player at.

Just do TriggerEvent("motd", "hello!");

actually this is the server side code - from what I understand, the server triggers an event for a specific player, doing triggerEvent would trigger the event for every player, no?

the problem is that the fiveM is unable to typecast the object returned by the spawner to the vector3

playerSpawned is a client sided event though. and yes, Vector3 doesn’t exist on the server side since that’s not what the server handles.

These are the only server sided events (by default) http://docs.fivem.net/events/server-events/

playerSpawned is a spawnmanager event (client-side) http://docs.fivem.net/events/client-events/#spawnmanager-events-resource-events

how can I then access the spawnInfo from the documentation in the playerSpawned event?

You access the event client side. If you want to send the info to the server you’d have to pass on each individual vector.

i.e.

Vector3 pos = new Vector3(0,1,2);
TriggerServerEvent("myEvent", pos.X, pos.Y, pos.Z)

I’m lost… it’s been working 10 minutes ago, now I get this…

the server code: https://pastebin.com/ekN5r4NM (I have no idea how to properly format code here)

Looks like you are missing some parameters for the playerSpawned callback as seen here:
http://docs.fivem.net/events/client-events/#spawnmanager-events-resource-events

      private void PlayerSpawned(dynamic spawnInfo)
      {
            TriggerEvent("motd", "Hello!");
      }

awww, I wanted the spawnInfo, thanks!

but the last issue was that I forgot to turn off the server that had faulty code (I tried to TriggerClientEvent without player after I got the first code working)

still… since in the tutorial there’s a boolean variable to check whether the user has saw the MOTD, I believe that the TriggerEvent will send MOTD to everyone after a player connects, right? so the TriggerEvent triggers a serverside event, not client side… I can’t test it, but it seems like it makes sense

Tutorial is wrong indeed, to be replaced soon :tm:

how do I access anything from the dynamic spawnInfo variable?

private void PlayerSpawned(dynamic spawnInfo)
{
     float x = spawnInfo.x;
     float y = spawnInfo.y;    
     float z = spawnInfo.z;
     float heading = spawnInfo.heading;
     int spawnpointIndex = spawnInfo.idx;
     uint model = spawnInfo.model;

     // Do something that needs to be done when playerSpawned event is triggered...
}
1 Like