I made my Own Event System but i miss one thing, so how to make that the last alive player in the event get automatic money and score? So the winnrer in the event and the only player with the inevent variable 'inevent = 1' get these things?
Thanks to all, Rodri. |
// Somewhere on the top of the script
#define Max_Event_Players 69
enum E_Players {
EventPlayerId,
bool:isAlive
} new EventPlayers[ Max_Event_Player ][ E_Players ];
new EventPlayersCount = 0;
new bool:IsPlayerOnEvent[ MAX_PLAYERS ];
public OnPlayerConnect( playerid ) {
IsPlayerOnEvent[ playerid ] = false;
}
public OnGameModeInit() {
for( new PlayerId = 0; PlayerId < Max_Event_Players; PlayerId ++ )
{
EventPlayers[ PlayerId ][ EventPlayerId ] = INVALID_PLAYER_ID; // meaning e.g. this player is not active, died, this slot's free, or something
EventPlayers[ PlayerId ][ isAlive ] = false;
}
}
public OnPlayerDeath( playerid, reason ) {
if( IsPlayerOnEvent[ playerid ] ) {
// When player dies, we assume, that he quits event automatically.
IsPlayerOnEvent[ playerid ] = false;
EventPlayersCount--;
EventPlayers[ SlotId ][ isAlive ] = false;
EventPlayers[ SlotId ][ EventPlayerId ] = INVALID_PLAYER_ID;
if(EventPlayersCount == 1)
FinishEvent();
}
}
// In the deeps of the bits
stock AddPlayerToEvent( playerid ) {
new SlotId = 0;
while( EventPlayers[ SlotId ][ EventPlayerId ] != INVALID_PLAYER_ID ) // Find next free slot
SlotId++;
if( SlotId == Max_Event_Players )
return false; // cannot add anymore players
EventPlayers[ SlotId ][ EventPlayerId ] = playerid;
}
// Somewhere else
stock StartEvent( ) {
new SlotId = 0;
while( EventPlayers[ SlotId ][ EventPlayerId ] != INVALID_PLAYER_ID || SlotId < Max_Event_Players) {
EventPlayers[ SlotId ][ isAlive ] = true;
EventPlayersCount++;
SlotId++;
}
}
// Yet in another place! Wow! :V
stock FinishEvent() {
// Find the winner in EventPlayers... Because only he's there, if we follow our convention mentioned in OnPlayerDeath callback
new SlotId = 0;
while( EventPlayers[ SlotId ][ EventPlayerId ] == INVALID_PLAYER_ID )
SlotId++;
// Here you can do whatever You want, because SlotId now contains ID of the player which is the only one left in the event.
}