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

[TF2] Help Please! Teleport to Look-location


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spazman0
Member
Join Date: Jul 2008
Old 07-11-2008 , 23:43   [TF2] Help Please! Teleport to Look-location
Reply With Quote #1

I have just started SourcePawn, and I am hoping to write sourcemod plugins for my friend. However, as I do not have access to the server, I have no way to test my plugins before he loads them onto his server. I just thought I would warn you of that first.

I am trying to write a plugin that teleports a client to the place where the admin is looking. From the slap example found on the wiki and another teleport example that teleports to a saved spot, I've botched together what I hope should find a player and teleport them. However, I am not sure about how to go about where to teleport them to. Here is my botched together code:

Code:
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
    RegAdminCmd("sm_tele", Command_tele, ADMFLAG_SLAY)
}


public Action:Command_tele(client, args)
{
    new String:arg1[32], String:arg2[32]
    GetCmdArg(1, arg1, sizeof(arg1))
    
    new target = FindTarget(client, arg1)
    if(target == -1)
    {
        return Plugin_Handled;
    }
    
    TeleportEntity(target, NULL_VECTOR, /*Angle of admin''s view*/, /*distance from admin?*/)
    
    new String:name[MAX_NAME_LENGTH]
    
    GetClientName(target, name, sizeof(name))
    
    ShowActivity2(client, "%s was Teleported!", name)
    LogAction(client, target, "\"%L\" teleported \"%L\" ", client, target)
    
    ReplyToCommand(client, "You Teleported %s.", name)
    
    return Plugin_Handled;
    
}
I am assuming that I will need some new variables to store the direction and distance of the admin's view, and I'm also assuming that these will need to be put into the TeleportEntity command.

I would like some help in figuring out what else I need to do to make this work. Also, if any of the code I have written could be improved, I'm all ears.
Spazman0 is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 07-12-2008 , 01:49   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #2

PHP Code:
new Float:vAngles[3], Float:vOrigin[3], Float:pos[3];
    
GetClientEyePosition(client,vOrigin);
GetClientEyeAngles(clientvAngles);
    
new 
Handle:trace TR_TraceRayFilterEx(vOriginvAnglesMASK_SHOTRayType_InfiniteTraceEntityFilterPlayer);
    
if(
TR_DidHit(trace)){
    
TR_GetEndPosition(postrace);
    
    
pos[2] += 10.0// make sure he does not get stuck to the floor, increse Z pos
    
    
TeleportEntitytargetposNULL_VECTORNULL_VECTOR ); //Teleport target player on hitpos

}
CloseHandle(trace);
    
    
    
    
//Put this somewhere else on the code
public bool:TraceEntityFilterPlayer(entitycontentsMask){
     return 
entity maxplayers || entity == 0;

I guess you are looking for that...
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 07-12-2008 at 02:31.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-12-2008 , 02:27   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #3

Code:
public bool:TraceEntityFilterPlayer(entity, contentsMask){
     return entity > maxplayers;
} 


What if they are aiming at the world? (entity 0) that will return 0 and end the traceray

Shouldn't it be:

Code:
public bool:TraceEntityFilterPlayer(entity, contentsMask){
     return entity > maxplayers || !entity;
} 
__________________

Last edited by Greyscale; 07-12-2008 at 02:30.
Greyscale is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 07-12-2008 , 02:30   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #4

Good point. but it seems it always has been working correctly with spray trace.

I am guessing it does not filter world...

Let me add a exception just in case...
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Spazman0
Member
Join Date: Jul 2008
Old 07-12-2008 , 03:07   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #5

Thanks Nican. I have put the code in like this, and it seems to compile all-right. However, as I can not test it, I have no idea whether or not it will work. I know from experience that just because something compiles does not mean its gonna work. So, can you tell me if you think this should work?


PHP Code:
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
    
RegAdminCmd("sm_tele"Command_teleADMFLAG_SLAY)
    
}

public 
bool:TraceEntityFilterPlayer(entitycontentsMask)
    {
        return 
entity GetMaxClients() || !entity;
    } 

public 
Action:Command_tele(clientargs)
{
    new 
Float:vAngles[3], Float:vOrigin[3], Float:pos[3];
    
    
GetClientEyePosition(client,vOrigin);
    
GetClientEyeAngles(clientvAngles);
    
    new 
String:arg1[32]
    
GetCmdArg(1arg1sizeof(arg1))
    
    new 
target FindTarget(clientarg1)
    if(
target == -1)
    {
        return 
Plugin_Handled;
    }
    
    
    new 
Handle:trace TR_TraceRayFilterEx(vOriginvAnglesMASK_SHOTRayType_InfiniteTraceEntityFilterPlayer);
    
    if(
TR_DidHit(trace))
    {
        
TR_GetEndPosition(postrace);
    
        
pos[2] += 10.0
    
        
TeleportEntitytargetposNULL_VECTORNULL_VECTOR ); 

    }
    
CloseHandle(trace);
    
    
     
    new 
String:name[MAX_NAME_LENGTH]
    
    
GetClientName(targetnamesizeof(name))
    
    
ShowActivity2(client"%s was Teleported!"name)
    
LogAction(clienttarget"\"%L\" teleported \"%L\" "clienttarget)
    
    
ReplyToCommand(client"You Teleported %s."name)
    
    return 
Plugin_Handled;
    

Spazman0 is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 07-12-2008 , 12:59   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #6

Quote:
Originally Posted by Greyscale View Post
Shouldn't it be:

Code:
public bool:TraceEntityFilterPlayer(entity, contentsMask){
     return entity > maxplayers || !entity;
} 
Hm, both works, but I don't know with is better.

"!var" is suppose to be used on boolean values, since 0 is false, it would return true...

--------

Spazman0
This seems wrong:
PHP Code:
LogAction(clienttarget"\"%L\" teleported \"%L\" "clienttarget
client and target are not "%L" values, I think you meant to use "%N"
Read http://wiki.alliedmods.net/Format_Cl...Mod_Scripting) for more information
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Spazman0
Member
Join Date: Jul 2008
Old 07-12-2008 , 21:43   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #7

Ok, thanks Nican. I am currently in the process of downloading SCRDS to test my plugins.

EDIT:

I have tested the plugin and it is fully working. I am now going to submit it to unapproved plugins for anyone else who wants to use it.

Last edited by Spazman0; 07-13-2008 at 02:47.
Spazman0 is offline
DiscoBBQ
Veteran Member
Join Date: Jan 2005
Location: Clemson, South Carolina
Old 07-12-2008 , 22:04   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #8

http://forums.alliedmods.net/showthread.php?t=69851
__________________
"Every man is guilty of all the good he did not do"
DiscoBBQ is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-12-2008 , 22:16   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #9

Quote:
Originally Posted by Nican View Post
client and target are not "%L" values, I think you meant to use "%N"
Read http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting) for more information
Sure they are. That link you linked proves it. Each just prints different information.
bl4nk is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 07-12-2008 , 22:18   Re: [TF2] Help Please! Teleport to Look-location
Reply With Quote #10

Oh shi... I confused %L with %T

I am going crazy...
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
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 08:39.


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