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

Weapon blocking/replacing


Post New Thread Reply   
 
Thread Tools Display Modes
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-21-2014 , 02:56   Re: Weapon blocking/replacing
Reply With Quote #11

Pretty sure that nounlocks plugin has an invert option to blacklist instead of whitelist
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
SmackDaddy
Veteran Member
Join Date: Oct 2009
Old 01-23-2014 , 16:19   Re: Weapon blocking/replacing
Reply With Quote #12

Quote:
Originally Posted by friagram View Post
Pretty sure that nounlocks plugin has an invert option to blacklist instead of whitelist
Would love to know how to do this....did a search and unless I overlooked a result, I couldn't find it....will try again, but if someone knows how to do this, it would be very much appreciated! Thank you.
SmackDaddy is offline
DarthNinja
SourceMod Plugin Approver
Join Date: Mar 2009
Location: PreThinkHook()
Old 01-23-2014 , 17:24   Re: Weapon blocking/replacing
Reply With Quote #13

Quote:
Cvars:
A config will be auto-generated on first run, located in your cfg/sourcemod folder. Change any permanent settings there.
  • sm_tnounlockspls_enable - enables, disables the plugin
  • sm_tnounlockspls_default - set to 1 to replace weapons by default, set to 0 to keep
__________________
DarthNinja is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-26-2014 , 03:57   Re: Weapon blocking/replacing
Reply With Quote #14

Edit 3:

Replace a weapon with another weapon
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>
#include <sdkhooks>

#define PLUGIN_VERSION                  "0x02"

public Plugin:myinfo = {
    
name "Replace weapons",
    
author "Chdata",
    
description "Hexy.",
    
version PLUGIN_VERSION,
    
url "http://steamcommunity.com/groups/tf2data"
};

public 
OnPluginStart()
{
    
HookEvent("post_inventory_application"evEquipped);
}

/*
On spawn, see if we need to replace a weapon for another one

*/
public Action:evEquipped(Handle:hEvent, const String:sName[], bool:bDontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(hEvent"userid"));
    
    new 
weapon GetPlayerWeaponSlot(clientTFWeaponSlot_Primary);

    if (
weapon != -1)
    {
        new 
index GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");

        switch (
index)
        {
            case 
561005//Huntsman
            
{
                
TF2_RemoveWeaponSlot(clientTFWeaponSlot_Primary);
                
SpawnWeapon(client"tf_weapon_sniperrifle"1490"");
            }
        }
    }

    return 
Plugin_Continue;
}

/*
Prepares an item to be given to someone

*/
stock SpawnWeapon(clientString:name[], indexlevelqualString:att[])
{
    new 
Handle:hWeapon TF2Items_CreateItem(OVERRIDE_ALL FORCE_GENERATION);

    if (
hWeapon == INVALID_HANDLE)
    {
        return -
1;
    }

    
TF2Items_SetClassname(hWeaponname);
    
TF2Items_SetItemIndex(hWeaponindex);
    
TF2Items_SetLevel(hWeaponlevel);
    
TF2Items_SetQuality(hWeaponqual);

    new 
String:atts[32][32];
    new 
count ExplodeString(att" ; "atts3232);

    if (
count 0)
    {
        
TF2Items_SetNumAttributes(hWeaponcount 2);

        new 
i2 0;

        for (new 
0count+= 2)
        {
            
TF2Items_SetAttribute(hWeaponi2StringToInt(atts[i]), StringToFloat(atts[1]));
            
i2++;
        }
    }
    else
    {
        
TF2Items_SetNumAttributes(hWeapon0);
    }

    new 
entity TF2Items_GiveNamedItem(clienthWeapon);

    
CloseHandle(hWeapon);
    
EquipPlayerWeapon(cliententity);

    return 
entity;

__________________

Last edited by Chdata; 01-30-2014 at 00:30.
Chdata is offline
SmackDaddy
Veteran Member
Join Date: Oct 2009
Old 01-26-2014 , 20:09   Re: Weapon blocking/replacing
Reply With Quote #15

I can most certainly see what you are saying to replace as far as the Slot weapon name, but what do the numbers in the following code represent and where would I find them for the other weapons I would like to block?

PHP Code:
switch (index)
        {
            case 
561005//Huntsman
            
{
                
TF2_RemoveWeaponSlot(clientTFWeaponSlot_Primary);
                
weapon SpawnWeapon(client"tf_weapon_sniperrifle"1490"");
            }
        } 
So, what do the numbers 56, 1005 represent and where do I find them for other weapons? And the 14,9,0 on the last line, what do those represent and where do I find those numbers? I presume the "SpawnWeapon(client," section is the replaced weapon if the huntsman is tried to be equipped? Can multiple weapons be added to that "switch (index)" area?

Also, is this a standalone or require an additional extension?

Thank you in advance for your assistance!

Also, this question is for anyone and I am still unable to get an answer on this, but how does one block the danger shield on a sniper server? It's not a "weapon" and weapon blocking plugins don't seem to work for a cosmetic item with attributes.....

Last edited by SmackDaddy; 01-26-2014 at 20:10.
SmackDaddy is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-27-2014 , 05:15   Re: Weapon blocking/replacing
Reply With Quote #16

Quote:
Originally Posted by Chdata View Post
Edit 3:

Replace a weapon with another weapon
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>
#include <sdkhooks>

#define PLUGIN_VERSION                  "0x03"

//Teams
#define TEAM_RED    2
#define TEAM_BLU    3

public Plugin:myinfo = {
    
name "Sniper Server Setup",
    
author "Chdata",
    
description "Hexy.",
    
version PLUGIN_VERSION,
    
url "http://steamcommunity.com/groups/tf2data"
};

public 
OnPluginStart()
{
    
HookEvent("post_inventory_application"evEquipped);
}

/*
On spawn, see if we need to replace a weapon for another one

*/
public Action:evEquipped(Handle:hEvent, const String:sName[], bool:bDontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(hEvent"userid"));
    
    if (
GetClientTeam(client) != TEAM_BLU && GetClientTeam(client) != TEAM_RED)
        return 
Plugin_Continue;

    if (!(
g_iEnabledFlags SNIPER_FLAG_NOHUNTSMAN))
    {
        return 
Plugin_Continue;
    }

    new 
weapon GetPlayerWeaponSlot(clientTFWeaponSlot_Primary);
    new 
index = -1;

    if (
weapon MaxClients && IsValidEdict(weapon))
    {
        
index GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");

        switch (
index)
        {
            case 
561005//Huntsman
            
{
                
TF2_RemoveWeaponSlot(clientTFWeaponSlot_Primary);
                
weapon SpawnWeapon(client"tf_weapon_sniperrifle"1490"");
            }
        }
    }

    return 
Plugin_Continue;
}

/*
Prepares an item to be given to someone

*/
stock SpawnWeapon(clientString:name[], indexlevelqualString:att[])
{
    new 
Handle:hWeapon TF2Items_CreateItem(OVERRIDE_ALL FORCE_GENERATION);

    if (
hWeapon == INVALID_HANDLE)
    {
        return -
1;
    }

    
TF2Items_SetClassname(hWeaponname);
    
TF2Items_SetItemIndex(hWeaponindex);
    
TF2Items_SetLevel(hWeaponlevel);
    
TF2Items_SetQuality(hWeaponqual);

    new 
String:atts[32][32];
    new 
count ExplodeString(att" ; "atts3232);

    if (
count 0)
    {
        
TF2Items_SetNumAttributes(hWeaponcount 2);

        new 
i2 0;

        for (new 
0count+= 2)
        {
            
TF2Items_SetAttribute(hWeaponi2StringToInt(atts[i]), StringToFloat(atts[1]));
            
i2++;
        }
    }
    else
    {
        
TF2Items_SetNumAttributes(hWeapon0);
    }

    new 
entity TF2Items_GiveNamedItem(clienthWeapon);

    
CloseHandle(hWeapon);
    
EquipPlayerWeapon(cliententity);

    return 
entity;

sometimes even I'm not lazy
Using the spawnweapon stock instead of just using the tf2items natives is kind of lazy, and inefficient :/

Also, why dont you just do if getclientteam < 2? 0 is unassigned, 1 is spec. In this case, you do not even need it.. Inv app only fires for alive players who have teams. Playerspawn fires for people on team 0 the first time they join the server, but you are not using that.

if (weapon > MaxClients && IsValidEdict(weapon)) can be replaced with if weapon != -1

You do not need to make an index variable, just put the getentprop in the switch....
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 01-27-2014 at 05:21.
friagram is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-27-2014 , 13:21   Re: Weapon blocking/replacing
Reply With Quote #17

I use what works ;p

Plus considering there exists a stock for spawning weapons, I assumed TF2Items just didn't already come with one.

That getclientteam was left over from something that actually used playerspawn. The fact that it's not <2 is because it's from someone else's code so I didn't bother to think about whether or not it's written efficiently. Same with the Edict thing. Even the index thing.

Though, I probably would've left out the weapon < MaxClients when the IsValidEdict is already there if I were paying attention.

Though, does weapon != -1 really work as an adequate replacement for IsValidEdict? I don't know if IsValidEdict has any other checks in it that I don't know about, considering the include file only says

PHP Code:
/**
 * Returns whether or not an edict index is valid.
 *
 * @param edict            Index of the edict.
 * @return                True if valid, false otherwise.
 */
native bool:IsValidEdict(edict); 
So I have no clue how it really checks that.

As for "What do these numbers mean"
https://wiki.alliedmods.net/Team_For....5BSlot_0.5D_6

And in spawn weapon

stock SpawnWeapon(client, String:name[], index, level, qual, String:att[])

Name, index, level quality, attribs should be obvious enough.
__________________

Last edited by Chdata; 01-27-2014 at 13:34.
Chdata is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-28-2014 , 02:39   Re: Weapon blocking/replacing
Reply With Quote #18

Quote:
GetPlayerWeaponSlot

Syntax:
native GetPlayerWeaponSlot(client, slot);

Usage:
client Client index.
slot Slot index (mod specific).
Notes:
Returns the weapon in a player's slot.

Return:
Entity index on success, -1 if no weapon existed
If you understand how the spawnweapon stock works, you'll see all it does is parse a string to get attribs, and then throw the args into tf2item natives.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-28-2014 , 14:19   Re: Weapon blocking/replacing
Reply With Quote #19

In my case I've only ever used it to give weapons with custom attribs though, but yea I could've trimmed it down for simple find/replacing weapons.

(This code comes from a small plugin I made for a sniper server where huntsman is replaced with a sniper rifle that has shooting while unscoped disabled).

Also thanks for the tips, I appreciate it ;p

Edit: I looked at it again and I'm surprised noone noticed I left in completely irrelevant stuff like that SNIPER_FLAG_NOHUNTSMAN that was undefined.

Anyway, now it should work as a standalone plugin (I edited the old post).
__________________

Last edited by Chdata; 01-30-2014 at 00:32.
Chdata is offline
Kincyr
Junior Member
Join Date: Jan 2013
Old 04-14-2014 , 00:45   Re: Weapon blocking/replacing
Reply With Quote #20

Quote:
Originally Posted by SmackDaddy View Post
Also, this question is for anyone and I am still unable to get an answer on this, but how does one block the danger shield on a sniper server? It's not a "weapon" and weapon blocking plugins don't seem to work for a cosmetic item with attributes.....
no plugin needed. add the following line to your server's item_whitelist.txt file:
Code:
"Darwin's Danger Shield" "0"
Kincyr 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 13:25.


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