24 12
發新話題
打印

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

[Close]

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

这是我自己设想的一个模式,希望有高手相助
1.开局时离开安全区,游戏就开机进入倒计时功能(这个时间可以在CFG中设置),在指定时间内跑到下一个安全室的玩家可以安全过关,而没有及时进入安全区域内的玩家,则会自爆或者自杀.

2.我希望一代也有一个开局虚血的模式,仿2代那个血流不止,不提供药包,只有小药

我希望高人如果觉得我的想法很好,可以尝试一下,再次谢过

TOP

另外倒计时能否有LOG文件记录玩家最快到达安全室的时间,比如
玩家:ABC
关卡:毫不留情第3关
全程时间:1分:30秒

因为我想使用ASP程序,来读取Log文件,如果有直接能写入数据库,然后用ASP调用,就更加方便了

TOP


第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

非常感谢 APPLE_W,已经测试,发现有个BUG
就是已经到安全门的人,再出来满街跑,就不会对他进行扣血惩罚

另外时间能否改为倒计时,比如您原先设定的是500,计算方式是1+
能否是在500的基础上 500-1

TOP

另外再每关的最后一章关卡上时间可能会有冲突
1.因为平常关,有时间限制大家可以不磨蹭,时间设置短
2.如果段时间,在最后一关,一般时间又不够用,比如

比如平常关3-5分钟足够,但最后一关由于需要等待时间,所以最少要10分钟
丧钟的第3幕教堂等开门也是一个很漫长的过程,所以时间上计算如何配置?


我大脑了现在能想出的办法是:
1.开安全门扣时间 -1(全局时间,无人到安全门自杀)
2.第一个幸存者进入安全门时,启动第2个计时器倒计时开始扣时(第一个幸存者进入安全门引发时间,如果其他幸存者没有及时进入,则自杀!)

这样保证了全局时间足够通关,又可以保证第一个幸存者能到家,说明其他幸存者也可以快速到家,而不是在外面磨蹭或者过意不回家捣乱

TOP

在此,对APPLE_W做出的贡献表示衷心的感谢,他丰富了我们对L4D的乐趣

TOP

这个插件只能第一次建图好用,过关以后插件就无效了,除非直接再建第2关,过关以后第3关就不好用了,然后还得重新建立第3关

TOP

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

TOP

是的,我是在COOP模式下使用的,并不打算在对抗中利用,因为这样反而失去了平衡

TOP

哦,原来是不支持COOP,只能在VERSUS下,这可令人头痛了!
难道合作模式没有什么办法吗?

apple_w,等待您的答复

TOP

APPLE_W每次等你回复需要一天哦,很折磨人~~~

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

编译的时候出现错误

sp<20>:error 017:undefined symbol "player_left_checkpoint"
sp<48>:error 017:undefined symbol "maxlength"
sp<46>:warning 204:symbol is assigned a value that is never used:"client"
//
// 2 errors.
//
compilation time :0.73 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

编译没有问题,但是代码已经产生了一些混乱

COOP模式一下,第一场景开头动画就开始计时,而且时间速度非常快3-4秒=现实中的1秒
而且直接时间就是负数,开始扣血,溢出安全门区域,时间又变了一个值,时而正,时而负,掌握不住规律

TOP

 24 12
發新話題