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

(Solved) GetClientAbsAngles problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
=MaTi=
Member
Join Date: Jan 2008
Old 09-04-2009 , 11:06   (Solved) GetClientAbsAngles problem
Reply With Quote #1

I'm trying to write a plugin that spawns entities in front of player. Everything works fine, except... Native GetClientAbsAngles updates the angle way too slowly. There is about 5 seconds (or even more) delay before it updates the angle. Because of this, players would end up spawning items in walls or other props. Is there a way to make it always retrieve the actual angle?

Here is the source code:

Code:
public Action:Command_TestSpawn(client, params)
{
    new Float:location[3];
    GetClientAbsOrigin(client, location);
    new Float:ang[3];
    GetClientAbsAngles(client, ang);
    new Float:location2[3];
    location2[0] = (location[0]+(150*(Cosine(DegToRad(ang[1]))))); //item spawns a little further, for testing purposes
    location2[1] = (location[1]+(150*(Sine(DegToRad(ang[1])))));
    location2[2] = location[2];
    PrintToChat(client,"Location1: %f, %f, %f", location[0], location[1], location[2]);
    PrintToChat(client,"Location2: %f, %f, %f", location2[0], location2[1], location2[2]);
    PrintToChat(client,"Angles: %f, %f, %f", ang[0], ang[1], ang[2]); 
    new EntitySpawnIndex = CreateEntityByName("weapon_zm_rifle");
    DispatchSpawn(EntitySpawnIndex);
    TeleportEntity(EntitySpawnIndex, location2, NULL_VECTOR, NULL_VECTOR);
}

Last edited by =MaTi=; 09-04-2009 at 13:39.
=MaTi= is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-04-2009 , 12:22   Re: GetClientAbsAngles problem
Reply With Quote #2

Quote:
Originally Posted by =MaTi= View Post
Is there a way to make it always retrieve the actual angle?
Of what exactly? The client, or the entity being spawned?
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
=MaTi=
Member
Join Date: Jan 2008
Old 09-04-2009 , 12:52   Re: GetClientAbsAngles problem
Reply With Quote #3

The client, entity angle doesn't really matter.
=MaTi= is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-04-2009 , 12:55   Re: GetClientAbsAngles problem
Reply With Quote #4

In my barrel launcher plugin, I used GetClientEyeAngles(client,ang);

Assuming you don't want up or down co-ords, just set ang[2] = 0.0;

That should hopefully solve your problem.

Edit: Also, my mathmatics is a bit rusty, but...
Code:
location2[0] = (location[0]+(150*(Cosine(DegToRad(ang[1]))))); //item spawns a little further, for testing purposes
    location2[1] = (location[1]+(150*(Sine(DegToRad(ang[1])))));
Did you intend for both of them to be ang[1]?

I actually know nothing of Cosine, Sine, Rad etc.

Last edited by Flynn; 09-04-2009 at 12:58. Reason: Bad Post Writing FTL
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
=MaTi=
Member
Join Date: Jan 2008
Old 09-04-2009 , 13:25   Re: GetClientAbsAngles problem
Reply With Quote #5

Quote:
Originally Posted by Flynn View Post
In my barrel launcher plugin, I used GetClientEyeAngles(client,ang);

Assuming you don't want up or down co-ords, just set ang[2] = 0.0;

That should hopefully solve your problem.
Yup, it works perfectly now


Quote:
Originally Posted by Flynn View Post
Did you intend for both of them to be ang[1]?

I actually know nothing of Cosine, Sine, Rad etc.
Yes, since I calculate the entitys position basing on client's horizontal angle. For instance, if client's looking in the sky, the item will spawn in front of him, not over him

Anyway, thanks for help!

Last edited by =MaTi=; 09-04-2009 at 13:41.
=MaTi= is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 10-28-2009 , 19:49   Re: GetClientAbsAngles problem
Reply With Quote #6

Quote:
Originally Posted by =MaTi= View Post
Yes, since I calculate the entitys position basing on client's horizontal angle. For instance, if client's looking in the sky, the item will spawn in front of him, not over him
do you know how i can do this? spawn the item right in front of their view? even if they are looking to the sky. i am terrible at math. i just want to get the location of about 32 units in front of their view, regardless where they are looking.
meng is offline
Send a message via Yahoo to meng
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 12-13-2009 , 18:30   Re: (Solved) GetClientAbsAngles problem
Reply With Quote #7

would still love to be able to do this. but im beginning to think its not possible. i have no idea how to include the z axis in these calculations. could somebody give it a try?
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 12-13-2009 , 18:40   Re: (Solved) GetClientAbsAngles problem
Reply With Quote #8

PHP Code:
    decl Float:location[3], Float:ang[3], Float:location2[3];
    
GetClientAbsOrigin(clientlocation);
    
GetClientEyeAngles(clientang);
    
    
location2[0] = (location[0]+(50*(Cosine(DegToRad(ang[1])))));
    
location2[1] = (location[1]+(50*(Sine(DegToRad(ang[1])))));
    
location2[2] = (location[2]+(50*(Sine(DegToRad(ang[2]))))); 
Like this - maybe you need a Cosine for the z coordinate though
AtomicStryker is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 12-23-2009 , 15:17   Re: (Solved) GetClientAbsAngles problem
Reply With Quote #9

thx, but that didnt seem to have the effect. it still spawns 50 units in front of their position in the map. this is why its so confusing. that z coordinate needs to be included in the early calculations somehow. for example, i try and spawn a grenade and hurl it towards where the player is looking. if they are looking up or down, it spawns 50 units away from their position and looks bad both first person and world view. if they are looking relatively parallel to the ground, it looks just fine. thx again though, this would be really key to getting a custom projectile to look a little more acceptable.
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
=MaTi=
Member
Join Date: Jan 2008
Old 12-27-2009 , 20:37   Re: (Solved) GetClientAbsAngles problem
Reply With Quote #10

Sorry, I didn't notice that somebody has replied to this old topic. If you want to spawn the object right in front of player, you need to take client's vertical angle (ang[0]) into account as well. Here is the code:

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

public Plugin:myinfo 
{
    
name "Spawn entity",
    
author "MaTi",
    
description "Spawn entity",
    
version "1.0",
    
url "none"
}

public 
OnPluginStart()
{
    
PrecacheModel("models/props_c17/oildrum001_explosive.mdl");
    
RegConsoleCmd("sm_spawntest"Command_TestSpawn);
}

public 
Action:Command_TestSpawn(clientparams)
{
    new 
Float:location[3];
    
GetClientEyePosition(clientlocation);
    new 
Float:ang[3];
    
GetClientEyeAngles(clientang);
    new 
Float:location2[3];
    
location2[0] = (location[0]+(100*((Cosine(DegToRad(ang[1]))) * (Cosine(DegToRad(ang[0]))))));
    
location2[1] = (location[1]+(100*((Sine(DegToRad(ang[1]))) * (Cosine(DegToRad(ang[0]))))));
    
ang[0] -= (2*ang[0]);
    
location2[2] = (location[2]+(100*(Sine(DegToRad(ang[0])))));
    
PrintToChat(client,"Location1: %f, %f, %f"location[0], location[1], location[2]);
    
PrintToChat(client,"Location2: %f, %f, %f"location2[0], location2[1], location2[2]);
    
PrintToChat(client,"Angles: %f, %f, %f"ang[0], ang[1], ang[2]); 
    new 
EntitySpawnIndex CreateEntityByName("prop_physics");
    
SetEntityModel(EntitySpawnIndex,"models/props_c17/oildrum001_explosive.mdl");
    
DispatchSpawn(EntitySpawnIndex);
    
SetEntityMoveType(EntitySpawnIndexMOVETYPE_VPHYSICS);
    
SetEntProp(EntitySpawnIndexProp_Data"m_CollisionGroup"5);
    
SetEntProp(EntitySpawnIndexProp_Data"m_nSolidType"6);
    
TeleportEntity(EntitySpawnIndexlocation2NULL_VECTORNULL_VECTOR);

Just change the code to spawn the entity you want and it should work

Last edited by =MaTi=; 01-30-2010 at 20:49.
=MaTi= 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 22:27.


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