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

[l4d 2] melee limit enforcer


Post New Thread Reply   
 
Thread Tools Display Modes
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 01-03-2011 , 13:36   Re: [l4d 2] melee limit enforcer
Reply With Quote #11

Thats why you put debug lines (read: PrintToChatAlls) all over the code during concept phase.

One breaker i could see right now is
PHP Code:
new secondary GetPlayerWeaponSlot(client0); 
Melee weapons are not in the primary slot 0, they are in the secondary slot, 1.
AtomicStryker is offline
GanjaStar
Senior Member
Join Date: Jun 2009
Old 01-03-2011 , 14:03   Re: [l4d 2] melee limit enforcer
Reply With Quote #12

Quote:
Originally Posted by AtomicStryker View Post
Thats why you put debug lines (read: PrintToChatAlls) all over the code during concept phase.

One breaker i could see right now is
PHP Code:
new secondary GetPlayerWeaponSlot(client0); 
Melee weapons are not in the primary slot 0, they are in the secondary slot, 1.
thx, will give it a go.

oe thing, what about this line?

Code:
ent = GetPlayerWeaponSlot(i, 0);
im going to test with that both at 1 and 0 probably before you respond, but im still putting it out there

as for the print chat to all thing, i would probalby spend more time figuring out how to add that into the plugin, then it would take me to do the actual troubleshooting

i am guilty of playing more then learing sourcemod. but that might change in the future
GanjaStar is offline
GanjaStar
Senior Member
Join Date: Jun 2009
Old 01-05-2011 , 05:17   Re: [l4d 2] melee limit enforcer
Reply With Quote #13

i tried both your suggestion and even with mine, still nothing.

Would be great if sometimes in the future you find a few min for this.

I won't keep bumping it though cause i feel bad always mooching of your coding skills. thx for all the help.
GanjaStar is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 01-05-2011 , 13:14   Re: [l4d 2] melee limit enforcer
Reply With Quote #14

Another breaker would be the WC_OnModuleStart() where OnPluginStart() would have to stand ahahahahaha
AtomicStryker is offline
GanjaStar
Senior Member
Join Date: Jun 2009
Old 01-05-2011 , 23:50   Re: [l4d 2] melee limit enforcer
Reply With Quote #15

Thx agian, i tried with all your suggestions.

and even tried both
Code:
ent = GetPlayerWeaponSlot(i, 0);
and
Code:
ent = GetPlayerWeaponSlot(i, 1)
; since im nost sure if im supposed to change it there as well.

the only thing i could see myself messing up is putting this in cfg but i don't think thats it:

l4d2_limit_melee 2
GanjaStar is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 01-06-2011 , 06:05   Re: [l4d 2] melee limit enforcer
Reply With Quote #16

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define TEST_DEBUG            0
#define TEST_DEBUG_LOG        0

static const MELEE_WEAPON_SLOT 1;

new 
Handle:WC_hLimitCount;
new 
String:WC_sLastWeapon[64];
new 
WC_iLimitCount 1;
new 
WC_iLastWeapon = -1;
new 
WC_iLastClient = -1;

static        
Handle:DROPPED_STUFF_ARRAY        INVALID_HANDLE;


public 
OnPluginStart()
{
    
WC_hLimitCount CreateConVar("l4d2_limit_melee""1""Limits the maximum number of melee weapons at one time to this number");
    
HookConVarChange(WC_hLimitCountWC_ConVarChange);
    
WC_iLimitCount GetConVarInt(WC_hLimitCount);
    
    
HookEvent("player_use"WC_PlayerUse_Event);
    
HookEvent("weapon_drop"WC_WeaponDrop_Event);
    
    
DROPPED_STUFF_ARRAY CreateArray();
}

public 
OnMapStart()
{
    
ClearArray(DROPPED_STUFF_ARRAY);
    
WC_iLimitCount GetConVarInt(WC_hLimitCount);
}

public 
WC_ConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    
WC_iLimitCount GetConVarInt(WC_hLimitCount);
}

public 
Action:WC_WeaponDrop_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
    
// this code saves a user and the gun he drops in the moment of dropping, in order to revert this if hes picking up something blocked

    
WC_iLastWeapon GetEventInt(event"propid");
    
WC_iLastClient GetClientOfUserId(GetEventInt(event"userid"));
    
GetEventString(event"item"WC_sLastWeaponsizeof(WC_sLastWeapon));
    
    if (!
WC_iLastClient || !IsClientInGame(WC_iLastClient)) return;
    
    
PushArrayCell(DROPPED_STUFF_ARRAYWC_iLastWeapon);
    
    
DebugPrintToAll("Player %N dropped event item %s"WC_iLastClientWC_sLastWeapon);
}

public 
Action:WC_PlayerUse_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
item GetEventInt(event"targetid");
    
    if (
HasBeenDropped(item))
    {
        return;
    }

    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (!
client || !IsClientInGame(client)) return;
    
    new 
secondary GetPlayerWeaponSlot(clientMELEE_WEAPON_SLOT);
    
    
decl String:stringbuffer[64];
    
GetEdictClassname(secondarystringbuffersizeof(stringbuffer));
    
    
DebugPrintToAll("Player %N picked %s up"clientstringbuffer);
    
    if (
StrEqual(stringbuffer"weapon_melee"))
    {
        if (
GetMeleeWeaponCount() > WC_iLimitCount)
        {
            if (
IsValidEdict(secondary))
            {
                
RemovePlayerItem(clientsecondary);
                
PrintToChat(client"Maximum number of %i melee weapon(s) is enforced."WC_iLimitCount);
            }
            
            if (
WC_iLastClient == client)
            {
                if (
IsValidEdict(WC_iLastWeapon))
                {
                    if (!
StrEqual(WC_sLastWeapon"melee"))
                    {
                        
AcceptEntityInput(WC_iLastWeapon"Kill");
                        
                        
Format(stringbuffersizeof(stringbuffer), "give %s"WC_sLastWeapon);
                    
                        new 
flags GetCommandFlags("give");
                        
SetCommandFlags("give"flags FCVAR_CHEAT);
                        
FakeClientCommand(clientstringbuffer);
                        
SetCommandFlags("give"flags);
                    }
                }
            }
        }
    }
    
    
WC_iLastWeapon = -1;
    
WC_iLastClient = -1;
}

static 
GetMeleeWeaponCount()
{
    new 
count 0;
    new 
ent = -1;
    
decl String:temp[64];
    
    for (new 
1MaxClients+1i++)
    {
        if (
IsClientConnected(i)
        && 
GetClientTeam(i) == 2
        
&& IsPlayerAlive(i))
        {
            
ent GetPlayerWeaponSlot(iMELEE_WEAPON_SLOT);
            if (
IsValidEdict(ent))
            {
                
GetEdictClassname(enttempsizeof(temp));
                
                if (
StrEqual(temp"weapon_melee"))
                    
count++;
            }
        }
    }
    
    
DebugPrintToAll("GetMeleeWeaponCount() returns %i"count);
    
    return 
count;
}

static 
bool:HasBeenDropped(item)
{
    new 
index FindValueInArray(DROPPED_STUFF_ARRAYitem);

    if (
index != -1)
    {
        
RemoveFromArray(DROPPED_STUFF_ARRAYindex);
        return 
true;
    }
    
    return 
false;
}

stock DebugPrintToAll(const String:format[], any:...)
{
    
#if (TEST_DEBUG || TEST_DEBUG_LOG)
    
decl String:buffer[256];
    
    
VFormat(buffersizeof(buffer), format2);
    
    
#if TEST_DEBUG
    
PrintToChatAll("[TEST] %s"buffer);
    
PrintToConsole(0"[TEST] %s"buffer);
    
#endif
    
    
LogMessage("%s"buffer);
    
#else
    //suppress "format" never used warning
    
if(format[0])
        return;
    else
        return;
    
#endif


Here, this one works.


And ive also added the second hand code for melee stuff.
Attached Files
File Type: sp Get Plugin or Get Source (l4d2_melee_limiter.sp - 567 views - 4.1 KB)

Last edited by AtomicStryker; 02-24-2011 at 12:15.
AtomicStryker is offline
GanjaStar
Senior Member
Join Date: Jun 2009
Old 01-06-2011 , 22:00   Re: [l4d 2] melee limit enforcer
Reply With Quote #17

works beautifully thx, you delivered again

and here and in the OP i will post the compiled plugin.

thx for the debug chat thing as well, will be nice for my attempts to code
Attached Files
File Type: smx l4d2_melee_limiter.smx (3.9 KB, 112 views)
File Type: sp Get Plugin or Get Source (l4d2_melee_limiter.sp - 283 views - 4.0 KB)

Last edited by GanjaStar; 01-06-2011 at 22:15.
GanjaStar is offline
GanjaStar
Senior Member
Join Date: Jun 2009
Old 01-08-2011 , 00:29   Re: [l4d 2] melee limit enforcer
Reply With Quote #18

in case you still care
Code:
SM] Native "IsClientConnected" reported: Client index 0 is invalid
L 01/06/2011 - 02:58:19: [SM] Displaying call stack trace for plugin "l4d2_melee_limiter_a.smx":
L 01/06/2011 - 02:58:19: [SM]   [0]  Line 86, /groups/sourcemod/upload_tmp/textHRdsJ9.sp::GetMeleeWeaponCount()
L 01/06/2011 - 02:58:19: [SM]   [1]  Line 48, /groups/sourcemod/upload_tmp/textHRdsJ9.sp::WC_PlayerUse_Event()
L 01/06/2011 - 02:58:21: [SM] Native "IsClientConnected" reported: Client index 0 is invalid
L 01/06/2011 - 02:58:21: [SM] Displaying call stack trace for plugin "l4d2_melee_limiter_a.smx":
L 01/06/2011 - 02:58:21: [SM]   [0]  Line 86, /groups/sourcemod/upload_tmp/textHRdsJ9.sp::GetMeleeWeaponCount()
L 01/06/2011 - 02:58:21: [SM]   [1]  Line 48, /groups/sourcemod/upload_tmp/textHRdsJ9.sp::WC_PlayerUse_Event()
L 01/06/2011 - 02:58:22: [SM] Native "IsClientConnected" reported: Client index 0 is invalid
L 01/06/2011 - 02:58:22: [SM] Displaying call stack trace for plugin "l4d2_melee_limiter_a.smx":
L 01/06/2011 - 02:58:22: [SM]   [0]  Line 86, /groups/sourcemod/upload_tmp/textHRdsJ9.sp::GetMeleeWeaponCount()
L 01/06/2011 - 02:58:22: [SM]   [1]  Line 48, /groups/sourcemod/upload_tmp/textHRdsJ9.sp::WC_PlayerUse_Event()
L 01/06/2011 - 02:58:23: [SM] Native "IsClientConnected" reported: Client index 0 is invalid
L 01/06/2011 - 02:58:23: [SM] Displaying call stack trace for plugin "l4d2_melee_limiter_a.smx":
this error is getting massively spamed
GanjaStar is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 01-08-2011 , 06:40   Re: [l4d 2] melee limit enforcer
Reply With Quote #19

See if you can figure that one out, its a very basic issue. Ive updated my code above with a fix anyway
AtomicStryker is offline
GanjaStar
Senior Member
Join Date: Jun 2009
Old 01-08-2011 , 10:18   Re: [l4d 2] melee limit enforcer
Reply With Quote #20

l4d2_melee_limiter_a

that was one of my attempts at fixing your non working version

thats not even the plugin name that i used for the one that works

silly me so i guess you didnt need to fix anything because the error relatees to a different plugin. thats why your code now doesn't compile.


sry to have wasted your time with that... im gonna be more careful next time :\

Last edited by GanjaStar; 01-08-2011 at 10:22.
GanjaStar 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 16:02.


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