PDA

View Full Version : AS versions of Q2 functions?



Nero
30-03-2016, 04:17 PM
Hi! I'm trying to make a plugin with code from Quake 2, but I can't figure out if there are AS versions of some of the functions(?).

AngleVectors(ent->client->v_angle, vecForward, NULL, NULL);


AngleVectors (angles, forward_vector, right_vector, up_vector)
Converts the angles into various vectors :

forward_vector : vector along angles
right_vector : vector 90 degrees to the right of forward_vector
up_vector : vector 90 up from forward_vector

void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
{
float angle;
static float sr, sp, sy, cr, cp, cy;
// static to help MS compiler fp bugs

angle = angles[YAW] * (M_PI*2 / 360);
sy = sin(angle);
cy = cos(angle);
angle = angles[PITCH] * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = angles[ROLL] * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);

if (forward)
{
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
if (right)
{
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
right[1] = (-1*sr*sp*sy+-1*cr*cy);
right[2] = -1*sr*cp;
}
if (up)
{
up[0] = (cr*sp*cy+-sr*-sy);
up[1] = (cr*sp*sy+-sr*cy);
up[2] = cr*cp;
}
}

and

VectorMA(vecSrc, 8192, vecForward, vecEnd);


VectorMA (vector1, scale, vector2, vector_out)
sets vector_out to : vector1 + scale * vector2

void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc)
{
vecc[0] = veca[0] + scale*vecb[0];
vecc[1] = veca[1] + scale*vecb[1];
vecc[2] = veca[2] + scale*vecb[2];
}



Thanks! :3

The two examples are used to see if the player is looking at the sky via a trace from the EyePosition.

Could AngleVectors(ent->client->v_angle, vecForward, NULL, NULL); be replaced with vecForward = Math.MakeVectors(pPlayer.pev.v_angle); ? :o

Nero
30-03-2016, 04:53 PM
Hehu, it seems that all I had to do was


Math.MakeVectors( pPlayer.pev.v_angle );
g_Utility.TraceLine( vecSrc, vecSrc + g_Engine.v_forward * 8192, dont_ignore_monsters, pPlayer.edict(), tr );


^^;

w00tguy123
30-03-2016, 04:54 PM
Use g_Engine.MakeVectors() for "AngleVectors". The resulting vectors are stored in g_Engine.v_forward, g_Engine.v_up, g_Engine.v_right.

I don't know of any function that works like "VectorMA".

Nero
30-03-2016, 06:38 PM
Yee thainks ^^
It doesn't seem to be doing anything for my plugin though. :[
I'm making an airstrike plugin that fires rockets from the sky (ceiling with sky texture), but they don't get fired down, they keep going off to the side instead. :[

Any help would be appreciated :3 <3


//Version 1.0
CScheduledFunction@ g_pASQ2ThinkFunc = null;
//int airstrike_called;
//Vector airstrike_entry;
//float airstrike_time;

void PluginInit()
{
g_Module.ScriptInfo.SetAuthor( "Nero" );
g_Module.ScriptInfo.SetContactInfo( "Nero @ Svencoop forums" );

//if( g_pASQ2ThinkFunc !is null )
//g_Scheduler.RemoveTimer( g_pASQ2ThinkFunc );

//@g_pASQ2ThinkFunc = g_Scheduler.SetInterval( "airstrikeQ2Think", 0.1f );

g_Module.ScriptInfo.SetMinimumAdminLevel( ADMIN_YES );
}

CClientCommand airstrikeq2( "airstrikeq2", "Toggles night vision on/off", @AirstrikeQ2CMD );

void MapInit()
{
/*
g_Game.PrecacheGeneric( "nero/airstrike/flyby1.wav" );
g_Game.PrecacheGeneric( "nero/airstrike/pilot1.wav" );
g_Game.PrecacheGeneric( "nero/airstrike/pilot2.wav" );
g_Game.PrecacheGeneric( "nero/airstrike/pilot3.wav" );
g_SoundSystem.PrecacheSound( "nero/airstrike/flyby1.wav" );
g_SoundSystem.PrecacheSound( "nero/airstrike/pilot1.wav" );
g_SoundSystem.PrecacheSound( "nero/airstrike/pilot2.wav" );
g_SoundSystem.PrecacheSound( "nero/airstrike/pilot3.wav" );
*/
g_Game.PrecacheModel( "models/rpgrocket.mdl" );
g_Game.PrecacheModel( "sprites/smoke.spr" );

g_SoundSystem.PrecacheSound( "weapons/rocket1.wav" );
}

void AirstrikeQ2CMD( const CCommand@ args )
{
CBasePlayer@ pPlayer = g_ConCommandSystem.GetCurrentPlayer();

Vector vecSrc, vecForward;
TraceResult tr;

// see if we're pointed at the sky
vecSrc = pPlayer.EyePosition();
//Math.MakeVectors( pPlayer.pev.v_angle );
//g_EngineFuncs.MakeVectors( pPlayer.pev.v_angle );

g_Utility.TraceLine( vecSrc, vecSrc + g_Engine.v_forward * 8192, dont_ignore_monsters, pPlayer.edict(), tr );

if ( g_EngineFuncs.PointContents( tr.vecEndPos ) != CONTENTS_SKY )
{
// We hit something but it wasn't sky, so let's see if there is sky above it!
vecSrc = tr.vecEndPos;
//Math.MakeVectors( pPlayer.pev.v_angle );
//g_EngineFuncs.MakeVectors( pPlayer.pev.v_angle );
g_Utility.TraceLine( vecSrc, vecSrc + g_Engine.v_up * 8192, dont_ignore_monsters, pPlayer.edict(), tr );

if ( g_EngineFuncs.PointContents( tr.vecEndPos ) != CONTENTS_SKY ) // No sky above it either!!
{
g_EngineFuncs.ClientPrintf( pPlayer, print_center, "Airstrikes have to come from the sky!!!\n" );
//g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_ITEM, "nero/airstrike/pilot1.wav", 0.4, ATTN_NORM, 0, PITCH_NORM, 0, true, tr.vecEndPos );
return;
}
}

// set up for the airstrike
//ent->client->airstrike_called = 1;
//ent->client->airstrike_time = level.time + 14;
g_EngineFuncs.ClientPrintf( pPlayer, print_center, "Airstrike on its way!\n" );
//g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_ITEM, "nero/airstrike/pilot3.wav", 0.8, ATTN_NORM, 0, PITCH_NORM, 0, true, tr.vecEndPos );
doAirstrikeQ2( pPlayer, tr.vecEndPos );
}

void doAirstrikeQ2( CBasePlayer@ pPlayer, Vector airstrike_entry )
{
Vector vecSrc, vecForward, vecTargetDir;
TraceResult tr, tr_2;

// find the target point
vecSrc = pPlayer.EyePosition();
//Math.MakeVectors( pPlayer.pev.v_angle );
//g_EngineFuncs.MakeVectors( pPlayer.pev.v_angle );
g_Utility.TraceLine( vecSrc, vecSrc + g_Engine.v_forward * 8192, dont_ignore_monsters, pPlayer.edict(), tr );

// find the direction from the entry point to the target
vecTargetDir = ( tr.vecEndPos.opSub( airstrike_entry ) ).Normalize(); //VectorNormalize(vecTargetDir);
vecSrc = airstrike_entry + vecTargetDir;

// check we have a clear line of fire
g_Utility.TraceLine( vecSrc, tr.vecEndPos, dont_ignore_monsters, pPlayer.edict(), tr_2 );

// check to make sure we're not materializing in a solid
// if ( g_EngineFuncs.PointContents( vecSrc ) == CONTENTS_SOLID || tr_2.flFraction < 1.0 )
// {
// g_EngineFuncs.ClientPrintf( pPlayer, print_center, "Airstrike intercepted en route.\n" );
// g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_ITEM, "nero/airstrike/pilot1.wav", 0.8, ATTN_NORM, 0, PITCH_NORM, 0, true, vecSrc );
// return;
// }

//g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_ITEM, "nero/airstrike/pilot2.wav", 0.9, ATTN_NORM, 0, PITCH_NORM, 0, true, vecSrc );
//g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_AUTO, "nero/airstrike/flyby1.wav", 0.7, ATTN_NORM, 0, PITCH_NORM, 0, true, vecSrc );

// fire away!
CBaseEntity@ pRocket1 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 250, pPlayer.edict() );
//CBaseEntity@ pRocket2 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 450, pPlayer.edict() );
//CBaseEntity@ pRocket3 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 150, pPlayer.edict() );
//CBaseEntity@ pRocket4 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 210, pPlayer.edict() );
//CBaseEntity@ pRocket5 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 430, pPlayer.edict() );
//CBaseEntity@ pRocket6 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 240, pPlayer.edict() );

pRocket1.pev.nextthink = 0.01;
pRocket1.pev.movetype = MOVETYPE_FLYMISSILE;
/*
pRocket1.pev.dmg = 70;
pRocket2.pev.dmg = 60;
pRocket3.pev.dmg = 40;
pRocket4.pev.dmg = 60;
pRocket5.pev.dmg = 30;
pRocket6.pev.dmg = 60;
*/
g_EngineFuncs.ClientPrintf( pPlayer, print_center, "Airstrike has arrived!\n" );
}
*/

Nero
30-03-2016, 06:42 PM
CBaseEntity@ pRocket1 = g_EntityFuncs.CreateRPGRocket( vecSrc, vecTargetDir, g_Engine.v_forward * 250, pPlayer.edict() );
Where vecTargetDir = ( tr.vecEndPos.opSub( airstrike_entry ) ).Normalize();
airstrike_entry = tr.vecEndPos from the trace in the command callback (AirstrikeQ2CMD)
vecSrc = airstrike_entry + vecTargetDir;

Nero
30-03-2016, 06:49 PM
Video of what happens.

https://www.youtube.com/watch?v=b309OngV1GU

w00tguy123
30-03-2016, 07:12 PM
Are the rockets supposed to shoot straight down always? Why not use Vector(0,0,180) (or whatever straight down is in HL angles) instead of vecTargetDir?

Nero
30-03-2016, 07:14 PM
Yeah straight down.
Yeah I tried that CBaseEntity@ pRocket1 = g_EntityFuncs.CreateRPGRocket( vecSrc, Vector(0,0,180), g_Engine.v_forward * 250, pPlayer.edict() );
But they still go the same way :[

w00tguy123
30-03-2016, 07:19 PM
Maybe the rockets are colliding with the sky in some weird way? Try spawning the rocket lower or creating an hvr_rocket instead (those don't do the jumping animation thing before starting the thrusters).

Nero
30-03-2016, 07:25 PM
I think it's because of how the RPG Rocket behave yes, the correct angles are probably not getting saved to when the rocket ignites. Or something D:
Oh, so there IS a rocket like that! :O
Thank you!

I just tried it though
CBaseEntity@ pRocket1 = g_EntityFuncs.Create( "hvr_rocket", vecSrc, Vector(0,0,180), false, pPlayer.edict() );
And it goes in the same direction :[

Nero
30-03-2016, 07:28 PM
SOLVED IT!
Vector(90,0,0) for g_EntityFuncs.CreateRPGRocket
and Vector(-90,0,0) for g_EntityFuncs.Create

:D

Nero
30-03-2016, 07:30 PM
Makes sense now that I think of it, Angles are not like Vectors

angles[0] = pitch (up and down)
angles[1] = yaw (turn left and right)
angles[2] = roll (tilt left and right, not really used)

^^

Nero
30-03-2016, 07:31 PM
The source coords are still a bit off though, they're not exactly above where I look when executing the command for some reason. D:

edit: at least not when looking at the skybrush. It only happens when looking at the ground.

Nero
30-03-2016, 07:42 PM
Replacing g_Utility.TraceLine( vecSrc, vecSrc + g_Engine.v_up * 8192, ignore_monsters, pPlayer.edict(), tr );
with g_Utility.TraceLine( vecSrc, vecSrc + Vector( 0, 0, 180 ) * 8192, ignore_monsters, pPlayer.edict(), tr );

Fixed that! :D