[C#][FXServer] Id to player


I’m trying to work on a script that when you type /ragdoll into chat it would ragdoll the player’s ped until they type /ragdoll again. I’m using CitizenFX.Core for both server and client side.


For some reason I can’t figure out a way to obtain a Player from the id that it gives me on the chatMessage event. There is no method for it, I couldn’t make my own (by using a foreach to list out the IDs and then check each ID individually) because the Player class has no ServerId parameter. I also looked through the identifiers but that only returned the IP and the steam hex. I also tried using a native called GET_PLAYER_FROM_SERVER_ID but that turned out to be only client side and would crash my script.


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(' ');
            if (args[0] == "/ragdoll")
                // Triggers for everyone because I can't get the player!

add source to your TriggerClientEvent parameter
You can also catch it client side and keep it, rather than GET_PLAYER_SERVER_ID()

I had the same exact issue. chatMessage won’t return the player object, just the id. Here’s the “fix”.


Of course it would be something like that. I honestly thought that it would check for the index and not the netId. Thanks for your topic.