Event System Variable
#1

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.
Reply
#2

you can use Timer for that, which will see how many players are there in that specific area, and when player count is 1, end the event and award him what ever you want.
hope i helped you some idea.
Reply
#3

Quote:
Originally Posted by Rodri99
Посмотреть сообщение
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.
Using timer is not bad idea, but not good either. It is better to trace 'alive players count' with variable which decerases when someone dies (thus, when the OnPlayerDeath callback is called). Here's the idea (I don't know how does Your system looks like, but if You're smart enough, You'll get the idea )

pawn Код:
// 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.
}
I haven't tested it, it has lack of some security stuff, because I want You to guide You to the right path, not provide you with ready-to-use script, because there's no profit from understanding the nature of code. Hope You understood everything what's above, I've tried to keep it as simple, as possible.

Greetings.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)