Help with script (C#)

Please elaborate? :smiley:

Woops yea, forgot to inherit from BaseScript.

I just copy pasted his code.

Make sure you are using the right dll (server side) and inherit from BaseScript. This exposes you to the right classes.

@d0p3t i did. Now i get the error in console i posted before.

Project settings > debug > advanced > embedded

I think, but might be some other place but Iā€™ll have to check in Vishal studio once Iā€™ve got time.

@Vespura the problem here isā€¦ that my Visual Studio is in german :stuck_out_tongue:

Well yeah idk then, youā€™ll have to translate it.

@Vespura actually i know what these words mean in german, but in Visual Studio i just cant find themā€¦

Maybe you can tell me, what i have to tick, am i even in the right settings?

Yes indeed its under Project Settings -> Build -> Advanced -> Set debug information to embedded :smiley:

@Quetschlex show your full current code. I have a high suspicion your code is wrong.

Normally server and client would have the Player.Handle property, Iā€™m wondering why heā€™d get such an error. Maybe old binaries??

@d0p3t

using CitizenFX.Core;
using System.Threading.Tasks;

namespace NoFormatName
{
    public class Class1 : BaseScript
    {
        public Class1()
        {
            Tick += OnTick;
        }

        private async Task OnTick()
        {
            rescan:
            await Delay(300000);
            PlayerList players = new PlayerList();
            foreach (Player player in players)
            {
                if (player.Name.Contains("^1") || player.Name.Contains("^~") || player.Name.Contains("^2") || player.Name.Contains("^3") || player.Name.Contains("^4") || player.Name.Contains("^5") || player.Name.Contains("^6") || player.Name.Contains("^6") || player.Name.Contains("^7") || player.Name.Contains("^8") || player.Name.Contains("^9") || player.Name.Contains("^*") || player.Name.Contains("^_") || player.Name.Contains("^=") || player.Name.Contains("^*^"))
                {
                    int pID = player.ServerId;

                    Debug.WriteLine("clientkick " + pID + " Dein Name darf keine Formatierungs-Codes enthalten!");
                    Debug.WriteLine("say Der Spieler (ID: " + pID + ") wurde gekickt!");
                    goto rescan;
                }
                goto rescan;
            }
            goto rescan;
        }
    }
}

Why are you using rescan??? Take that out (see my code snippet).

This handler OnTick will run every tick.

@d0p3t so waitā€¦
if i do it like this:

using CitizenFX.Core;
using System.Threading.Tasks;

namespace NoFormatName
{
    public class Class1 : BaseScript
    {
        public Class1()
        {
            Tick += OnTick;
        }

        private async Task OnTick()
        {
            await Delay(300000);
            PlayerList players = new PlayerList();
            foreach (Player player in players)
            {
                if (player.Name.Contains("^1") || player.Name.Contains("^~") || player.Name.Contains("^2") || player.Name.Contains("^3") || player.Name.Contains("^4") || player.Name.Contains("^5") || player.Name.Contains("^6") || player.Name.Contains("^6") || player.Name.Contains("^7") || player.Name.Contains("^8") || player.Name.Contains("^9") || player.Name.Contains("^*") || player.Name.Contains("^_") || player.Name.Contains("^=") || player.Name.Contains("^*^"))
                {
                    int pID = player.ServerId;

                    Debug.WriteLine("clientkick " + pID + " Dein Name darf keine Formatierungs-Codes enthalten!");
                    Debug.WriteLine("say Der Spieler (ID: " + pID + ") wurde gekickt!");
                }
            }
        }
    }
}

will the code then still check every 5 minutes? And does it use more server-resources?

Yes exactly. A tick is exactly what it says. A server runs on a certain tick rate. And so does the client (usually similar to amount of frames).

Specifics for FiveM isnā€™t important but just now that when adding a tick to Tick ( like you do with OnTick in the constructor), it will runs OnTick every tick. Continuously. In this case this particular OnTick function will wait 300000ms until it continues.

@d0p3t couldnt i remove the delay then?

Then it wouldnā€™t check every 5 minutes

@d0p3t then it would check on every tick, right?
But with the delayā€¦ doesnt it start the delay on every tick then?

OnTick blocks until its done and then will run again

await Delay(300000) will pretty much skip 300000 ticks

@d0p3t ahh okay, thanks :wink:
but now: why do i get the error? Something wrong when i use player.ServerId and / or player.Handle dont they exist?

@Syntasu do i may need something else than the CitizenFX.Core.dll?