Optimize this moneycheck? -
Face9000 - 29.12.2011
Hello guys,i've this code:
pawn Code:
forward MoneyCheck();
public MoneyCheck()
{
for(new i; i < MAX_PLAYERS; i++)
{
new cash = GetPlayerMoney(i);
if(cash > 999999990)
{
SetPlayerHealth(i, 0.0);
SendClientMessage(i, 0x10F441AA, "You forgot to pay the tax,nub.");
new string[128];
new pName[MAX_PLAYER_NAME];
GetPlayerName(i, pName, sizeof(pName));
format(string, 100, "%s was auto-banned for MoneyHack - $%d.", pName,GetPlayerMoney(i));
SendClientMessageToAll(COLOR_RED, string);
GameTextForAll("~r~HAAAAAAAAAAAAAAAAAAX", 3000, 5);
new sss[128];
format(sss, sizeof(sss), "You have Been Banned by ANTICHEAT. Reason: Moneyhack.");
SendClientMessage(i,COLOR_LIGHTBLUE, sss);
SendClientMessage(i,COLOR_RED, "To Get Unbanned Post an Unban Request at Our Forums");
SendClientMessage(i,COLOR_LIGHTRED, "Don't Evade, Otherwise you wont get unbanned.");
new str[136];
GetPlayerName(i, pName, sizeof(pName));
format(str,sizeof str,"0,4%s was auto-banned for MoneyHack - $%d.", pName,GetPlayerMoney(i));
IRC_GroupSay(IRC_Group, EchoChan,str);
BanLog(string);
new str2[64];
format(str2,sizeof str2,"%s", pName);
Blacklist(str2);
Ban(i);
new tmp[128];
dUserSetINT(tmp).("AccountBanned",1);
}
}
}
And this timer on OnGameModeInit:
SetTimer("MoneyCheck", 5000, true);
----
I want to optimize this code,any tips?
Re: Optimize this moneycheck? -
PowerPC603 - 29.12.2011
Something like this:
pawn Code:
forward MoneyCheck();
public MoneyCheck()
{
new Msg[128], Msg2[136], Msg3[64], pName[MAX_PLAYER_NAME], Cash;
for (new playerid; playerid < MAX_PLAYERS; playerid++)
{
if (IsPlayerConnected(playerid))
{
Cash = GetPlayerMoney(playerid);
if (Cash > 999999990)
{
GetPlayerName(playerid, pName, sizeof(pName));
SetPlayerHealth(playerid, 0.0);
SendClientMessage(playerid, 0x10F441AA, "You forgot to pay the tax, nub.");
format(Msg, sizeof(Msg), "%s was auto-banned for MoneyHack - $%d.", pName, Cash);
SendClientMessageToAll(COLOR_RED, Msg);
GameTextForAll("~r~HAAAAAAAAAAAAAAAAAAX", 3000, 5);
BanLog(Msg);
format(Msg, sizeof(Msg), "You have Been Banned by ANTICHEAT. Reason: Moneyhack.");
SendClientMessage(playerid, COLOR_LIGHTBLUE, Msg);
SendClientMessage(playerid, COLOR_RED, "To Get Unbanned Post an Unban Request at Our Forums");
SendClientMessage(playerid, COLOR_LIGHTRED, "Don't Evade, Otherwise you wont get unbanned.");
format(Msg2, sizeof(Msg2), "0,4%s was auto-banned for MoneyHack - $%d.", pName, Cash);
IRC_GroupSay(IRC_Group, EchoChan, Msg2);
format(Msg3, sizeof(Msg3), pName);
Blacklist(Msg3);
Ban(playerid);
dUserSetINT(pName).("AccountBanned", 1);
}
}
}
}
Re: Optimize this moneycheck? -
AndreT - 29.12.2011
Another thing I can think of is using foreach for the player loop!
Re: Optimize this moneycheck? -
cessil - 29.12.2011
pawn Code:
forward MoneyCheck();
public MoneyCheck()
{
for(new i; i < MAX_PLAYERS; i++)
{
new cash = GetPlayerMoney(i);
if(cash > 999999990)
{
//SetPlayerHealth(i, 0.0);
SendClientMessage(i, 0x10F441AA, "You forgot to pay the tax,nub.");
new string[128];
new pName[MAX_PLAYER_NAME];
GetPlayerName(i, pName, sizeof(pName));
format(string, 100, "%s was auto-banned for MoneyHack - $%d.", pName,cash);
SendClientMessageToAll(COLOR_RED, string);
GameTextForAll("~r~HAAAAAAAAAAAAAAAAAAX", 3000, 5);
SendClientMessage(i,COLOR_LIGHTBLUE, "You have Been Banned by ANTICHEAT. Reason: Moneyhack.");
SendClientMessage(i,COLOR_RED, "To Get Unbanned Post an Unban Request at Our Forums");
SendClientMessage(i,COLOR_LIGHTRED, "Don't Evade, Otherwise you wont get unbanned.");
format(str,sizeof str,"0,4%s was auto-banned for MoneyHack - $%d.", pName,cash);
IRC_GroupSay(IRC_Group, EchoChan,str);
BanLog(string);
Blacklist(pName);
Ban(i);
new tmp[128];
//im no expert in this ini system but I'm pretty sure this wouldn't work
dUserSetINT(tmp).("AccountBanned",1);
}
}
}
if that's actually from your anticheat then I recommend reading this
https://sampforum.blast.hk/showthread.php?tid=220089