Cops counting problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Cops counting problem (
/showthread.php?tid=465967)
Cops counting problem -
Lidor124 - 25.09.2013
Hey all!
I made a bank robbery system and i made in it count of the cops in the server - each cop logins to the server so counting +1, the problem is when the cop disconnect its still +1 and not -1, what's wrong?
For bank robbery the robber needs at least 4 cops online.... 4 connected and one leave - he still can rob... :/
there is the code of cop counting online:
Код:
#pragma unused params
if(IsPlayerConnected(playerid))
{
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(PlayerInfo[i][pMember] == 1 || PlayerInfo[i][pLeader] == 1)
{
LEOOnline++;
}
}
if(LEOOnline < 4)
{
SendClientMessage(playerid, COLOR_GRAD3, "You need at least 4 Law Enforcement officers!");
return 1;
}
Re: Cops counting problem -
Konstantinos - 25.09.2013
Do you dicrease it by 1 after the player (who is cop) disconnects?
Well, you can do it easier with foreach. It'll loop faster through the online cops, plus it counts too.
For example:
pawn Код:
// Global
new
Iterator:Cop<MAX_PLAYERS>
;
// Where he gets cop status or loggin and being set as cop:
Iter_Add(Cop, playerid);
// When a player leaves the cop status or disconnects:
Iter_Remove(Cop, playerid);
// For bank robbery - count the cops
if( Iter_Count(Cop) >= 4 )
{
// robber can rob!
}
else // send an error message that he cannot rob when there are not atleast 4 cops online.
Re: Cops counting problem -
=KempeR= - 25.09.2013
You are missing
IsPlayerConnected
PHP код:
#pragma unused params
if (IsPlayerConnected(playerid)) {
for (new i = 0; i < MAX_PLAYERS; i++)
if (IsPlayerConnected(i) && (PlayerInfo[i][pMember] == 1 || PlayerInfo[i][pLeader] == 1))
LEOOnline++;
if (LEOOnline < 4)
return SendClientMessage(playerid, COLOR_GRAD3, "You need at least 4 Law Enforcement officers!");
}
Re: Cops counting problem -
Lidor124 - 25.09.2013
Quote:
Originally Posted by Konstantinos
Do you dicrease it by 1 after the player (who is cop) disconnects?
Well, you can do it easier with foreach. It'll loop faster through the online cops, plus it counts too.
For example:
pawn Код:
// Global new Iterator:Cop<MAX_PLAYERS> ;
// Where he gets cop status or loggin and being set as cop: Iter_Add(Cop, playerid);
// When a player leaves the cop status or disconnects: Iter_Remove(Cop, playerid);
// For bank robbery - count the cops if( Iter_Count(Cop) >= 4 ) { // robber can rob! } else // send an error message that he cannot rob when there are not atleast 4 cops online.
|
well i never heard about these codes, i scripter beginner so... your define "Cop" instead of it put PlayerInfo[playerid][pMember] == 1 or what? can you suit your code to my code please? and when cop log off so it will be -1 cop in the server, then the robber won't rob the bank because of only 3 cops online.