AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CurWeapon jitter (https://forums.alliedmods.net/showthread.php?t=58040)

Vet 07-17-2007 13:39

CurWeapon jitter
 
I wrote a quickie plugin for knives-only for DOD and it works for almost all players. But a few players can circumvent the plugin by quickly switching weapons back and forth. Its like the CurWeapon event isn't being caught and processed every time for them. So the code works. But a few players can trick it somehow. I've tried various combinations of event conditions, and tried putting a weapon check in the event function, but none of that made any difference. Any ideas why?

Code:


#include <amxmodx>
#include <amxmisc>
 
new g_enable
 
public plugin_init() {
g_enabled = register_cvar("knivesonly_enable", "0")
    register_plugin("Knives Only", "0.1", "Vet")
    register_event("CurWeapon", "knivesonly", "be", "1=1", "2!1", "2!2", "2!19", "2!37)
}
 
public knivesonly(id) {
    if (get_pcvar_num(g_enable))
        client_cmd(id, "weapon_knife")
}


kp_uparrow 07-17-2007 14:04

Re: CurWeapon jitter
 
why not just download the knifes only plugin? well if they shoot the other weapon they are gona switch to knife again, curweapon doesnt catch all when the switch really fast

Rolnaaba 07-17-2007 16:28

Re: CurWeapon jitter
 
I am supprised this line compiled, you have an unterminated string...
Code:
public plugin_init() {  g_enabled = register_cvar("knivesonly_enable", "0")     register_plugin("Knives Only", "0.1", "Vet")     register_event("CurWeapon", "knivesonly", "be", "1=1", "2!1", "2!2", "2!19", "2!37) }

ConnorMcLeod 07-17-2007 17:34

Re: CurWeapon jitter
 
Replace

client_cmd(id, "weapon_knife")

by

engclient_cmd(id, "weapon_knife")

kp_uparrow 07-17-2007 18:19

Re: CurWeapon jitter
 
Quote:

Originally Posted by connorr (Post 504571)
Replace

client_cmd(id, "weapon_knife")

by

engclient_cmd(id, "weapon_knife")

how much cpu is this gonna save?

ones through cmd and ones through client's engine or something right?

Vet 07-17-2007 19:18

Re: CurWeapon jitter
 
Ya, the example code was just hand typed in and is not the actual code I'm using. Its just a representation for my question.

The whole point isn't the code itself. The point is, that a few players in the game are able to exploit/circumvent the CurWeapon event by quickly switching weapons back and forth with invprev, or continually pressing a gun key.

Quote:

Originally Posted by kp_uparrow (Post 504466)
curweapon doesnt catch all when the switch really fast

I think you understand what I'm getting at. So if what you say is true, that the CurWeapon event doesn't catch all, then what good is it? And why are only a few players, not everyone, able to do it?

Wilson [29th ID] 07-17-2007 19:32

Re: CurWeapon jitter
 
A much better method would be to alter the pev_weapons variable. Use the following stock to "remove" the weapons from the variable:

Code:
stock remove_weapon( id, wpnid ) {     new m_bitmask = pev( id, pev_weapons );     m_bitmask &= ~(1<<wpnid);         set_pev( id, pev_weapons, m_bitmask ); }

For what you want to do, however, since all you want is a knife for any class, I would alter the pev_weapons bitmask to only include DODW_AMERKNIFE (if british or american) or DODW_GERKNIFE / DODW_SPADE (if axis) and simply set the variable to that bitmask.

This way you won't have to worry about sending client commands and switching weapons and risking a "reach-around" - it prevents the client from pulling out the weapon in the first place.

For a very basic example:

Code:
stock allow_weapon( id, wpnid ) {     new m_bitmask &= (1<<wpnid);         set_pev( id, pev_weapons, m_bitmask ); }

Then allow_weapon( id, DODW_AMERKNIFE ) if the player is allies, etc.

stupok 07-17-2007 21:13

Re: CurWeapon jitter
 
I had no idea you could do such a thing! Thanks for posting that Wilson :D

Vet 07-17-2007 21:29

Re: CurWeapon jitter
 
That's a good idea. I'll give it a try.

Currently, since the other method didn't work perfectly, I used fm_strip_user_weapons and fm_give_item to accomplish it. And all worked great. But then, another problem popped up. The players were still able to pick up weapons on the ground left by dead players. OK, so I added a routine to remove the dead weapons when touched. Everything was honky-dorey when tested on a listen server. But to my dismay, after being installed on the game server, the strip function would not act on a live player if the plugin was enabled mid-game. I checked for plugin contention, but couldn't find anything obvious.

So Wilson, in your opinion, can the CurWeapon event be a bit iffy at times?

stupok 07-17-2007 23:22

Re: CurWeapon jitter
 
If I understood Wilson correctly, removing a weapon from the player's bit mask disables the player from accessing that weapon altogether.

I think this would work, using Wilson's suggestion. (It's probably not the best or most efficient way, though.)

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <dodconst>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "stupok69"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("ResetHUD""event_resethud")
}

public 
event_resethud(id)
{
    
remove_all_weapons(id)
    
    
// I don't know how to properly check the team for DoD.
    
    
if(pev(idpev_team) == ALLIES)
    {
        
allow_weapon(idDODW_AMERKNIFE)
        
allow_weapon(idDODW_BRITKNIFE)
    }
    else
    {
        
allow_weapon(idDODW_GERKNIFE)
        
allow_weapon(idDODW_SPADE)
    }
}

stock remove_all_weapons(id)
{
    new 
m_bitmask pev(idpev_weapons)
    
    for(new 
1<= 41i++)
    {
        
m_bitmask &= ~(1<<i)
    }
    
    
set_pev(idpev_weaponsm_bitmask)
}

stock remove_weapon(idwpnid)
{
    new 
m_bitmask pev(idpev_weapons)
    
m_bitmask &= ~(1<<wpnid)
    
    
set_pev(idpev_weaponsm_bitmask)
}

stock allow_weapon(idwpnid)
{
    new 
m_bitmask &= (1<<wpnid)
    
    
set_pev(idpev_weaponsm_bitmask)




All times are GMT -4. The time now is 21:30.

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