Exemple #1
0
/**
 * @brief Level system module init function.
 **/
void LevelSystemOnInit(/*void*/)
{
    // Prepare all levels data
    LevelSystemOnLoad();

    // If level system disable, then stop
    if(!gCvarList[CVAR_LEVEL_SYSTEM].BoolValue || !gCvarList[CVAR_LEVEL_HUD].BoolValue )
    {
        // Validate loaded map
        if(gServerData.MapLoaded)
        {
            // Validate sync
            if(gServerData.LevelSync != null)
            {
                // i = client index
                for(int i = 1; i <= MaxClients; i++)
                {
                    // Validate client
                    if(IsPlayerExist(i, false))
                    {
                        // Remove timer
                        delete gClientData[i].LevelTimer;
                    }
                }
                
                // Remove sync
                delete gServerData.LevelSync;
            }
        }
        return;
    }
    
    // Creates a HUD synchronization object
    if(gServerData.LevelSync == null)
    {
        gServerData.LevelSync = CreateHudSynchronizer();
    }
    
    // Validate loaded map
    if(gServerData.MapLoaded)
    {
        // i = client index
        for(int i = 1; i <= MaxClients; i++)
        {
            // Validate client
            if(IsPlayerExist(i, false))
            {
                // Enable level system
                LevelSystemOnClientUpdate(i);
            }
        }
    }
}
/**
 * Event callback (player_death)
 * The player is about to die.
 * 
 * @param iVictim		The victim index.
 * @param iAttacker		The attacker index.
 **/
void DeathOnClientDeath(int iVictim, int iAttacker)
{
	// Get real player index from event key
	CBasePlayer* cBaseVictim  = view_as<CBasePlayer>(iVictim);
	CBasePlayer* cBaseAttacker = view_as<CBasePlayer>(iAttacker);

	// Remove glowing
	cBaseVictim->m_bSetGlow(false);
	
	// Remove night vision
	cBaseVictim->m_bNightVisionOn = 0;
	
	// Clear any existing overlay from screen
	if(RoundEndGetRoundValidate())
	{
		ToolsSwitchLevel(cBaseVictim, UNVALID_MESSAGE_ID);
	}

	// Emit scream sound
	cBaseVictim->InputEmitAISound(SNDCHAN_VOICE, SNDLEVEL_SCREAMING, (ZombieIsFemale(cBaseVictim->m_nZombieClass)) ? "ZOMBIE_FEMALE_DEATH_SOUNDS" : "ZOMBIE_DEATH_SOUNDS", true);
	
	// Player was killed by other ?
	if(cBaseVictim != cBaseAttacker) 
	{
		// If respawn amount more, than limit, stop
		if(cBaseVictim->m_nRespawnTimes > GetConVarInt(gCvarList[CVAR_RESPAWN_AMOUNT]))
		{
			return;
		}
		
		// Verify that the attacker is connected and alive
		if(IsPlayerExist(view_as<int>(cBaseAttacker)))
		{
			// Give ammopacks for kill
			cBaseAttacker->m_nAmmoPacks += GetConVarInt(gCvarList[CVAR_BONUS_KILL]);

			// Level system work only for humans and zombies
			if(!cBaseAttacker->m_bNemesis && !cBaseAttacker->m_bSurvivor)
			{
				if(GetConVarBool(gCvarList[CVAR_LVL_SYSTEM]) && cBaseAttacker->m_iLevel < 10)
				{
					// Increment level
					cBaseAttacker->m_iLevel++;

					// Update overlays and speed
					ToolsSwitchLevel(cBaseAttacker, cBaseAttacker->m_iLevel);
					ToolsIncreaseSpeed(cBaseAttacker, cBaseAttacker->m_iLevel);
				}
			}
		}
	}
	// If player was killed by world, respawn on suicide?
	else if (!GetConVarBool(gCvarList[CVAR_RESPAWN_WORLD]))
	{
		return;
	}

	// Respawn if human/zombie/nemesis/survivor?
	if ((cBaseVictim->m_bZombie && !cBaseVictim->m_bNemesis && !GetConVarBool(gCvarList[CVAR_RESPAWN_ZOMBIE])) || (!cBaseVictim->m_bZombie && !cBaseVictim->m_bSurvivor && !GetConVarBool(gCvarList[CVAR_RESPAWN_HUMAN])) || (cBaseVictim->m_bNemesis && !GetConVarBool(gCvarList[CVAR_RESPAWN_NEMESIS])) || (cBaseVictim->m_bSurvivor && !GetConVarBool(gCvarList[CVAR_RESPAWN_SURVIVOR])))
	{
		return;
	}
	
	// Increment count
	cBaseVictim->m_nRespawnTimes++;
	
	// Set timer for respawn player
	EndTimer(Task_ZombieRespawn[view_as<int>(cBaseVictim)]);
	Task_ZombieRespawn[view_as<int>(cBaseVictim)] = CreateTimer(GetConVarFloat(gCvarList[CVAR_RESPAWN_TIME]), EventRespawnZombie, view_as<int>(cBaseVictim));
}