發新話題
打印

求一个倒计时SP程序的源代码

[Close]

第2點 因為未寫L4D 1插件 所以廢時寫啦
複製內容到剪貼板
代碼:
#include <sourcemod>
#include <sdktools>
#define FCVAR_FLAGS FCVAR_PLUGIN|FCVAR_NOTIFY
#define        IsValidClient(%1)        (1 <= %1 <= MaxClients && IsClientInGame(%1))
new Handle:timerr[MAXPLAYERS+1] = { INVALID_HANDLE,...};
new count[MAXPLAYERS+1];
new Handle:sec  = INVALID_HANDLE;
new Handle:hurt  = INVALID_HANDLE;
public Plugin:myinfo =
{
name  = "**侮辱成份** timer",
author  = "david43/Apple_W",
description = "**侮辱成份** timer",
version  = "0.0.0.1",
url   = "N/A",
}
public OnPluginStart()
{
HookEvent("player_left_start_area",round_start);
HookEvent("player_entered_checkpoint",round_end);
HookEvent("round_end",Event_round_end);
sec = CreateConVar("l4d2_timer_sec","500","幾秒後開始扣血", FCVAR_FLAGS);
hurt = CreateConVar("l4d2_timer_hurt","5","招幾多血", FCVAR_FLAGS);
}
public Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
for( new i = 1; i < GetMaxClients(); i++ )
{
  if (IsValidClient(i))
  {
   if (GetClientTeam(i)==2)
   {
   count[i]=0;
   timerr[i]=CreateTimer(1.0,counts,i,TIMER_REPEAT)
   
   }
  }
}
}
public Action:counts(Handle:timer,any:i)
{
if(count[i]>=GetConVarInt(sec))
{
SlapPlayer(i,GetConVarInt(hurt));
}
count[i]+=1;
PrintHintText(i,"你已經用左%d秒",count[i]);
}
public Action:round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
new client =GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client))
{
if (GetClientTeam(client)==2 && timerr[client]!=INVALID_HANDLE)
{
PrintToChat(client,"你在%d秒到達安全室",count[client]);
KillTimer(timerr[client])
timerr[client]=INVALID_HANDLE;
count[client]=0;
}
}
}
public Action:Event_round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
for( new i = 1; i < GetMaxClients(); i++ )
{
if(timerr[i]!=INVALID_HANDLE)
{
KillTimer(timerr[i])
timerr[i]=INVALID_HANDLE;
count[i]=0;
}
}
}
[ 本帖最後由 apple_W 於 2011-7-4 13:01 編輯 ]

TOP

原來player_left_start_area E個EVENT 唔支持COOP嫁
只支持VERSUS
所以轉左場就不能運作

TOP

新版本
COOP應該可以用啦
複製內容到剪貼板
代碼:
#include <sourcemod>
#include <sdktools>
#define FCVAR_FLAGS FCVAR_PLUGIN|FCVAR_NOTIFY
#define        IsValidClient(%1)        (1 <= %1 <= MaxClients && IsClientInGame(%1))
new Handle:timerr[MAXPLAYERS+1] = { INVALID_HANDLE,...};
new count[MAXPLAYERS+1];
new Handle:sec                = INVALID_HANDLE;
new Handle:hurt                = INVALID_HANDLE;
new bool:ontimer=false;
public Plugin:myinfo =
{
        name                = "**侮辱成份** timer",
        author                = "david43/Apple_W",
        description        = "**侮辱成份** timer",
        version                = "0.0.0.2",
        url                        = "N/A",
}
public OnPluginStart()
{
player_left_checkpoint
HookEvent("player_left_checkpoint",Event_player_left_checkpoint);
HookEvent("round_start",Event_round_start);
HookEvent("player_left_start_area",round_start);
HookEvent("player_entered_checkpoint",round_end);
HookEvent("round_end",Event_round_end);
HookEvent("player_use",Event_Player_Use);
sec = CreateConVar("l4d2_timer_sec","500","幾秒後開始扣血", FCVAR_FLAGS);
hurt = CreateConVar("l4d2_timer_hurt","5","招幾多血", FCVAR_FLAGS);
}

public OnMapStart()
{
ontimer=false;
}
public Action:Event_player_left_checkpoint(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
timerr[client]=CreateTimer(1.0,counts,client,TIMER_REPEAT)
count[client]=2;
}
public Action:Event_Player_Use(Handle:event, const String:name[], bool:dontBroadcast)
{
if(!ontimer)
{
        ontimer=true;
        new client = GetClientOfUserId(GetEventInt(event, "userid"));
        new Entity = GetEventInt(event, "targetid");
        new String:entname[MAXLENGTH];
        GetEdictClassname(Entity, entname, sizeof(entname))
        if(StrEqual(entname, "prop_door_rotating_checkpoint"))
        {
        for( new i = 1; i < GetMaxClients(); i++ )
        {
                if (IsValidClient(i))
                {
                        if (GetClientTeam(i)==2)
                        {
                        count[i]=GetConVarInt(sec);
                        timerr[i]=CreateTimer(1.0,counts,i,TIMER_REPEAT)
                       
                        }
                }
        }
        }
}
}



public Action:Event_round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
for( new i = 1; i < GetMaxClients(); i++ )
{
        if(timerr[i]!=INVALID_HANDLE)
        {
        KillTimer(timerr[i])
        timerr[i]=INVALID_HANDLE;
        count[i]=GetConVarInt(sec);
        }
}
}

public Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
        /*for( new i = 1; i < GetMaxClients(); i++ )
        {
                if (IsValidClient(i))
                {
                        if (GetClientTeam(i)==2)
                        {
                        count[i]=GetConVarInt(sec);
                        timerr[i]=CreateTimer(1.0,counts,i,TIMER_REPEAT)
                       
                        }
                }
        }*/
}
public Action:counts(Handle:timer,any:i)
{
if(count[i]<=0)
{
SlapPlayer(i,GetConVarInt(hurt));
}
count[i]-=1;
PrintHintText(i,"你還有%d秒",count[i]);
}
public Action:round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
new client =GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client))
{
        if (GetClientTeam(client)==2 && timerr[client]!=INVALID_HANDLE)
        {
        PrintToChat(client,"你在%d秒到達安全室",count[client]);
        KillTimer(timerr[client])
        timerr[client]=INVALID_HANDLE;
        count[client]=GetConVarInt(sec);
        }
}
}
public Action:Event_round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
for( new i = 1; i < GetMaxClients(); i++ )
{
        if(timerr[i]!=INVALID_HANDLE)
        {
        KillTimer(timerr[i])
        timerr[i]=INVALID_HANDLE;
        count[i]=GetConVarInt(sec);
        }
}
}

TOP

複製內容到剪貼板
代碼:
#include <sourcemod>
#include <sdktools>
#define FCVAR_FLAGS FCVAR_PLUGIN|FCVAR_NOTIFY
#define        IsValidClient(%1)        (1 <= %1 <= MaxClients && IsClientInGame(%1))
new Handle:timerr[MAXPLAYERS+1] = { INVALID_HANDLE,...};
new count[MAXPLAYERS+1];
new Handle:sec                = INVALID_HANDLE;
new Handle:hurt                = INVALID_HANDLE;
new bool:ontimer=false;
public Plugin:myinfo =
{
        name                = "**侮辱成份** timer",
        author                = "david43/Apple_W",
        description        = "**侮辱成份** timer",
        version                = "0.0.0.2",
        url                        = "N/A",
}
public OnPluginStart()
{
HookEvent("player_left_checkpoint",Event_player_left_checkpoint);
HookEvent("round_start",Event_round_start);
HookEvent("player_left_start_area",round_start);
HookEvent("player_entered_checkpoint",round_end);
HookEvent("round_end",Event_round_end);
HookEvent("player_use",Event_Player_Use);
sec = CreateConVar("l4d2_timer_sec","500","幾秒後開始扣血", FCVAR_FLAGS);
hurt = CreateConVar("l4d2_timer_hurt","5","招幾多血", FCVAR_FLAGS);
}

public OnMapStart()
{
ontimer=false;
}
public Action:Event_player_left_checkpoint(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
timerr[client]=CreateTimer(1.0,counts,client,TIMER_REPEAT)
count[client]=2;
}
public Action:Event_Player_Use(Handle:event, const String:name[], bool:dontBroadcast)
{
if(!ontimer)
{
        ontimer=true;
       //new client = GetClientOfUserId(GetEventInt(event, "userid"));
        new Entity = GetEventInt(event, "targetid");
        new String:entname[255];
        GetEdictClassname(Entity, entname, sizeof(entname))
        if(StrEqual(entname, "prop_door_rotating_checkpoint"))
        {
        for( new i = 1; i < GetMaxClients(); i++ )
        {
                if (IsValidClient(i))
                {
                        if (GetClientTeam(i)==2)
                        {
                        count[i]=GetConVarInt(sec);
                        timerr[i]=CreateTimer(1.0,counts,i,TIMER_REPEAT)
                        
                        }
                }
        }
        }
}
}



public Action:Event_round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
for( new i = 1; i < GetMaxClients(); i++ )
{
        if(timerr[i]!=INVALID_HANDLE)
        {
        KillTimer(timerr[i])
        timerr[i]=INVALID_HANDLE;
        count[i]=GetConVarInt(sec);
        }
}
}

public Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
        /*for( new i = 1; i < GetMaxClients(); i++ )
        {
                if (IsValidClient(i))
                {
                        if (GetClientTeam(i)==2)
                        {
                        count[i]=GetConVarInt(sec);
                        timerr[i]=CreateTimer(1.0,counts,i,TIMER_REPEAT)
                        
                        }
                }
        }*/
}
public Action:counts(Handle:timer,any:i)
{
if(count[i]<=0)
{
SlapPlayer(i,GetConVarInt(hurt));
}
count[i]-=1;
PrintHintText(i,"你還有%d秒",count[i]);
}
public Action:round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
new client =GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client))
{
        if (GetClientTeam(client)==2 && timerr[client]!=INVALID_HANDLE)
        {
        PrintToChat(client,"你在%d秒到達安全室",count[client]);
        KillTimer(timerr[client])
        timerr[client]=INVALID_HANDLE;
        count[client]=GetConVarInt(sec);
        }
}
}
public Action:Event_round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
for( new i = 1; i < GetMaxClients(); i++ )
{
        if(timerr[i]!=INVALID_HANDLE)
        {
        KillTimer(timerr[i])
        timerr[i]=INVALID_HANDLE;
        count[i]=GetConVarInt(sec);
        }
}
}

TOP

除了時間不正常
還有其他問題?

TOP

建議你用依個插件
我個插件太多BUG
http://po heart.com/for um.php?mod=viewth read&tid=2870&extra=page%3D5

TOP

發新話題