Raised This Month: $ Target: $400
 0% 

Merging plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SmackDaddy
Veteran Member
Join Date: Oct 2009
Old 09-24-2015 , 14:17   Merging plugins
Reply With Quote #1

I have a couple plugins which block specific weapons from being used....but I'd like to merge them into one plugin in the most efficient way possible. I am not a sourcepawn scripter but am willing to learn....I am providing an example of one of the plugins.....the other plugin is almost identical except that the weapon index that is referenced is different.

Code:
#define WEP_DEX_Medigun 35

public OnPluginStart()
{
	//HookEvent("player_spawn", Event_player_spawn);
	CreateTimer(0.1, Timer_DoEquip, 0, TIMER_REPEAT);
}


public Action:Timer_DoEquip(Handle:timer, any:derp)
{
	for(new client=1; client <= MaxClients; client++)
	{		
		if(IsClientInGame(client) && IsPlayerAlive(client))
		{		
			new slot1 = GetPlayerWeaponSlot(client, 1);
						
			if(TF2_GetPlayerClass(client) == TFClass_Medic)
			{
				if(slot1 > MaxClients && IsValidEntity(slot1) && GetEntProp(slot1, Prop_Send, "m_iItemDefinitionIndex") == WEP_DEX_Medigun)
				{
					TF2_RemoveWeaponSlot(client, 1);
					PrintToChat(client, "The Kritzkrieg is blocked and broken due to the Crits mod here");
				}
			}
		}	
	}
}
(this blocks the Kritzkrieg, and another one written almost like it blocks the quick-fix)

Thank you in advance for any help that is provided!
SmackDaddy is offline
R1KO
Member
Join Date: Sep 2013
Old 09-24-2015 , 14:33   Re: Merging plugins
Reply With Quote #2

PHP Code:
#define WEP_DEX_Medigun 35
#define WEP_DEX_Weapon2 33 // second weapon index

public OnPluginStart()
{
    
//HookEvent("player_spawn", Event_player_spawn);
    
CreateTimer(0.1Timer_DoEquip0TIMER_REPEAT);
}


public 
Action:Timer_DoEquip(Handle:hTimer)
{
    
decl iClientiWeaponiSlot;
    for(
iClient=1iClient <= MaxClients; ++iClient)
    {        
        if(
IsClientInGame(iClient) && IsPlayerAlive(iClient) && TF2_GetPlayerClass(iClient) == TFClass_Medic)
        {        
            if((
iSlot GetPlayerWeaponSlot(iClient1)) != -1)
            {
                
iWeapon GetEntProp(iSlotProp_Send"m_iItemDefinitionIndex");
                if(
iWeapon == WEP_DEX_Medigun ||
                    
iWeapon == WEP_DEX_Weapon2)
                {
                    
TF2_RemoveWeaponSlot(iClient1);
                    
PrintToChat(iClient"The Kritzkrieg is blocked and broken due to the Crits mod here");
                }
            }
        }    
    }

but this is best done when a player is trying to buy or take up arms

Last edited by R1KO; 09-24-2015 at 14:33.
R1KO is offline
Send a message via Skype™ to R1KO
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 09-24-2015 , 15:04   Re: Merging plugins
Reply With Quote #3

Instead of having a constantly repeating timer, you can use TF2Items_OnGiveNamedItem to stop spawning the weapon in the first place. It's also a lot more cleaner.

PHP Code:
#include <sourcemod>
#define WEP_DEX_Medigun 35
#define WEP_DEX_QuickFix 411

public Action TF2Items_OnGiveNamedItem(int clientchar[] classnameint indexHandle &hItem)
{
    if(
index == WEP_DEX_Medigun)
    {
        
PrintToChat(client"The Kritzkrieg is blocked and broken due to the Crits mod here"); 
        return 
Plugin_Handled;
    }
    else if(
index == WEP_DEX_QuickFix)
    {
        
PrintToChat(client"The Quick-Fix is blocked and broken due to the Crits mod here"); 
        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;

__________________
Chaosxk is offline
SmackDaddy
Veteran Member
Join Date: Oct 2009
Old 09-24-2015 , 15:10   Re: Merging plugins
Reply With Quote #4

Wow Chaos, I will try that...it almost looks too simple to work! ;) I am not sure why the code was written with a timer unless it was simply checking to be sure someone didn't try and change weapons and hit the locker to try and spawn it again ....*shrugs*
SmackDaddy is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 09-24-2015 , 15:13   Re: Merging plugins
Reply With Quote #5

They probably didn't know of the function. TF2Items_OnGiveNamedItem detect any sorts of weapon change, from locker to players loadout.
__________________
Chaosxk is offline
SmackDaddy
Veteran Member
Join Date: Oct 2009
Old 09-24-2015 , 15:19   Re: Merging plugins
Reply With Quote #6

So the player class doesn't even need to be identified or referenced then eh? Interesting! Thanks again, will try it out in a little bit and report back!
SmackDaddy is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-24-2015 , 19:07   Re: Merging plugins
Reply With Quote #7

Simply removing weapons is a bad idea... it's a better idea to use TF2Items and replace them with the stock version of the item.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
SmackDaddy
Veteran Member
Join Date: Oct 2009
Old 09-24-2015 , 19:29   Re: Merging plugins
Reply With Quote #8

Tried at one point and couldn't get it to work, that's why I've been using this and it's worked ok for us.....maybe I'll look into TF2Items again over the weekend.
SmackDaddy is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-24-2015 , 21:38   Re: Merging plugins
Reply With Quote #9

Oh right, I should probably mention that changing one weapon index into another in TF2Items_OnGiveNamedItem only works if they're the same item class. Something about the game validating the item and it notices the classname change and blocks it.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-24-2015 , 23:30   Re: Merging plugins
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
Oh right, I should probably mention that changing one weapon index into another in TF2Items_OnGiveNamedItem only works if they're the same item class. Something about the game validating the item and it notices the classname change and blocks it.
This should be documented on tf2items.inc itself.
Potato Uno 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 11:35.


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