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

TF2 Speedmod


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Jonz00r
New Member
Join Date: Apr 2009
Old 06-26-2009 , 03:20   TF2 Speedmod
Reply With Quote #1

Well I've been working for a few hours now, and have reached a deadend.
I've been writing a plugin to modify a TF2 player's speed. It compiles runs but i get this in the server console.

[SM] Native "GetEntProp" reported: Entity 2 is invalid.

Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
#define TF2_PLAYER_SLOWED       (1 << 0)    // 1
#define TF2_PLAYER_ZOOMED       (1 << 1)    // 2

stock Handle:g_SpeedTimers[ MAXPLAYERS+1 ];
new Float:speedmod[ MAXPLAYERS ];
//new Float:defspd;

public Plugin:myinfo =
{
    name = "SpeedMod",
    author = "Jonz",
    description = "Modifies a player's speed",
    version = "0.0.0.3",
    url = ""
};
 
public OnPluginStart()
{
    RegAdminCmd("sm_fast", Command_Faster, ADMFLAG_SLAY);
    
    HookEvent("player_spawn", Event_player_spawn);
    HookEvent("player_death", Event_PlayerDeath);
    
    //defspd = FindSendPropInfo("CTFPlayer", "m_flMaxspeed");
}

public OnClientConnected(client)
{    //Reset player speed
    speedmod[ client ] = 1.0;
}

public OnClientDisconnect(client)
{
    KillSpeedTimer(client)
}

public Action:Command_Faster(client, args)
{
    new String:arg1[32], String:arg2[32];
    new Float:targetspeed = 0.0;
    
    GetCmdArg(1, arg1, sizeof(arg1))
    
    if (args >= 2 && GetCmdArg(2, arg2, sizeof(arg2)))
    {
        targetspeed = StringToFloat(arg2)
    }
    
    new target = FindTarget(client, arg1)
    
    if (target == -1)
    {
        return Plugin_Continue;
    }
    
    speedmod[ target ] = targetspeed;
    return Plugin_Continue;
}


public Action:Event_player_spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetEventInt(event, "userid");

    CreateSpeedTimer(client);
    
    return Plugin_Continue;
}

public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetEventInt(event, "userid");
    
    KillSpeedTimer(client);
    
    return Plugin_Continue;
}

/*public Action:Event_playerdc(Handle:event, const Sting:name[], bool:dontBroadcast)
{
    new client = GetEventInt(event, "userid");
    
    KillSpeedTimer(client);
    
    return Plugin_Continue;
}
*/
stock CreateSpeedTimer(client)
{
    if (g_SpeedTimers[client] == INVALID_HANDLE)
    {
        g_SpeedTimers[client] = CreateTimer(1.0,Timer_CheckSpeed,client,TIMER_REPEAT);
    }
}

stock KillSpeedTimer(client)
{
    new Handle:timer=g_SpeedTimers[client];
    if (timer != INVALID_HANDLE)
    {
        KillTimer(timer);
        g_SpeedTimers[client] = INVALID_HANDLE;    
    }
}

public Action:Timer_CheckSpeed(Handle:timer, any:client)
{
    CheckClientSpeed(client);
}

CheckClientSpeed(client)
{
    new Float:Speed = TF2_GetPlayerSpeed(client)*speedmod[client]
    if( TF2_GetPlayerSpeed(client) != Speed)
    {
        UpdateClientSpeed(client)
    }
    
}
UpdateClientSpeed( client )
{
    //Do not completly remove the speed, connected players have their rights
    if( speedmod[ client ] > 0.0 )
    {
        new Float:newspeed;
        if (TF2_GetPlayerSpeed(client) * speedmod[ client ] > 400)
        {
            newspeed = 400.0;
        }
        else
        {
            newspeed = TF2_GetPlayerSpeed(client) * speedmod[ client ];
        }
        SetEntDataFloat(client, FindSendPropInfo("CTFPlayer", "m_flMaxspeed"), newspeed);
    }
    return Plugin_Continue;
}

stock Float:TF2_GetClassSpeed(TFClassType:class)
{
    switch (class)
    {
        case TFClass_Scout:     return 400.0;
        case TFClass_Soldier:   return 240.0;
        case TFClass_DemoMan:   return 280.0;
        case TFClass_Medic:     return 320.0;
        case TFClass_Pyro:      return 300.0;
        case TFClass_Spy:       return 300.0;
        case TFClass_Engineer:  return 300.0;
        case TFClass_Sniper:    return 300.0;
        case TFClass_Heavy:     return 230.0;
    }
    return 0.0;
}

stock Float:TF2_GetPlayerSpeed(client)
{
    return TF2_GetClassSpeed(TF2_GetPlayerClass(client));
}
I'm lost at this point.
Jonz00r is offline
 



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 13:21.


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