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

[TF2] Detecting when a player is standing on a teleporter exit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
404UserNotFound
BANNED
Join Date: Dec 2011
Old 05-19-2014 , 04:50   [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #1

Have a little idea I want to try out, but detecting when a player is standing on a teleporter exit (specifically, the Engineer who built the exit).

Not sure how to make this happen. Any good ideas? I know we can check if a player is on the ground or up against a wall (I've got an "up against a wall" check used in the TF2 Grenades plugin that I'm working on with my buddy), but I draw a blank when trying to figure out how to check if the player is standing on a teleporter exit.
404UserNotFound is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 05-19-2014 , 05:38   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #2

SDKHooks' Touch hook?
__________________
ddhoward is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 05-19-2014 , 07:22   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #3

Did it with traceray ... tested aswell.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

/****************************************************************
            C O N S T A N T S
*****************************************************************/

#define PLUGIN_NAME     "Player On Teleporter?"
#define PLUGIN_AUTHOR   "floube"
#define PLUGIN_DESC     "-"
#define PLUGIN_VERSION  "1.00"
#define PLUGIN_URL      "http://www.styria-games.eu/"

/****************************************************************
            P L U G I N   I N F O
*****************************************************************/

public Plugin:myinfo 
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
description PLUGIN_DESC,
    
version PLUGIN_VERSION,
    
url PLUGIN_URL
};

/****************************************************************
            F O R W A R D   P U B L I C S
*****************************************************************/

public OnPluginStart() {
    
RegConsoleCmd("sm_ontele"Command_CheckOnTeleporter);
}

public 
Action:Command_CheckOnTeleporter(clientargs) {
    if (
ClientOnTeleporter(client0true)) {
        
PrintToChatAll("%N stands on a entrance teleporter and is the owner!"client);
    } else if (
ClientOnTeleporter(client1)) {
        
PrintToChatAll("%N stands on a exit teleporter!"client);
    } else {
        
PrintToChatAll("No teleporter for %N!"client);
    }

    return 
Plugin_Handled;
}

/**
 * Checks if a client is standing on a teleporter.
 *
 * @param client        The clients to check.
 * @param type            The teleporter type. (0 = entrance, 1 = exit)
 * @param ownerOnly        If the client must be the owner of the teleporter.
 * @return                True if the client stands on a teleporter, false otherwise.
 */

bool:ClientOnTeleporter(clienttypebool:ownerOnly=false) {
    if (
client || client MaxClients
        return 
false;

    if (!(
IsClientConnected(client) && IsClientInGame(client) && IsPlayerAlive(client)))
        return 
false;

    
// Client is on the ground
    
if (GetEntPropEnt(clientProp_Send"m_hGroundEntity") == 0)
         return 
false;
    
    new 
Float:location[3];
    
GetClientAbsOrigin(clientlocation);
    
    
location[2] += 10.0;

    
TR_TraceRayFilter(locationFloat:{90.00.00.0}, MASK_PLAYERSOLIDRayType_InfiniteTraceRayNoPlayersclient);
    
    if (
TR_DidHit()) {
        new 
entity TR_GetEntityIndex();

        if (
entity != -1) {
            new 
String:classname[128];

            
GetEntityClassname(entityclassnamesizeof(classname));

            if (
StrEqual(classname"obj_teleporter")) {
                new 
mode GetEntProp(entityProp_Send"m_iObjectMode");
                
                if (
mode == type) {
                    if (
ownerOnly) {
                        new 
owner GetEntPropEnt(entityProp_Send"m_hBuilder");

                        if (
client == owner) {
                            return 
true;
                        }
                    } else {
                        return 
true;
                    }
                }
            }
        }
    }

    return 
false;
}

public 
bool:TraceRayNoPlayers(entitymaskany:data) {
    if (
entity == data || (entity >= && entity <= MaxClients)) {
        return 
false;
    }

    return 
true;

__________________
floube is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 05-19-2014 , 07:27   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #4

Traceray may be too CPU expensive.

Touch events would be preferable, or a simple box hull compare.
h3bus is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 05-19-2014 , 07:31   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #5

Just get the m_hGroundEntity and check if it's a teleporter
__________________
Pelipoika is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 05-19-2014 , 11:24   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #6

There is a netprop to tell you if it is an entrance/exit, or you can use getbuildingtype
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 05-19-2014 , 11:45   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #7

Quote:
Originally Posted by h3bus View Post
Traceray may be too CPU expensive.

Touch events would be preferable, or a simple box hull compare.
You wouldnt notice any of the 'expensive' CPU usage, as i use traces a crap ton, and don't notice (almost 5 traces a player once with 26 players in a server.)
Mitchell is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 05-19-2014 , 18:01   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #8

Quote:
Originally Posted by floube View Post
Did it with traceray ... tested aswell.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

/****************************************************************
            C O N S T A N T S
*****************************************************************/

#define PLUGIN_NAME     "Player On Teleporter?"
#define PLUGIN_AUTHOR   "floube"
#define PLUGIN_DESC     "-"
#define PLUGIN_VERSION  "1.00"
#define PLUGIN_URL      "http://www.styria-games.eu/"

/****************************************************************
            P L U G I N   I N F O
*****************************************************************/

public Plugin:myinfo 
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
description PLUGIN_DESC,
    
version PLUGIN_VERSION,
    
url PLUGIN_URL
};

/****************************************************************
            F O R W A R D   P U B L I C S
*****************************************************************/

public OnPluginStart() {
    
RegConsoleCmd("sm_ontele"Command_CheckOnTeleporter);
}

public 
Action:Command_CheckOnTeleporter(clientargs) {
    if (
ClientOnTeleporter(client0true)) {
        
PrintToChatAll("%N stands on a entrance teleporter and is the owner!"client);
    } else if (
ClientOnTeleporter(client1)) {
        
PrintToChatAll("%N stands on a exit teleporter!"client);
    } else {
        
PrintToChatAll("No teleporter for %N!"client);
    }

    return 
Plugin_Handled;
}

/**
 * Checks if a client is standing on a teleporter.
 *
 * @param client        The clients to check.
 * @param type            The teleporter type. (0 = entrance, 1 = exit)
 * @param ownerOnly        If the client must be the owner of the teleporter.
 * @return                True if the client stands on a teleporter, false otherwise.
 */

bool:ClientOnTeleporter(clienttypebool:ownerOnly=false) {
    if (
client || client MaxClients
        return 
false;

    if (!(
IsClientConnected(client) && IsClientInGame(client) && IsPlayerAlive(client)))
        return 
false;

    
// Client is on the ground
    
if (GetEntPropEnt(clientProp_Send"m_hGroundEntity") == 0)
         return 
false;
    
    new 
Float:location[3];
    
GetClientAbsOrigin(clientlocation);
    
    
location[2] += 10.0;

    
TR_TraceRayFilter(locationFloat:{90.00.00.0}, MASK_PLAYERSOLIDRayType_InfiniteTraceRayNoPlayersclient);
    
    if (
TR_DidHit()) {
        new 
entity TR_GetEntityIndex();

        if (
entity != -1) {
            new 
String:classname[128];

            
GetEntityClassname(entityclassnamesizeof(classname));

            if (
StrEqual(classname"obj_teleporter")) {
                new 
mode GetEntProp(entityProp_Send"m_iObjectMode");
                
                if (
mode == type) {
                    if (
ownerOnly) {
                        new 
owner GetEntPropEnt(entityProp_Send"m_hBuilder");

                        if (
client == owner) {
                            return 
true;
                        }
                    } else {
                        return 
true;
                    }
                }
            }
        }
    }

    return 
false;
}

public 
bool:TraceRayNoPlayers(entitymaskany:data) {
    if (
entity == data || (entity >= && entity <= MaxClients)) {
        return 
false;
    }

    return 
true;

Oh wow, this seems perfect....Also, I may as well come clean: The idea is an Engineer "Jump Pad" based off of a YouTube video I saw where a player builds a teleporter entrance/exit and a minisentry, then has a medic heal them while they get shot at by the sentry, then something happens and they get launched.

With this however, it'll be a command that you use while standing on a teleporter and it'll launch you in the direction you are facing.
404UserNotFound is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 05-20-2014 , 06:45   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #9

Quote:
Originally Posted by Mitchell View Post
You wouldnt notice any of the 'expensive' CPU usage, as i use traces a crap ton, and don't notice (almost 5 traces a player once with 26 players in a server.)
Do you have any idea how often the game uses traces anyways?
Like every time you fire a hitscan weapon, every pellet is tracerayd. It's fairly cheap.
I'v got plugins that fire this 10 times a second per client, it's fine.

Even with rapid fire using scatterguns and miniguns, the server is ok.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 05-20-2014 , 09:19   Re: [TF2] Detecting when a player is standing on a teleporter exit
Reply With Quote #10

Quote:
Originally Posted by friagram View Post
Do you have any idea how often the game uses traces anyways?
Like every time you fire a hitscan weapon, every pellet is tracerayd. It's fairly cheap.
I'v got plugins that fire this 10 times a second per client, it's fine.

Even with rapid fire using scatterguns and miniguns, the server is ok.
i forgot to mention that the traces i was performing was on a Prethink of each client.
Mitchell 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 17:23.


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