sendmessagetoadmins problem -
MrakBuster - 08.02.2018
Hello,
i just created a little pm system, where admin can read messages, that players send to each other.
part of the pm system (where admins can read messages) is here:
PHP код:
for(new i = 0; < MAX_PLAYERS; i++)
{
if(PlayerInfo[i][pAdmin] > 0)
{
format(adminovi, sizeof(adminovi), "%s -> %s: %s", GetName(playerid), GetName(targetid), text);
SendClientMessage(i, ADMIN, adminovi);
}
}
Error line 2591 is the first line in code above (loop).
the errors are:
Код:
(2591) : error 029: invalid expression, assumed zero
(2591) : warning 215: expression has no effect
(2591) : error 001: expected token: ")", but found ";"
(2591) : error 036: empty statement
(2591) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
for any help i am thankful
Re: sendmessagetoadmins problem -
solstice_ - 08.02.2018
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++)
You forgot an "i" there.
Also going to give you a quick suggestion, there's a better way on sending a message to administrators.
You can just create a stock and then use it everytime you want to send a message to online admins.
Example:
PHP код:
stock SendAdminMessage(color, string[])
{
foreach(Player, i)
{
if(PlayerInfo[i][pAdmin] >= 1)
{
SendClientMessage(i, color, string);
}
}
}
And then you can use: SendAdminMessage(COLOR, message);
Re: sendmessagetoadmins problem -
MrakBuster - 08.02.2018
Well, I thought that I can just compare it straight forward, heh, thanks!
And for the handy dandy little tool, thanks aswell, i will use it asap, and than just differ in certain commands.
REP +
Re: sendmessagetoadmins problem -
Dayrion - 09.02.2018
If you don't use foreach, you must optimize your loop.
PHP код:
for(new i, j = GetPlayerPoolSize(); i <= j; i++)
{
if(!IsPlayerConnected(i))
continue;
if(PlayerInfo[i][pAdmin] > 0)
{
format(adminovi, sizeof(adminovi), "%s -> %s: %s", GetName(playerid), GetName(targetid), text);
SendClientMessage(i, ADMIN, adminovi);
}
}
Re: sendmessagetoadmins problem -
MrakBuster - 09.02.2018
What is the difference between regular loop and this one?
Re: sendmessagetoadmins problem -
Dayrion - 09.02.2018
Quote:
Originally Posted by MrakBuster
What is the difference between regular loop and this one?
|
This is more optimized. Why?
- Your loop do : 0 to 1000 but I'm pretty sure you don't have 1000 players on your server
- You are checking admin level for people doesn't exist
- This one loop through 0 to the highest player id
- It check if the player is connected or not
You can even add
&& !IsPlayerNPC(i) if you have bots on your server.