Raised This Month: $51 Target: $400
 12% 

[Contagion] Infinite Ammo Plugin Crashing Server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Max91
New Member
Join Date: Dec 2017
Old 12-12-2017 , 17:16   [Contagion] Infinite Ammo Plugin Crashing Server
Reply With Quote #1

Hello,
I found this plugin in the web and it looks like the author isn't supporting this plugin anymore.
It looks like this plugin causing server lag and crash.
Usually server is crashing when there are 6+ players.
Anyone have an idea what should I change to fix this crashing/lagging issue?


Code:
////////////////////////////////////
// Infinite ammo mode (Contagion)
////////////////////////////////////
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "0.1.0"

#define PLAYER_SURVIVOR_ID 2  // 生存者

#define CLEANAMMO_INTERVAL 10.0 // ammoエンティティ除去Interval

// ammoエンティティ除去タイマーハンドル
new Handle:g_hCleanAmmoTimer = INVALID_HANDLE;

public Plugin:myinfo = {
    name        = "Infinite ammo mode",
    author      = "takedeppo.50cal",
    description = "This plugin is provide random weapons when player spawned.",
    version     = PLUGIN_VERSION,
    url         = "http://steamcommunity.com/id/takedeppo"
};

// プラグインスタート
public OnPluginStart() {    
    // sv_cheats通知OFF
    new Handle:svCheats = FindConVar("sv_cheats");
    new flags = GetConVarFlags(svCheats) ;
    flags &= ~(FCVAR_NOTIFY|FCVAR_REPLICATED);
    SetConVarFlags(svCheats, flags);
    
    // 各種Hook,Listenerイベント
    HookEvent("player_spawn", Event_PlayerSpawn);
    HookEvent("player_death", Event_PlayerDeath);
     
    // 無限Ammo設定
    SetCommandFlags("sv_infinite_collected_ammo", GetCommandFlags("sv_infinite_collected_ammo") & ~FCVAR_CHEAT); 
    SetConVarBool(FindConVar("sv_infinite_collected_ammo"), true, false);
}

// マップスタート時
public OnMapStart() {    
    // ammoエンティティ削除Interval開始
    g_hCleanAmmoTimer = CreateTimer(CLEANAMMO_INTERVAL, Timer_cleanAmmo, _, TIMER_REPEAT);
}
// マップエンド時
public OnMapEnd() {
    // タイマーハンドル後処理
    KillTimer(g_hCleanAmmoTimer);
    g_hCleanAmmoTimer = INVALID_HANDLE;
}

// ammoエンティティ除去タイマー処理
public Action:Timer_cleanAmmo(Handle:timer) {
    cleanAmmo();
    return Plugin_Continue;
}

// プレイヤーSPAWN時
public Event_PlayerSpawn( Handle:event, const String:szEventName[], bool:bDontBroadcast ) {

    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    if ((0 < client <= MaxClients ) && !IsFakeClient(client)) {
        // suvivorの場合のみ
        if (GetClientTeam(client) == PLAYER_SURVIVOR_ID) {
            joinSpawnWeapon(client);
        } else {
            CreateTimer(1.0, Timer_respawnWeapon, GetClientSerial(client));
        }
        cleanAmmo();
    }
}

// プレイヤー死亡時
public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) {
    cleanAmmo();
}

// ランダムで武器
stock joinSpawnWeapon (client) {
 
    SetConVarBool(FindConVar("sv_cheats"), true, false);
    
    // 既存武器の解除
    removeWeapons(client);
    
    new weapon = GetRandomInt(1, 8);
    switch (weapon) {
        case 1:{  FakeClientCommand(client, "give sig");          }
        case 2:{  FakeClientCommand(client, "give 1911");         }
        case 3:{  FakeClientCommand(client, "give revolver");     }
        case 4:{  FakeClientCommand(client, "give blr");          }
        case 5:{  FakeClientCommand(client, "give mossberg");     }
        case 6:{  FakeClientCommand(client, "give overunder");    }
        case 7:{  FakeClientCommand(client, "give remington870"); }
        case 8:{  FakeClientCommand(client, "give m1garand");     }
    }
    
    new optional = GetRandomInt(1, 6);
    if (optional == 1) {
        FakeClientCommand(client, "give firstaid");
    } else if (optional == 2) {
        FakeClientCommand(client, "give grenade");
    } else if (optional == 3) {
        FakeClientCommand(client, "give ied");
    } 
    
    new optional2 = GetRandomInt(1, 3);
    if (optional2 <= 2) {
        FakeClientCommand(client, "give plight");
    }
    
    SetConVarBool(FindConVar("sv_cheats"), false, false);

    LogToGame("infiniteammomode: player#%d got weapon (wep=%d,op1=%d,op2=%d)", client, weapon, optional, optional2);
}

// リスポン後武器
public Action:Timer_respawnWeapon(Handle:timer, any:serial) {
    new client = GetClientFromSerial(serial);
    if (client == 0) {
        return Plugin_Stop;
    }
    
    if (GetClientTeam(client) == PLAYER_SURVIVOR_ID) {
        SetConVarBool(FindConVar("sv_cheats"), true, false);
        removeWeapons(client);
        new weapon = GetRandomInt(1, 3);
        switch (weapon) {
            case 1:{  FakeClientCommand(client, "give sniper");   }
            case 2:{  FakeClientCommand(client, "give crossbow"); }
            case 3:{  FakeClientCommand(client, "give compbow");  }
        }
        SetConVarBool(FindConVar("sv_cheats"), false, false);
        LogToGame("infiniteammomode: player#%d got weapon (resp wep=%d)", client, weapon);
    }
    return Plugin_Stop;
}



// 所持武器の全解除
stock removeWeapons(client) {
    new ent;
    for (new i = 0; i < 4; i++) {
        ent = GetPlayerWeaponSlot(client, i);
        if (IsValidEntity(ent)) {
            RemovePlayerItem(client, ent);
            RemoveEdict(ent);
        }
    }
}

// ammoエンティティ除去
stock cleanAmmo(){
    // ※ammo無限の場合、ammo_エンティティが増えすぎるので、定期的に削除
    decl String:className[64];
    for(new i = 0; i <= GetMaxEntities(); i++) {
        if(IsValidEdict(i) && IsValidEntity(i)) {
            GetEdictClassname(i, className, sizeof(className));
            // 各種ammoを除去
            if (   (strcmp(className, "item_ammo_9mm", false) == 0)
                || (strcmp(className, "item_ammo_1911", false) == 0)
                || (strcmp(className, "item_ammo_rifle", false) == 0) 
                || (strcmp(className, "item_ammo_sniper", false) == 0)
                || (strcmp(className, "item_ammo_shotgun", false) == 0)
                || (strcmp(className, "item_ammo_arrow", false) == 0)
                || (strcmp(className, "item_ammo_arrow_pack", false) == 0)
            ){
                
                RemoveEdict(i);
            }
        }
    }
}

Thanks!
Max91 is offline
Reply



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 12:27.


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