Raised This Month: $ Target: $400
 0% 

[L4D2] Anti-Runner System


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
kiraibrasil
Member
Join Date: Jun 2009
Old 04-03-2010 , 21:55   Re: [L4D2] Anti-Runner System
Reply With Quote #11

I fixed the plugins in versus mode. Damn I translate for my language, the more you can put into your language.
I do not get the error charger door. So I hung up

PHP Code:
#include <sourcemod>
#include <sdktools>

#define DEBUG 0
#define JAPANESE 0
#define PLUGIN_VERSION "1.0"
#define CVAR_FLAGS FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY
#define MAXLENGTH 128

#define SURVIVOR 2
#define CHARGER 6
#define TANK 8

#define UNLOCK 0
#define LOCK 1

new Handle:sm_ar_announce INVALID_HANDLE;
new 
Handle:sm_ar_assault_health INVALID_HANDLE;
new 
Handle:sm_ar_assault_hate INVALID_HANDLE;
new 
Handle:sm_ar_lock_tankalive INVALID_HANDLE;

/* Lock flag */
new SafetyLock;

/* Keyman's ID */
new idKeyman;

/* Goal door ID */
new idGoal;

/* Keyman's name */
new String:nmKeyman[MAXLENGTH];

/* Sound file */
new String:SoundNotice[MAXLENGTH] = "doors/latchlocked2.wav";
new 
String:SoundDoorOpen[MAXLENGTH] = "doors/door_squeek1.wav";
new 
String:SoundDoorSpawn[MAXLENGTH] = "music/gallery_music.mp3";

/* Assault door model */
new String:ModelAssault[MAXLENGTH] = "models/props_doors/checkpoint_door_02.mdl";

public 
Plugin:myinfo 
{
    
name "[L4D2] Anti-Runner System feat.Assault door",
    
author "ztar",
    
description "Only Keyman can open saferoom door.",
    
version PLUGIN_VERSION,
    
url "http://ztar.blog7.fc2.com/"
}

public 
OnPluginStart()
{
    
sm_ar_announce          CreateConVar("sm_ar_announce","1""Announce plugin info(0:OFF 1:ON)"CVAR_FLAGS);
    
sm_ar_assault_health CreateConVar("sm_ar_assault_health","2000""Health of Assault door"CVAR_FLAGS);
    
sm_ar_assault_hate      CreateConVar("sm_ar_assault_hate","0""Probability of spawning Assault door(0-100)"CVAR_FLAGS);
    
sm_ar_lock_tankalive CreateConVar("sm_ar_lock_tankalive","1""Lock door if any Tank is alive(0:OFF 1:ON)"CVAR_FLAGS);
    
    
HookEvent("player_death"Event_Player_Death);
    
HookEvent("player_use"Event_Player_Use);
    
HookEvent("round_start"Event_Round_Start);
    
HookEvent("player_team"Event_Join_Team);
    
    
AutoExecConfig(true"l4d2_anti-runner");
}

public 
OnMapStart()
{
    
/* Precache */
    
PrecacheSound(SoundNoticetrue);
    
PrecacheSound(SoundDoorOpentrue);
    
PrecacheSound(SoundDoorSpawntrue);
    
PrecacheModel(ModelAssaulttrue);
    
    
/* Find goal door and lock */
    //InitDoor();
    
    /* Select Keyman */
    //SelectKeyman();
    #if DEBUG
    //LogMessage("[ARS][0] Keyman selected -> <%d:%s>", idKeyman, nmKeyman);
    #endif
}

public 
OnClientPutInServer(client)
{
    if(!
IsValidEntity(client))
        return;
    if(
IsFakeClient(client))
        return;
    
    
/* Announce about this plugin */
    
CreateTimer(20.0TimerAnnounceclient);
}

public 
Event_Join_Team(Handle:eventString:event_name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    new 
clientTeam GetEventInt(event"team");
    new 
bool:isBot GetEventBool(event"isbot");
    
    if(!
IsValidEntity(client) || isBot == true)
        return;
    if(
clientTeam == SURVIVOR)
    {
        
SelectKeyman();
        
#if DEBUG
        
LogMessage("[ARS][1] Keyman selected -> <%d:%s>"idKeymannmKeyman);
        
#endif
    
}
}

public 
Action:TimerAnnounce(Handle:timerany:client)
{
    if(
IsClientInGame(client) && GetConVarInt(sm_ar_announce))
        
PrintToChat(client"\x04[ARS]\x01 Sistema de\x03 Anti-Rush \x01ativado.");
}

public 
OnClientDisconnect(client)
{
    if(!
IsValidEntity(client))
        return;
    
    
/* If Keyman disconnect, Re-select Keyman */
    
if(client == idKeyman)
    {
        
SelectKeyman();
        
#if DEBUG
        
LogMessage("[ARS][2] Keyman selected -> <%d:%s>"idKeymannmKeyman);
        
#endif
    
}
}

public 
Action:RoundStartDelay(Handle:timerany:client)
{
    
InitDoor();
    
SelectKeyman();
    
#if DEBUG
    
LogMessage("[ARS][3] Keyman selected -> <%d:%s>"idKeymannmKeyman);
    
#endif
}

public 
Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
    
CreateTimer(1.0RoundStartDelay)
}

public 
Action:Event_Player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));
    
    
/* If victim was Keyman, Re-select Keyman */
    
if(victim == idKeyman)
    {
        
SelectKeyman();
        
#if DEBUG
        
LogMessage("[ARS][4] Keyman selected -> <%d:%s>"idKeymannmKeyman);
        
#endif
    
}
    return 
Plugin_Continue;
}

public 
Action:Event_Player_Use(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    new 
Entity GetEventInt(event"targetid");
    
    if(
IsValidEntity(Entity) && (SafetyLock == LOCK) && (Entity == idGoal))
    {
        new 
String:entname[MAXLENGTH];
        if(
GetEdictClassname(Entityentnamesizeof(entname)))
        {
            
/* Saferoom door */
            
if(StrEqual(entname"prop_door_rotating_checkpoint"))
            {
                for (new 
1<= GetMaxClients(); i++)
                {
                    
/* is valid, in game, alive, and not bot */
                    
if(IsValidEntity(i) && IsClientInGame(i))
                    {
                        if(
GetEntProp(iProp_Send"m_zombieClass") == TANK && GetConVarInt(sm_ar_lock_tankalive))
                        {
                            
EmitSoundToAll(SoundNoticeEntity);
                            
PrintHintText(client"O Tank ainda está vivo, mate-o seu covarde!");
                            return 
Plugin_Continue;
                        }
                    }
                }
                
                
AcceptEntityInput(Entity"Lock");
                
SetEntProp(EntityProp_Data"m_hasUnlockSequence"LOCK);
                
                if(!
IsValidEntity(idKeyman) || !IsClientInGame(idKeyman) || !IsPlayerAlive(idKeyman) || IsFakeClient(idKeyman))
                {
                    
SelectKeyman();
                    
#if DEBUG
                    
LogMessage("[ARS][5] Keyman selected -> <%d:%s>"idKeymannmKeyman);
                    
#endif
                
}
                
                if(
client == idKeyman)
                {
                    
/* If client is Keyman, unlock */
                    
EmitSoundToAll(SoundDoorOpenEntity);
                    
SafetyLock UNLOCK;
                    
ControlDoor(EntityUNLOCK);
                    if(
GetConVarInt(sm_ar_announce))
                    {
                        
PrintToChatAll("\x04[ARS] \x01O Homem-Chave \x03%s\x01 chegou na Sala Segura!"nmKeyman);
                    }
                    
                    
/* Caluculate probability */
                    
new adProb GetConVarInt(sm_ar_assault_hate);
                    
//new adProb = GetConVarInt(sm_ar_assault_hate) * (DeadCount()+1);
                    
if(adProb 100adProb 100;
                    if(
adProb GetRandomInt(099))
                    {
                        
/* Spawn Assault door */
                        //PrintHintTextToAll("Porta de ASSALTO!");
                        //AssaultDoor(client, Entity);
                    
}
                }
                else
                {
                    
/* Notify client who is Keyman */
                    
EmitSoundToAll(SoundNoticeEntity);
                    
PrintHintTextToAll("O Homem-Chave é %s.\nApenas ele pode abrir a porta da Sala Segura!"nmKeyman);
                }
            }
        }
    }
    return 
Plugin_Continue;
}

public 
SelectKeyman()
{
    new 
count 0;
    new 
idAlive[MAXPLAYERS+1];
    
    
/* See all clients */
    
for (new 1<= GetMaxClients(); i++)
    {
        
/* is valid, in game, alive, and not bot */
        
if(IsValidEntity(i) && IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i))
        {
            
/* Survivor team */
            
if(GetClientTeam(i) == SURVIVOR)
            {
                
idAlive[count] = i;
                
count++;
            }
        }
    }
    if(
count == 0) return;
    new 
key GetRandomInt(0count-1);
    
    
/* Get Keyman ID and name */
    
idKeyman idAlive[key];
    
GetClientName(idKeymannmKeymansizeof(nmKeyman));
    
    return;
}

public 
InitDoor()
{
    new 
Entity = -1;
    while((
Entity FindEntityByClassname(Entity"prop_door_rotating_checkpoint")) != -1)
    {
        if(
GetEntProp(EntityProp_Data"m_hasUnlockSequence") == UNLOCK)
        {
            
idGoal Entity;
            
ControlDoor(EntityLOCK);
        }
    }
    
SafetyLock LOCK;
}

public 
ControlDoor(EntityOperation)
{
    if(
Operation == LOCK)
    {
        
/* Close and lock */
        
AcceptEntityInput(Entity"Close");
        
AcceptEntityInput(Entity"Lock");
        
AcceptEntityInput(Entity"ForceClosed");
        
SetEntProp(EntityProp_Data"m_hasUnlockSequence"LOCK);
    }
    else if(
Operation == UNLOCK)
    {
        
/* Unlock and open */
        
SetEntProp(EntityProp_Data"m_hasUnlockSequence"UNLOCK);
        
AcceptEntityInput(Entity"Unlock");
        
AcceptEntityInput(Entity"ForceClosed");
        
AcceptEntityInput(Entity"Open");
    }
}

public 
AssaultDoor(clientEntity)
{
    if(!
client) return;
    
    
/* Spawn Charger */
    
new admindata GetUserFlagBits(client);
    
SetUserFlagBits(clientADMFLAG_ROOT);
    new 
spawnflags GetCommandFlags("z_spawn");
    
SetCommandFlags("z_spawn"spawnflags & ~FCVAR_CHEAT);
    
FakeClientCommand(client"z_spawn charger");
    
SetCommandFlags("z_spawn"spawnflags|FCVAR_CHEAT);
    
SetUserFlagBits(clientadmindata);
    
    for (new 
1<= GetMaxClients(); i++)
    {
        
/* is Charger */
        
if(GetEntProp(iProp_Send"m_zombieClass") == CHARGER)
        {
            
/* Get entity position */
            
decl Float:pos[3];
            
GetClientAbsOrigin(clientpos);
            
pos[2] += 30;
            
            
/* Teleport after setting up */
            
ScreenFade(client200002001001);
            
SetEntityModel(iModelAssault);
            
SetEntityHealth(iGetConVarInt(sm_ar_assault_health));
            
TeleportEntity(iposNULL_VECTORNULL_VECTOR);
            
EmitSoundToAll(SoundDoorSpawni);
            
            return;
        }
    }
}

public 
DeadCount()
{
    new 
dCount 0;
    
    
/* See all clients */
    
for (new 1<= GetMaxClients(); i++)
    {
        if(!
IsValidEntity(i) || !IsClientInGame(i) || IsFakeClient(i))
            continue;
        
        
/* Count DEAD player in survivor team */
        
if(!IsPlayerAlive(i))
            
dCount++;
    }
    return 
dCount;
}

public 
ScreenFade(targetredgreenbluealphadurationtype)
{
    new 
Handle:msg StartMessageOne("Fade"target);
    
BfWriteShort(msg500);
    
BfWriteShort(msgduration);
    if (
type == 0)
        
BfWriteShort(msg, (0x0002 0x0008));
    else
        
BfWriteShort(msg, (0x0001 0x0010));
    
BfWriteByte(msgred);
    
BfWriteByte(msggreen);
    
BfWriteByte(msgblue);
    
BfWriteByte(msgalpha);
    
EndMessage();

Sorry for my bad english

Last edited by kiraibrasil; 04-03-2010 at 21:59.
kiraibrasil is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode