PDA

View Full Version : Help with a public function.


Strier
26/05/2013, 07:18 AM
Alright, when the minutes / seconds are @0 the code is supposed to re-spawn everyone and show them the class selection, and announce the winner but it just goes to 0:00 and nothing happens, here is the public function.

public TeamWinning(playerid)
{
if(Seconds == 0 && Minutes == 0)
{
if(cKills > tKills)
{
GameTextForAll("~r~~h~Terrorists win!", 5000, 6);
cKills = 0;
tKills = 0;
for(new i=0;i<MAX_PLAYERS;i++)
{
ForceClassSelection(playerid);
}
}
else if(cKills < tKills)
{
if(Seconds == 0 && Minutes == 0)
{
GameTextForAll("~b~~h~Counter terrorists win!", 5000, 6);
cKills = 0;
tKills = 0;
for(new i=0;i<MAX_PLAYERS;i++)
{
ForceClassSelection(playerid);
}
}
}
else if(cKills == tKills)
{
if(Seconds == 0 && Minutes == 0)
{
GameTextForAll("~w~~h~None won the match!",4000,6);
cKills = 0;
tKills = 0;
for(new i=0;i<MAX_PLAYERS;i++)
{
ForceClassSelection(playerid);
}
}
}
}
return 1;
}

Revo
26/05/2013, 07:39 AM
You'll need to provide more information, e.g. the timer to zero function, and the timer or function that triggers this function.

Also, you're repeating your code, it doesn't matter much, but it's just a pain in my eyes to keep it like that, simply due to its length. Also check if the player is connected.

Consider doing this:


if(Seconds == 0 && Minutes == 0)
{
if(cKills > tKills)
{
GameTextForAll("~r~~h~Terrorists win!", 5000, 6);
}
else if(cKills < tKills)
{
GameTextForAll("~b~~h~Counter terrorists win!", 5000, 6);
}
else
{
GameTextForAll("~w~~h~None won the match!",4000,6);
}

cKills = 0;
tKills = 0;
for(new i=0;i<MAX_PLAYERS;i++)
{
if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
ForceClassSelection(playerid);
}
}

Strier
26/05/2013, 07:45 AM
new Seconds = 59;
new Minutes = 4;

public GameTime(playerid)
{
if(Seconds || Minutes) {
Seconds--;
if(Seconds <= -1) {
Minutes--;
Seconds=59;
}
new TimeString[128];
format(TimeString, 128, "~Y~~H~TIME LEFT: %02d:%02d", Minutes, Seconds);
PlayerTextDrawSetString(playerid, Textdraw0[ playerid ], TimeString);
}

return 1;
}

SetTimer("GameTime", 1000, true);

The timer is set in ongamemodeinit and it's set to 1000 to update the TD..

Strier
26/05/2013, 05:53 PM
Bump

Vince
26/05/2013, 06:07 PM
Also check if the player is connected.


No point. Functions won't work for players that aren't connected. To fix your problem, read this: http://wiki.sa-mp.com/wiki/ForceClassSelection. Specifically the note.

Strier
26/05/2013, 11:39 PM
So yeah, i've finished the code still when the count is 0, it doesn't do what it has to do...

here the code:

public TeamWinning(playerid)
{
if(Seconds == 0 && Minutes == 0)
{
if(cKills > tKills)
{
GameTextForAll("~r~~h~Terrorists win!", 5000, 6);
}
else if(cKills < tKills)
{
GameTextForAll("~b~~h~Counter terrorists win!", 5000, 6);
}
else
{
GameTextForAll("~w~~h~None won the match!",4000,6);
}

cKills = 0;
tKills = 0;
Seconds=59;
Minutes=0;
for(new i=0;i<MAX_PLAYERS;i++)
{
if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
ForceClassSelection(i);
TogglePlayerSpectating(i, true);
TogglePlayerSpectating(i, false);
}
}
return 1;
}