AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Maxspeed problems (https://forums.alliedmods.net/showthread.php?t=227363)

KuvZz 09-30-2013 11:27

Maxspeed problems
 
Hello. When I use set_user_maxspeed I get two problems:
1) When I change weapon it resets.
2) Maxspeed is always the same. I tested it some times, for example: Default maxspeed is 250, if I set lower maxspeed (200) it'll OK but if I set more than 250 (251, 300, 850...), maxspeed will be the same.
I found this https://forums.alliedmods.net/showpo...33&postcount=5 but I don't undestand well.
PD: I always do this
PHP Code:

register_cvar("speed_1""300.0"

and then...
PHP Code:

set_user_maxspeed(idfloat(get_cvar_num("speed_1"))) 

Someone can help me? Ty.

~Ice*shOt 09-30-2013 11:35

Re: Maxspeed problems
 
So, use curweapon event then.

Edit:
Here's example

PHP Code:

new Cvar_Speed

public plugin_init()
{
    
Cvar_Speed register_cvar("Speed""300")

    
register_event("CurWeapon""Event_CurWeapon" "be""1=1")
}

public 
Event_CurWeapon(id)
{
    if (!
is_user_alive(id))
        return

    static 
FloatMaxSpeed
    MaxSpeed 
get_pcvar_float(Cvar_Speed)

    
set_user_maxspeed(idMaxSpeed)



simanovich 09-30-2013 12:27

Re: Maxspeed problems
 
Quote:

Originally Posted by ~Ice*shOt (Post 2043228)
So, use curweapon event then.

Edit:
Here's example

PHP Code:

new Cvar_Speed

public plugin_init()
{
    
Cvar_Speed register_cvar("Speed""300")

    
register_event("CurWeapon""Event_CurWeapon" "be""1=1")
}

public 
Event_CurWeapon(id)
{
    if (!
is_user_alive(id))
        return

    static 
FloatMaxSpeed
    MaxSpeed 
get_pcvar_float(Cvar_Speed)

    
set_user_maxspeed(idMaxSpeed)



DON'T USE CURWEAPON EVENT.

Use Ham_Item_PreFrame

~Ice*shOt 09-30-2013 12:34

Re: Maxspeed problems
 
Quote:

Originally Posted by simanovich (Post 2043257)
DON'T USE CURWEAPON EVENT.

Use Ham_Item_PreFrame

Say the reason why he can't use curweapon event?

simanovich 09-30-2013 12:37

Re: Maxspeed problems
 
Quote:

Originally Posted by ~Ice*shOt (Post 2043266)
Say the reason why he can't use curweapon event?

Because it called so many times.

ConnorMcLeod 09-30-2013 12:45

Re: Maxspeed problems
 
CBasePlayer::ResetMaxSpeed is the internal cstrike function called when the game is changing player maxspeed, so it is the best place for a plugin to manage maxspeed changes.

Also, you should use cvar pointers instead of cvars names, it is faster.


You need hamsandwhich updating version for following code to compile and to run.
PHP Code:

#include < amxmodx >
#include < hamsandwich >
#include < fun >

new g_pcvarSpeed_1

public plugin_init()
{
    
RegisterHam(Ham_CS_Player_ResetMaxSpeed"player""OnCBasePlayer_ResetMaxSpeed_P"true);

    
g_pcvarSpeed_1 register_cvar("speed_1""300.0");
}

public 
OnCBasePlayer_ResetMaxSpeed_Pid )
{
    if( 
is_user_alive(id) && get_user_maxspeed(id) != 1.0 )
    {
        
set_user_maxspeed(idget_pcvar_float(g_pcvarSpeed_1));
    }



KuvZz 09-30-2013 12:48

Re: Maxspeed problems
 
I'll try that, thanks.

Edit:
I think, I'm doing something wrong but I got problems.
I copy&paste and works fine, but I tried to add this to my menu. I did this:
PHP Code:

new g_pcvarSpeed_1

public plugin_init()
{
    
RegisterHam(Ham_CS_Player_ResetMaxSpeed"player""OnCBasePlayer_ResetMaxSpeed_P"true);

    
g_pcvarSpeed_1 register_cvar("speed_1""850.0");
}

public 
OnCBasePlayer_ResetMaxSpeed_Pid )
{
    if( 
is_user_alive(id) && get_user_maxspeed(id) != 1.0 )
    {
//What should I put here? :S
    
}


In case:
PHP Code:

        case 1:
    {
        
ChatColor(id"!gYou are an Assassin.")
        
strip_user_weapons(id)
        
give_item(id"weapon_tmp")
        
give_item(id"weapon_knife")
        
set_user_maxspeed(idget_pcvar_float(g_pcvarSpeed_1));


When I select the option it works, but if I change weapon or die it'll reset.

tonykaram1993 10-02-2013 06:13

Re: Maxspeed problems
 
Set a bool to true in case 1 for each player, and check in OnCBasePlayer_ResetMaxSpeed_P if the player has that bool set to true, if so then return HAM_SUPERCEDE else return HAM_IGNORED. The bool must be an array of 33 (to hold all players).

If you want to optimize your code a bit more, use bitsums. To know how to use bitsums, search the forums for the tutorial.

KuvZz 10-02-2013 11:59

Re: Maxspeed problems
 
I did that, the plugin compile but give me 2 warnings:
Code:

// C:\Program Files (x86)\Counter-Strike 1.6\cstrike\addons\amxmodx\scripting\Classes.sma(73) : warning 211: possibly unintended assignment
// C:\Program Files (x86)\Counter-Strike 1.6\cstrike\addons\amxmodx\scripting\Classes.sma(75) : warning 209: function "OnCBasePlayer_ResetMaxSpeed_P" should return a value

PHP Code:

new bool:AssassinSpeed[33]
public 
plugin_init()
{
    
register_plugin(PLUGIN,VERSION,AUTHOR )
    
register_clcmd("say /class""Classes")
    
RegisterHam(Ham_CS_Player_ResetMaxSpeed"player""OnCBasePlayer_ResetMaxSpeed_P"true)
//(More...)
}

public 
OnCBasePlayer_ResetMaxSpeed_P(id//Speed
{
    if (
AssassinSpeed[id] = true//LINE 73
    
return HAM_SUPERCEDE
//LINE 75 

In case:
PHP Code:

        case 1:
    {
        
AssassinSpeed[id] = true
//(More...)
         


Where I should add the speed modification? (For example 850) I added a cvar but I'm not sure.

~Ice*shOt 10-02-2013 12:04

Re: Maxspeed problems
 
PHP Code:

    if (AssassinSpeed[id] = true//LINE 73
    
return HAM_SUPERCEDE 

:arrow:
PHP Code:

    if (AssassinSpeed[id]) //LINE 73
    
return HAM_SUPERCEDE 



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

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