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

Setting a client's maxspeed permanently and efficiently


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 06-10-2009 , 00:30   Setting a client's maxspeed permanently and efficiently
Reply With Quote #1

I'm trying to reach the best method of setting a client's maxspeed without hooking a "constant forward". To 1.0 (to block him)

I don't like to hook events (but it's still better than ClientCmdStart or PreThink) so, I tried to use ham hooks and also to hook FM_SetClientMaxspeed but, that didn't work so, i'm sticking with something like:

PHP Code:

register_event
("CurWeapon","eventCurWeapon""be","1=1")

...

public 
block(id)
{
    
blocked[id] = true
    
    engfunc
(EngFunc_SetClientMaxspeed,id,1.0)
    
    return 
PLUGIN_HANDLED
}

public 
eventCurWeapon(id)
{
    if(
blocked[id])
    {
        
engfunc(EngFunc_SetClientMaxspeed,id,1.0)
    }

It works and since I don't care about the resetting on round starts it's ok.

Now I want to be able to reset the maxspeed accordingly to the carrier's weapon.

I tried executing Ham_CS_Item_GetMaxSpeed but it returns 0.0 for the weapons I tested.

So my questions are:

Do you have a better way to handle the setting situation?

There is a way of getting the maxspeed related to a weapon without having it in the code?
___

A funny thing that happened to me during this process was that I tried Ham_CS_Item_GetMaxSpeed passing it a player, like:

PHP Code:
ExecuteHam(Ham_CS_Item_GetMaxSpeed,id,maxspeed
And this spawned from my body:

[IMG]http://img195.**************/img195/3701/deinferno0007c.th.jpg[/IMG]

So I guess that the offset that hamsandwich is using for Ham_CS_Item_GetMaxSpeed is instead for another function
__________________

Last edited by joaquimandrade; 06-10-2009 at 00:34.
joaquimandrade is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-10-2009 , 00:35   Re: Setting a client's maxspeed permanently efficiently
Reply With Quote #2

Quote:
Originally Posted by joaquimandrade View Post

PHP Code:
ExecuteHam(Ham_CS_Item_GetMaxSpeed,id,maxspeed
You passed player id.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 06-10-2009 , 00:36   Re: Setting a client's maxspeed permanently efficiently
Reply With Quote #3

Quote:
Originally Posted by ConnorMcLeod View Post
You passed player id.
Yes but, that was after (for testing). I tried with the weapon id.

Edit:

look:
PHP Code:
public unblock(id)
{
    
blocked[id] = false;
    
    new 
Float:maxspeed 123.123
    
    
new weapon get_pdata_cbase(id,373)
    
    
ExecuteHam(Ham_CS_Item_GetMaxSpeed,weapon,maxspeed)
    
    new class[
30]
    
pev(weapon,pev_classname,class,charsmax(class))
    
    
client_print(id,print_chat,"Max speed %f",maxspeed)
    
client_print(id,print_chat,"Weapon %s",class);
    
    
//engfunc(EngFunc_SetClientMaxspeed,id,maxspeed)
    
    
return PLUGIN_HANDLED;

Result:

Code:
Max speed 123.123001
Weapon weapon_knife
(I've gave a random value to the var maxspeed just to be sure that it wasn't returning 0.0)
__________________

Last edited by joaquimandrade; 06-10-2009 at 00:39.
joaquimandrade is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-10-2009 , 00:39   Re: Setting a client's maxspeed permanently efficiently
Reply With Quote #4

Quote:
Originally Posted by joaquimandrade View Post
Yes but, that was after (for testing). I tried with the weapon id.
Weapon Entity Id ? (works for me).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Old 06-10-2009, 00:40
joaquimandrade
This message has been deleted by joaquimandrade.
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-10-2009 , 00:53   Re: Setting a client's maxspeed permanently and efficiently
Reply With Quote #5

For entity id, you do it right.

To set player maxspeed :
PHP Code:
    set_user_maxspeed(idflMaxSpeed
Then to prevent it to change, you have to hook Ham_CS_Item_GetMaxSpeed for every items, then retrieve the owner (either with weapon m_pPlayer offset either with pev_owner) and to supercede it returning a stored by plugin value)
Other solution is to post hook Item_Deploy and to send here set_user_maxspeed.
Last solution is to filter CurWeapon to determinate when a player switch weapon.
Basically something like this should be enough :
PHP Code:
public Event_CurWeapon_Activeid )
{
    new 
iCurWeapon read_data(2)
    if( 
iCurWeapon != g_iCurWeapon[id] )
    {
        
g_iCurWeapon[id] = iCurWeapon
        
new Float:flCustomMaxSpeed g_flCustomMaxSpeed[id]
        if( 
flCustomMaxSpeed != 0.0 )
        {
            
set_user_maxspeed(idflCustomMaxSpeed)
        }
    }

Also, to reset player speed you can use this :
PHP Code:
cs_reset_user_maxspeed(id)
{
    new 
Float:flMaxSpeed;
    switch ( 
get_user_weapon(id) )
    {
        case 
CSW_SG550CSW_AWPCSW_G3SG1 flMaxSpeed 210.0;
        case 
CSW_M249 flMaxSpeed 220.0;
        case 
CSW_AK47 flMaxSpeed 221.0;
        case 
CSW_M3CSW_M4A1 flMaxSpeed 230.0;
        case 
CSW_SG552 flMaxSpeed 235.0;
        case 
CSW_XM1014CSW_AUGCSW_GALILCSW_FAMAS flMaxSpeed 240.0;
        case 
CSW_P90 flMaxSpeed 245.0;
        case 
CSW_SCOUT flMaxSpeed 260.0;
        default : 
flMaxSpeed 250.0;
    }
    
set_user_maxspeed(idflMaxSpeed);

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-10-2009 at 01:07.
ConnorMcLeod is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 06-10-2009 , 01:01   Re: Setting a client's maxspeed permanently and efficiently
Reply With Quote #6

I tried to hook Item_Deploy post and it happens before the maxspeed setting so that doesn't work.

I'm giving now a try to the rest of what you said. I guess you have solved this.
__________________
joaquimandrade is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 06-10-2009 , 01:44   Re: Setting a client's maxspeed permanently and efficiently
Reply With Quote #7

Ok. Both of Connor's suggestions work. I'm sticking with:

PHP Code:
#include <amxmodx>
#include <fakemeta>

#define PLUGIN    "New Plugin"
#define AUTHOR    "Unknown"
#define VERSION    "1.0"

new PreviousCurWeaponID[33]
new 
blocked[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("block","block")
    
register_clcmd("unblock","unblock")
    
    
register_event("CurWeapon","eventCurWeapon""be","1=1")
}

public 
eventCurWeapon(id)
{
    if(
blocked[id])
    {
        new 
curWeapon read_data(2)
        
        if(
curWeapon != PreviousCurWeaponID[id])
        {
            
PreviousCurWeaponID[id] = curWeapon
            engfunc
(EngFunc_SetClientMaxspeed,id,1.0)
        }
    }
}  

public 
block(id)
{
    
blocked[id] = true
    
    engfunc
(EngFunc_SetClientMaxspeed,id,1.0)
    
    return 
PLUGIN_HANDLED
}

public 
unblock(id)
{
    
blocked[id] = false;
    
    
cs_reset_user_maxspeed(id);
        
    return 
PLUGIN_HANDLED;
}


cs_reset_user_maxspeed(id)
{
    new 
Float:flMaxSpeed;
    switch ( 
get_user_weapon(id) )
    {
        case 
CSW_SG550CSW_AWPCSW_G3SG1 flMaxSpeed 210.0;
        case 
CSW_M249 flMaxSpeed 220.0;
        case 
CSW_AK47 flMaxSpeed 221.0;
        case 
CSW_M3CSW_M4A1 flMaxSpeed 230.0;
        case 
CSW_SG552 flMaxSpeed 235.0;
        case 
CSW_XM1014CSW_AUGCSW_GALILCSW_FAMAS flMaxSpeed 240.0;
        case 
CSW_P90 flMaxSpeed 245.0;
        case 
CSW_SCOUT flMaxSpeed 260.0;
        default : 
flMaxSpeed 250.0;
    }
    
    
engfunc(EngFunc_SetClientMaxspeed,id,flMaxSpeed);

Thanks Connor. +karma
__________________
joaquimandrade is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-10-2009 , 02:26   Re: Setting a client's maxspeed permanently and efficiently
Reply With Quote #8

Quote:
Originally Posted by joaquimandrade View Post
Thanks Connor. +karma
Thanks my brazilian friend
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 06-11-2009 , 13:44   Re: Setting a client's maxspeed permanently and efficiently
Reply With Quote #9

I found a way that should be the most efficient of doing this job (Set a usermaxspeed permanently)

Its about adding a new "offset" to hamdata.ini related to the function

<ResetMaxSpeed__11CBasePlayer>

I found it by doing some experiment and by having some luck since i'm a newbie in those matters.

The way, without changing hamsandwich code:

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN    "New Plugin"
#define AUTHOR    "Unknown"
#define VERSION    "1.0"

new Ham:Ham_Player_ResetMaxSpeed Ham_Player_ShouldFadeOnDeath

new bool:IsBlocked[33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_Player_ResetMaxSpeed,"player","resetMaxSpeed")
    
    
register_clcmd("block","block")
    
register_clcmd("unblock","unblock")
}

public 
resetMaxSpeed(id)
{
    return 
IsBlocked[id] ? HAM_SUPERCEDE HAM_IGNORED;
}

public 
block(id)
{
    
IsBlocked[id] = true;
    
engfunc(EngFunc_SetClientMaxspeed,id,1.0);
    return 
PLUGIN_HANDLED
}

public 
unblock(id)
{
    
IsBlocked[id] = false;
    
ExecuteHam(Ham_Player_ResetMaxSpeed,id);
    return 
PLUGIN_HANDLED

And then in hamdata.ini modify player_shouldfadeondeath or any player_* entry that you don't care about

player_shouldfadeondeath 69 in windows
player_shouldfadeondeath 71 in linux, i guess but i haven't tried it.
__________________
joaquimandrade is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-11-2009 , 16:32   Re: Setting a client's maxspeed permanently and efficiently
Reply With Quote #10

Good job to find that.
__________________
Arkshine 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 21:14.


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