Skip to content

Instantly share code, notes, and snippets.

@Southclaws
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Southclaws/9173392 to your computer and use it in GitHub Desktop.
Save Southclaws/9173392 to your computer and use it in GitHub Desktop.
A testing script for rendering lines on camera and bullet vectors for hit spread analysis.
#define FILTERSCRIPT
#include <a_samp>
#include <streamer> // by Incognito - github.com/samp-incognito/samp-streamer-plugin/releases
#include <SIF/Core.pwn> // by Southclaw - github.com/Southclaw/SIF
#include <strlib> // by Slice - github.com/oscar-broman/strlib
#include <Line> // by Southclaw - github.com/Southclaw/Line
#include <ZCMD> // by Zeex - forum.sa-mp.com/showthread.php?t=91354
public OnFilterScriptInit()
{
Streamer_ToggleIdleUpdate(0, true);
SetWorldTime(0); // So we can see neon
}
Float:absoluteangle(Float:angle)
{
while(angle < 0.0)angle += 360.0;
while(angle > 360.0)angle -= 360.0;
return angle;
}
stock GetPlayerCameraWeaponVector(playerid, & Float: vX, & Float: vY, & Float: vZ)
{
if(GetPlayerCameraFrontVector(playerid, vX, vY, vZ))
{
switch(GetPlayerWeapon(playerid))
{
case WEAPON_SNIPER, WEAPON_ROCKETLAUNCHER, WEAPON_HEATSEEKER:
{
return true;
}
case WEAPON_RIFLE:
{
new
Float: angle = -(atan2(vX, vY) + 12.920722)
;
vX += floatcos(angle, degrees) * 0.019384;
vY += floatsin(angle, degrees) * 0.019384;
vZ += 0.047052;
return true;
}
case WEAPON_AK47, WEAPON_M4:
{
new
Float: angle = -(atan2(vX, vY) + 16.827384)
;
vX += floatcos(angle, degrees) * 0.029147;
vY += floatsin(angle, degrees) * 0.029147;
vZ += 0.069293;
return true;
}
case WEAPON_COLT45 .. WEAPON_MP5, WEAPON_TEC9, WEAPON_FLAMETHROWER, WEAPON_MINIGUN:
{
new
Float: angle = -(atan2(vX, vY) + 15.476425)
;
vX += floatcos(angle, degrees) * 0.043317;
vY += floatsin(angle, degrees) * 0.043317;
vZ += 0.103916;
return true;
}
}
}
return false;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(fX*fY*fZ == 0.0)
return 1;
new
Float:fOriginX,
Float:fOriginY,
Float:fOriginZ,
Float:fHitPosX,
Float:fHitPosY,
Float:fHitPosZ;
new
Float:fCamVecX,
Float:fCamVecY,
Float:fCamVecZ,
Float:fHitVecX,
Float:fHitVecY,
Float:fHitVecZ;
new
Float:fBulletRotation,
Float:fBulletElevation,
Float:fCameraRotation,
Float:fCameraElevation;
GetPlayerLastShotVectors(playerid, fOriginX, fOriginY, fOriginZ, fHitPosX, fHitPosY, fHitPosZ);
GetPlayerCameraWeaponVector(playerid, fCamVecX, fCamVecY, fCamVecZ);
fHitVecX = fHitPosX - fOriginX;
fHitVecY = fHitPosY - fOriginY;
fHitVecZ = fHitPosZ - fOriginZ;
fBulletRotation = absoluteangle(-(90-(atan2((fHitVecY), (fHitVecX)))));
fBulletElevation = 90-floatabs(atan2(floatsqroot(floatpower(fHitVecX, 2.0) + floatpower(fHitVecY, 2.0)), fHitVecZ));
fCameraRotation = absoluteangle(-(90-(atan2((fCamVecY), (fCamVecX)))));
fCameraElevation = 90-floatabs(atan2(floatsqroot(floatpower(fCamVecX, 2.0) + floatpower(fCamVecY, 2.0)), fCamVecZ));
ShowActionText(playerid,
sprintf("~>~: %.2f | ~u~: %.2f~n~~>~: %.2f | ~u~: %.2f~n~~>~: %.2f | ~u~: %.2f",
fBulletRotation, fBulletElevation,
fCameraRotation, fCameraElevation,
fCameraRotation - fBulletRotation, fCameraElevation - fBulletElevation), 0);
CreateLineSegment(19087, 2.46,
fOriginX, fOriginY, fOriginZ,
fHitPosX, fHitPosY, fHitPosZ,
.RotX = 90.0, .objlengthoffset = -(2.46/2));
new
Float:fCamPosX,
Float:fCamPosY,
Float:fCamPosZ;
GetPlayerCameraPos(playerid, fCamPosX, fCamPosY, fCamPosZ);
CreateLineSegment(18648, 2.0,
fCamPosX, fCamPosY, fCamPosZ,
fCamPosX + (fCamVecX * 100), fCamPosY + (fCamVecY * 100), fCamPosZ + (fCamVecZ * 100),
.RotX = 0.0, .objlengthoffset = -(2.0/2));
return 0;
}
CMD:w(playerid, params[])
{
GivePlayerWeapon(playerid, strval(params), 99999);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment