View Single Post
LinLinLin
Senior Member
Join Date: Sep 2021
Old 10-09-2022 , 14:20   Re: [L4D2]Spawn Infected couldn't find position 5 times.
Reply With Quote #4

好的,我想我大概知道怎麼做了
我在使用了一個全局 Arraylist 和一個全局計時器。
每3秒检查這個生成隊列

ok, maybe i know how to do it .
i use a global Arraylisy and a global repeat-timer.

PHP Code:
g_infected_spawn_queue = new ArrayList(1);
g_timer_infectedbot_spawn_queue CreateTimer(3.0,Timer_SpawnInfectedInQueue,_,TIMER_REPEAT); 
在特感生成的時候寫入(無論是否成功)
When spawn an infectedbot, it's type will be push in the arraylist whether it spawn successfully or not.
PHP Code:
void SpawnInfected(int class)
{
    
g_infected_spawn_queue.Push(class);

在特感成功生成的時候移除出隊列
The type of infectebot in arraylist will be remove when it trigger player_spawn event, as it spawn successfully.
PHP Code:
void Event_PlayerSpawnInfo(Event event, const char[] namebool dontBroadcast)
{
    
//省略了部分代碼
    
int index g_infected_spawn_queue.FindValue(type);
    if( 
index != -1)
    {
        
g_infected_spawn_queue.Erase(index);
    }

考慮到性能,每3秒僅生成隊列第一個特感
spawn too many infectedbot in once is not good, the timer will spawn one infectedbot and the type is the value in arraylist(0).

PHP Code:
Action Timer_SpawnInfectedInQueue(Handle timer)
{
    if( !
g_gamemode_on || g_has_round_end )
    {
        
g_timer_infectedbot_spawn_queue null;
        return 
Plugin_Stop;
    }
        

    if( 
g_infected_spawn_queue.Length == )
        return 
Plugin_Continue;
    
    
//生成查询队列里生成的特感.
    
int class = g_infected_spawn_queue.Get(0);
    
SpawnInfected(class);
    return 
Plugin_Continue;

經過測試,感覺3秒檢查和生成隊列首個特感比較合適。在多特情況下,最終章開啟機關後,特感緩慢 增加到設置的數量。
服務器sv 不會出現太大波動。
Now it seems good in my server. Infectedbot will respawn in order after it spawn failed. By setting 3 seconds timer, the infectedbot count will increase slowly when it can spawn.
And my server sv don't change radically.

Last edited by LinLinLin; 10-09-2022 at 16:27.
LinLinLin is offline