AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Setting a client's maxspeed permanently and efficiently (https://forums.alliedmods.net/showthread.php?t=94331)

joaquimandrade 06-10-2009 00:30

Setting a client's maxspeed permanently and efficiently
 
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

ConnorMcLeod 06-10-2009 00:35

Re: Setting a client's maxspeed permanently efficiently
 
Quote:

Originally Posted by joaquimandrade (Post 845294)

PHP Code:

ExecuteHam(Ham_CS_Item_GetMaxSpeed,id,maxspeed


You passed player id.

joaquimandrade 06-10-2009 00:36

Re: Setting a client's maxspeed permanently efficiently
 
Quote:

Originally Posted by ConnorMcLeod (Post 845295)
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)

ConnorMcLeod 06-10-2009 00:39

Re: Setting a client's maxspeed permanently efficiently
 
Quote:

Originally Posted by joaquimandrade (Post 845296)
Yes but, that was after (for testing). I tried with the weapon id.

Weapon Entity Id ? (works for me).

ConnorMcLeod 06-10-2009 00:53

Re: Setting a client's maxspeed permanently and efficiently
 
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);



joaquimandrade 06-10-2009 01:01

Re: Setting a client's maxspeed permanently and efficiently
 
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 06-10-2009 01:44

Re: Setting a client's maxspeed permanently and efficiently
 
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

ConnorMcLeod 06-10-2009 02:26

Re: Setting a client's maxspeed permanently and efficiently
 
Quote:

Originally Posted by joaquimandrade (Post 845323)
Thanks Connor. +karma

Thanks my brazilian friend :mrgreen:

joaquimandrade 06-11-2009 13:44

Re: Setting a client's maxspeed permanently and efficiently
 
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.

Arkshine 06-11-2009 16:32

Re: Setting a client's maxspeed permanently and efficiently
 
Good job to find that.


All times are GMT -4. The time now is 13:49.

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