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

[L4D2] Disable Magnum


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 03-30-2012 , 03:09   [L4D2] Disable Magnum
Reply With Quote #1

I just need a simple script that will either remove magnums from the game or replace them with pistols.
chinagreenelvis is offline
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 03-31-2012 , 03:43   Re: [L4D2] Disable Magnum
Reply With Quote #2

Tried this, but no luck:

Code:
public OnPluginStart()
{
	HookEvent("round_start", Event_Round_Start);
}

public Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
	CreateTimer(10.0, ReplaceMagnumDelay);
}

public Action:ReplaceMagnumDelay(Handle:timer)
{
	ReplaceMagnum();
}

ReplaceMagnum()
{

	new ent = -1;
	new prev = 0;
	new replacement;
	decl Float:origin[3];
	decl Float:angles[3];
	while ((ent = FindEntityByClassname(ent, "weapon_magnum_spawn")) != -1)
	{
		if (prev)
		{
			GetEntPropVector(prev, Prop_Send, "m_vecOrigin", origin);
			GetEntPropVector(prev, Prop_Send, "m_angRotation", angles);
			
			replacement = CreateEntityByName("weapon_pistol");
			DispatchSpawn(replacement);
			PrintToChatAll("Replacing weapon_magnum_spawn %i with weapon_pistol %i", prev, replacement);
			if (!IsValidEdict(replacement)) return;
			
			TeleportEntity(replacement, origin, angles, NULL_VECTOR);
			PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum_spawn now", replacement);
			
			if (IsValidEdict(prev)) RemoveEdict(prev);
		}
		prev = ent;
	}
	if (prev)
	{
		GetEntPropVector(prev, Prop_Send, "m_vecOrigin", origin);
		GetEntPropVector(prev, Prop_Send, "m_angRotation", angles);
			
		replacement = CreateEntityByName("weapon_pistol");
		DispatchSpawn(replacement);
		PrintToChatAll("Replacing weapon_magnum_spawn %i with weapon_pistol %i", prev, replacement);
		if (!IsValidEdict(replacement)) return;
			
		TeleportEntity(replacement, origin, angles, NULL_VECTOR);
		PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum_spawn now", replacement);
			
		if (IsValidEdict(prev)) RemoveEdict(prev);
	}
}
chinagreenelvis is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 03-31-2012 , 05:17   Re: [L4D2] Disable Magnum
Reply With Quote #3

PHP Code:
public OnPluginStart()
{
    
HookEvent("round_start"Event_Round_Start);
}

public 
Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
    
CreateTimer(10.0ReplaceMagnumDelay);
}

public 
Action:ReplaceMagnumDelay(Handle:timer)
{
    
ReplaceMagnum();
}

ReplaceMagnum()
{

    new 
ent = -1;
    new 
prev 0;
    new 
replacement;
    
decl Float:origin[3];
    
decl Float:angles[3];
    while ((
ent FindEntityByClassname(ent"weapon_magnum_spawn")) != -1)
    {
        if (
prev)
        {
            
GetEntPropVector(prevProp_Send"m_vecOrigin"origin);
            
GetEntPropVector(prevProp_Send"m_angRotation"angles);
            
            
replacement CreateEntityByName("weapon_pistol");
            
DispatchSpawn(replacement);
            
PrintToChatAll("Replacing weapon_magnum_spawn %i with weapon_pistol %i"prevreplacement);
            if (!
IsValidEdict(replacement)) return;
            
            
TeleportEntity(replacementoriginanglesNULL_VECTOR);
            
PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum_spawn now"replacement);
            
            if (
IsValidEdict(prev)) RemoveEdict(prev);
        }
        
prev ent;
    }
    if (
prev)
    {
        
GetEntPropVector(prevProp_Send"m_vecOrigin"origin);
        
GetEntPropVector(prevProp_Send"m_angRotation"angles);
            
        
replacement CreateEntityByName("weapon_pistol");
        
DispatchSpawn(replacement);
        
PrintToChatAll("Replacing weapon_magnum_spawn %i with weapon_pistol %i"prevreplacement);
        if (!
IsValidEdict(replacement)) return;
            
        
TeleportEntity(replacementoriginanglesNULL_VECTOR);
        
PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum_spawn now"replacement);
            
        if (
IsValidEdict(prev)) RemoveEdict(prev);
    }
    while ((
ent FindEntityByClassname(ent"weapon_spawn")) != -1)
    {
        if (
prev)
        {
            
GetEntPropVector(prevProp_Send"m_vecOrigin"origin);
            
GetEntPropVector(prevProp_Send"m_angRotation"angles);
            
            
replacement CreateEntityByName("weapon_pistol");
            
DispatchSpawn(replacement);
            
PrintToChatAll("Replacing weapon_magnum_spawn %i with weapon_pistol %i"prevreplacement);
            if (!
IsValidEdict(replacement)) return;
            
            
TeleportEntity(replacementoriginanglesNULL_VECTOR);
            
PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum_spawn now"replacement);
            
            if (
IsValidEdict(prev)) RemoveEdict(prev);
        }
        
decl String:weptospawn[32];
        
GetEntPropString(entProp_Data"m_iszWeaponToSpawn"weptospawnsizeof(weptospawn));
        if(
StrContains(weptospawn"any_pistol"false) != -|| StrContains(weptospawn"weapon_pistol_magnum"false) != -1)
        {
            
prev ent;
        }
    }
    if (
prev)
    {
        
GetEntPropVector(prevProp_Send"m_vecOrigin"origin);
        
GetEntPropVector(prevProp_Send"m_angRotation"angles);
            
        
replacement CreateEntityByName("weapon_pistol");
        
DispatchSpawn(replacement);
        
PrintToChatAll("Replacing weapon_magnum_spawn %i with weapon_pistol %i"prevreplacement);
        if (!
IsValidEdict(replacement)) return;
            
        
TeleportEntity(replacementoriginanglesNULL_VECTOR);
        
PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum_spawn now"replacement);
            
        if (
IsValidEdict(prev)) RemoveEdict(prev);
    }

A bit repetitious, but it should filter almost all magnums. It can't really filter a weapon_spawn marked to spawn "any" weapon.
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 03-31-2012 , 13:51   Re: [L4D2] Disable Magnum
Reply With Quote #4

Interesting. Would it make more sense to leave the magnums in tact but cheat-give the person who picks one up dual pistols instead?
chinagreenelvis is offline
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 03-31-2012 , 21:21   Re: [L4D2] Disable Magnum
Reply With Quote #5

Well, I can't seem to find out what event is triggered when magnums or pistols are picked up. It seems it doesn't work with "item_pickup", "ammo_pickup", or even "weapon_pickup."
chinagreenelvis is offline
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 04-01-2012 , 23:49   Re: [L4D2] Disable Magnum
Reply With Quote #6

Trying this. It gets to the point where it prints "Saw Magnum!" but doesn't do the replacement.

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0.0"

public Plugin:myinfo 
{
    
name "[L4D2] Replace Magnum",
    
author "chinagreenelvis",
    
description "Replaces Magnum with pistol.",
    
version PLUGIN_VERSION,
    
url "http://forums.alliedmods.net"    
}

public 
OnPluginStart()
{
    
HookEvent("weapon_spawn_visible"Event_WeaponSpawnVisible);
}

public 
Action:Event_WeaponSpawnVisible(Handle:event, const String:name[], bool:dontBroadcast)
{
    
PrintToChatAll("Saw Weapon Spawn!");
    
decl String:weapon[16];
    
GetEventString(event"weaponname"weaponsizeof(weapon));
    if (
StrEqual(weapon"pistol_magnum")) 
    { 
        
PrintToChatAll("Saw Magnum!");
        new 
ent = -1;
        new 
replacement;
        
decl Float:origin[3];
        
decl Float:angles[3];
        while ((
ent FindEntityByClassname(ent"weapon_magnum")) != -1)
        {
            if (
ent)
            {
                
GetEntPropVector(entProp_Send"m_vecOrigin"origin);
                
GetEntPropVector(entProp_Send"m_angRotation"angles);
            
                
replacement CreateEntityByName("weapon_pistol");
                
DispatchSpawn(replacement);
                
PrintToChatAll("Replacing weapon_magnum %i with weapon_pistol %i"entreplacement);
                if (!
IsValidEdict(replacement)) return;
                
                
TeleportEntity(replacementoriginanglesNULL_VECTOR);
                
PrintToChatAll("Teleported weapon_pistol %i into position, removing weapon_magnum now"replacement);
                
                if (
IsValidEdict(ent)) RemoveEdict(ent);
            }
        }
    }

chinagreenelvis is offline
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 04-02-2012 , 00:36   Re: [L4D2] Disable Magnum
Reply With Quote #7

Ugh. What the heck is the name of the magnum entity once it has been spawned?
chinagreenelvis is offline
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 04-02-2012 , 01:23   Re: [L4D2] Disable Magnum
Reply With Quote #8

Quote:
A bit repetitious, but it should filter almost all magnums. It can't really filter a weapon_spawn marked to spawn "any" weapon.
Still not working for me, by the way. Thanks for trying, though! Not sure why it doesn't have any effect. For the record, I'm playtesting on Crash Course, where the first magnum spawn is under the bridge, outside the first window you're forced to go through.

Last edited by chinagreenelvis; 04-02-2012 at 01:25.
chinagreenelvis is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 04-02-2012 , 02:27   Re: [L4D2] Disable Magnum
Reply With Quote #9

I just remembered that it's not weapon_magnum or weapon_magnum_spawn, but instead weapon_pistol_magnum and weapon_pistol_magnum_spawn.
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
asto
Member
Join Date: Aug 2010
Old 04-04-2012 , 14:59   Re: [L4D2] Disable Magnum
Reply With Quote #10

Simple way is using Stripper:Source.
http://forums.alliedmods.net/showthread.php?t=39439

Add this to global_filters.cfg to replace magnums:
Code:
modify:
{
    match:
    {    
    "classname" "weapon_pistol_magnum_spawn"
    }
    replace:
    {
    "classname" "weapon_pistol_spawn"
    }
}
asto 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 15:39.


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