Customize SendClientMessageToAll function
#1

Hey, I've been trying and trying, but can't figure it out.
I am doing a custom SendClientMessageToAll function, but it just doesn't work.

My code is:
pawn Код:
stock AntiCheatKick(playerid, string[], reason[])
{
    new string[100];
    format(string, sizeof(string), "{A9FF63}[ANTI-CHEAT] {FFFFFF}%s has been kicked from the server. {9DFF8C}[REASON] {FFFFFF}%s", GetPlayerName(playerid), reason);
    SendClientMessageToAll(-1, string);
    SetTimerEx("AntiCheatKickFunction", 1000, 0, "d", playerid);
}

AntiCheatKick(playerid, string, "Test reason"); //The function I should use and then it'll paste the string and afterwards i could write the reason.
So what i imagined i would see in game would be: {A9FF63}[ANTI-CHEAT] {FFFFFF}CrazyChoco has been kicked from the server. {9DFF8C}[REASON] {FFFFFF}Test reason.

But When i compile i recieve these warnings;
Код HTML:
C:\Users\us\Desktop\SA-MP 0.3z\gamemodes\gamemode.pwn(315) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\us\Desktop\SA-MP 0.3z\gamemodes\gamemode.pwn(316) : warning 202: number of arguments does not match definition
C:\Users\us\Desktop\SA-MP 0.3z\gamemodes\gamemode.pwn(316) : warning 202: number of arguments does not match definition
C:\Users\us\Desktop\SA-MP 0.3z\gamemodes\gamemode.pwn(313) : warning 203: symbol is never used: "string"
Reply
#2

1) You cannot declare an array or variable in a function with the same name of an existing parameter of the function.
2) GetPlayerName does not return direct values, refer to it's wiki : https://sampwiki.blast.hk/wiki/GetPlayerName
Reply
#3

I fixed the warnings, but now I am getting a new warning:
Quote:

warning 224: indeterminate array size in "sizeof" expression (symbol "")

pawn Код:
stock AntiCheatKick(playerid, message[], reason[])
{
    format(message, sizeof(message), "{A9FF63}[ANTI-CHEAT] {FFFFFF}%s. {9DFF8C}[REASON] {FFFFFF}%s", message, reason);
    SendClientMessageToAll(-1, message);
    SetTimerEx("AntiCheatKickFunction", 1000, 0, "d", playerid);
}
Reply
#4

Add an optional parameter to the function which sets it's value to the size of message parameter.
pawn Код:
stock AntiCheatKick(playerid, message[], reason[], size = sizeof(message))
{
    format(message, size, "{A9FF63}[ANTI-CHEAT] {FFFFFF}%s. {9DFF8C}[REASON] {FFFFFF}%s", message, reason);
    SendClientMessageToAll(-1, message);
    SetTimerEx("AntiCheatKickFunction", 1000, 0, "d", playerid);
    return 1;
}
Reply
#5

Thank you very much!

You helped me solving this issue, and as a little thanks gift, I just repped you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)