View Single Post
DeathChaos25
Senior Member
Join Date: Jan 2014
Location: Puerto Rico
Old 08-26-2014 , 05:54   Re: [L4D2] Weapon Remove
Reply With Quote #10

Quote:
Originally Posted by Hanzoligen View Post
I altered the script to make it adjustable for each weapon.
It works for both L4D1 + 2.
You can set a general pick up limit if you don't feel like altering each weapon for its own. It's also possible to set a limit of "0" to remove specific weapons completely or use "-1" if you want infinite amount (l4d standard).

Thanks to Rain_orel for the initial plugin!

For the bugs above: I didn't encounter the script not working, although I restarted several times. Can you try again and report please?
I couldn't test the other bug (takes time to walk through the map). Each item spawn has it's unique ID. Unless that equals the ID of the gun you are holding it shouldn't get removed.

Edit: I noticed that if you change the limits you need to reload the map twice before they get applied. I have no idea why. Any hints are welcome.
I don't know if this is why the bug happens, but, you guys forgot to code the ConVar changed event, meaning if someone changes the value mid game, the plugin is never told so until it is reset, so it'll never change until the plugins are unloaded and refreshed or until a map change.

Here it is,

PHP Code:
#include <sourcemod>
#include <sdktools>
 
public Plugin:myinfo =
{
    
name "[L4D2] Weapon Remove",
    
author "Rain_orel",
    
description "Removes weapon spawn",
    
version "1.0",
    
url "http://www.sourcemod.net/"
};

new 
ent_table[64][2];
new 
new_ent_counter 0;
new 
Handle:hCount;

public 
OnPluginStart()
{
    
HookEvent("spawner_give_item"Event_SpawnerGiveItem);
    
hCount CreateConVar("l4d2_usecount""1""How many times a weapon spawn can be used before it will be removed.")
    
HookConVarChange(hCountConVarhCount
}

public 
OnMapStart()
{
    for(new 
i=0;i<63;i++)
    {
    
ent_table[i][0]=-1;
    
ent_table[i][1]=-1;
    }
    
new_ent_counter 0
}

public 
OnMapEnd(){}

public 
Event_SpawnerGiveItem(Handle:event, const String:name[], bool:dontBroadcast)
{
   
//decl String:item_name[32]
   //GetEventString(event, "item", item_name, 32);  No need yet
   
new entity_id GetEventInt(event"spawner")
   
   
   if(
GetUseCount(entity_id)==-1)
   {
   
ent_table[new_ent_counter][0]=entity_id;
   
ent_table[new_ent_counter][1]=0;
   
new_ent_counter++;
   }
   
   
SetUseCount(entity_id);
   
   if(
GetUseCount(entity_id)==GetConVarInt(hCount))RemoveEdict(entity_id);
}

GetUseCount(entid)
{
    for(new 
i=0;i<63;i++)
    {
    if(
ent_table[i][0]==entid)return ent_table[i][1]
    }
    return -
1
}

SetUseCount(entid)
{
    for(new 
j=0;j<63;j++)
    {
    if(
ent_table[j][0]==entid)ent_table[j][1]++;
    }
}
    
public 
ConVarhCount(Handle:convar, const String:oldValue[], const String:newValue[])
{
    
hCount GetConVarInt(convar


Last edited by DeathChaos25; 08-26-2014 at 05:54.
DeathChaos25 is offline