PDA

View Full Version : Drop a model



ORDI
31st May 2015, 12:13
Hello

i would like to know how to drop a model, i mean:
i get a sentry from shop and this sentry must be in my vision and it moves only if i move my vision and i have to press f to drop the model. Mhm idk how to say, i hope you understand, i have already seen it in a few servers and i would like to have it too.

i tried somethings with 'self geteye()' but it do not work.

ORDI

kung foo man
31st May 2015, 19:58
To get the position your player is looking to, try this:

https://github.com/kungfooman/cod2_std/blob/master/utils.gsc#L203




getRealEye()
{
player = self;

stance = player getStance();

offset = 0;
switch (stance)
{
case "stand": offset = 20; break;
case "duck": offset = 0; break;
case "lie": offset = -30; break;
//default: offset = getcvarint("offset");
}

realEye = player getEye() + (0,0,offset);
return realEye;
}

lookAtRaw()
{
player = self;

originStart = player getRealEye();
//originStart = player getTagOrigin("j_head");
//originStart = player getTagOrigin("tag_aim");

angles = player getPlayerAngles();
forward = anglesToForward(angles);

originEnd = originStart + vectorScale(forward, 100000);

trace = bullettrace(originStart, originEnd, false, undefined);

if (trace["fraction"] == 1)
return undefined;

return trace;
}



The getStance() function needs libcod though.

You still need to add a distance check, like replacing



originEnd = originStart + vectorScale(forward, 100000);


with



originEnd = originStart + vectorScale(forward, 100);


If you can't run libcod, replace getRealEye() with getEye().

Tally
31st May 2015, 20:57
GetStance() for normal COD2:


GetStance()
{
trace = bulletTrace( self.origin, self.origin + ( 0, 0, 80 ), false, undefined );
top = trace["position"] + ( 0, 0, -1); //find the ceiling, if it's lower than 80

bottom = self.origin + ( 0, 0, -12 );
forwardangle = maps\mp\_utility::vectorScale( anglesToForward( self.angles ), 12 );

leftangle = ( -1 * forwardangle[1], forwardangle[0], 0 );//a lateral vector

//now do traces at different sample points
//there are 9 sample points, forming a 3x3 grid centered on player's origin
//and oriented with the player facing forward
trace = bulletTrace( top + forwardangle, bottom + forwardangle, true, undefined );
height1 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top - forwardangle, bottom - forwardangle, true, undefined );
height2 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top + leftangle, bottom + leftangle, true, undefined );
height3 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top - leftangle, bottom - leftangle, true, undefined );
height4 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top + leftangle + forwardangle, bottom + leftangle + forwardangle, true, undefined );
height5 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top - leftangle + forwardangle, bottom - leftangle + forwardangle, true, undefined );
height6 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top + leftangle - forwardangle, bottom + leftangle - forwardangle, true, undefined );
height7 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top - leftangle - forwardangle, bottom - leftangle - forwardangle, true, undefined );
height8 = trace["position"][2] - self.origin[2];

trace = bulletTrace( top, bottom, true, undefined );
height9 = trace["position"][2] - self.origin[2];

//find the maximum of the height samples
heighta = getMax( height1, height2, height3, height4 );
heightb = getMax( height5, height6, height7, height8 );
maxheight = getMax( heighta, heightb, height9, 0 );

//categorize stance based on height
if( maxheight < 33 )
stance = "lie";
else if( maxheight < 52 )
stance = "duck";
else
stance = "stand";

return( stance );
}

ORDI
3rd June 2015, 15:02
mhm where is the problem ? i would like every 0.1 second, the model move according to my vision.



sentry()
{
self endon("disconnect");
self endon("killed_player");

self iprintlnbold("^7Press ^3[^7F^3] ^7to Place a sentry");
sentry = spawn("script_model",self geteye()+(0,0,-40));
sentry setmodel("xmodel/ordi_sentrygun");
s1 = undefined;

for(;;)
{
wait 0.1;
trace = bullettrace(self getEye()+(0,0,-40), self getEye()+(0,0,-40)+maps\mp\_utility::vectorScale(anglesToForward( self getPlayerAngles()), 100000), false, undefined);

if(trace["fraction"]!=1)
{
if(isdefined(trace["entity"]))
{
if(isplayer(trace["entity"]))
{
s1=trace["entity"];
sentry.origin = s1.origin;
s1 linkto(sentry);
}
}
}

if(self usebuttonpressed())
{
sentry unlink();
s1=undefined;
self iprintln("Sentry placed!");
self thread activation_sentry();
break;
}
}
}