Raised This Month: $213 Target: $400
 53% 

TF2 Speedmod


Post New Thread Reply   
 
Thread Tools Display Modes
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
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-26-2009 , 09:17   Re: TF2 Speedmod
Reply With Quote #2

Is that the code you're actually running? It doesn't use GetEntProp.

But anyway, you're getting a userid from events and using it like a client ID.
Fyren is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 06-26-2009 , 09:41   Re: TF2 Speedmod
Reply With Quote #3

Going by what Fyren said, you need to do something like this:

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

Also, I may be blind, but I never see where you set the speed? (BTW use [php] tags instead of [code] tags)
Dragonshadow is offline
Jonz00r
New Member
Join Date: Apr 2009
Old 06-26-2009 , 15:24   Re: TF2 Speedmod
Reply With Quote #4

Quote:
Originally Posted by Fyren View Post
Is that the code you're actually running? It doesn't use GetEntProp.

But anyway, you're getting a userid from events and using it like a client ID.
It worked before i rewrote the code. Before I only have the hook for player spawn. but it worked. I've had to rewrite it to account for the heavy gun ready mode and sniper zoom along with other events and now i can't get it working.
I assume that GetEntProp is called by some other function but i keep getting the error.

L 06/26/2009 - 15:293: [SM] Native "GetEntProp" reported: Entity 2 is invalid
L 06/26/2009 - 15:293: [SM] Displaying call stack trace for plugin "speed.smx":
L 06/26/2009 - 15:293: [SM] [0] Line 94, /home/jon/srcds_l/orangebox/tf/addons/sourcemod/scripting/include/tf2_stocks.inc::TF2_GetPlayerClass()
L 06/26/2009 - 15:293: [SM] [1] Line 163, speed.sp::TF2_GetPlayerSpeed()
L 06/26/2009 - 15:293: [SM] [2] Line 118, speed.sp::CheckClientSpeed()
L 06/26/2009 - 15:293: [SM] [3] Line 113, speed.sp::Timer_CheckSpeed()

Last edited by Jonz00r; 06-26-2009 at 15:39.
Jonz00r is offline
Jonz00r
New Member
Join Date: Apr 2009
Old 06-30-2009 , 00:26   Re: TF2 Speedmod
Reply With Quote #5

bump
Jonz00r is offline
slipvyne
Junior Member
Join Date: Jun 2009
Old 06-30-2009 , 02:08   Re: TF2 Speedmod
Reply With Quote #6

Quote:
But anyway, you're getting a userid from events and using it like a client ID.
Quote:
L 06/26/2009 - 15:293: [SM] Native "GetEntProp" reported: Entity 2 is invalid
I think these 2 are connected. A user id, i dont beleive, is a Prop or an entity. Just quickly looking over the post and noticed this.
slipvyne is offline
Send a message via AIM to slipvyne Send a message via MSN to slipvyne
Dragonshadow
BANNED
Join Date: Jun 2008
Old 06-30-2009 , 10:26   Re: TF2 Speedmod
Reply With Quote #7

Well when I compiled it, I changed the functions to what I stated, but was getting this:

Code:
L 06/30/2009 - 10:14:29: [SM] Plugin encountered error 4: Invalid parameter or parameter type
L 06/30/2009 - 10:14:29: [SM] Native "ReplyToCommand" reported: Language phrase "More than one client matched" not found
L 06/30/2009 - 10:14:29: [SM] Displaying call stack trace for plugin "TF2 Speedmod.smx":
L 06/30/2009 - 10:14:29: [SM]   [0]  Line 131, C:\tf2dedi\orangebox\tf\addons\sourcemod\scripting\include\commandfilters.inc::ReplyToTargetError()
L 06/30/2009 - 10:14:29: [SM]   [1]  Line 199, C:\tf2dedi\orangebox\tf\addons\sourcemod\scripting\include\helpers.inc::FindTarget()
L 06/30/2009 - 10:14:29: [SM]   [2]  Line 53, TF2 Speedmod.sp::Command_Faster()
Then I noticed you had forgotten to add

PHP Code:
 LoadTranslations("common.phrases"); 
to your OnPluginStart

After adding that, it no longer errors, but instead of increasing speed, it just gives the [SM] targeting message telling me that more than one client matches the params I gave it (none) doing sm_fast myname does the same thing.
Dragonshadow is offline
Reply


Thread Tools
Display Modes

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 19:43.


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