Last active
March 5, 2021 21:37
-
-
Save AmyrAhmady/0266a6b33b61d72f20cd8c623291f264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FILTERSCRIPT | |
#include <a_samp> | |
#include <colandreas> | |
new pBall; | |
new | |
Float:InGameX = 0.7, | |
Float:InGameY = 0.525, | |
Float:InGameYw = 0.4, // Widescreen | |
Float:OnScreenX = 640.0, | |
Float:OnScreenY = 448.0; | |
stock NormCrossProduct(&Float:x, &Float:y, &Float:z, Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z) | |
{ | |
x = v1y * v2z - v2y * v1z; | |
y = v1z * v2x - v2z * v1x; | |
z = v1x * v2y - v2x * v1y; | |
v1x = VectorSize(x,y,z); | |
x /= v1x; | |
y /= v1x; | |
z /= v1x; | |
} | |
stock ScreenToWorld(playerid, Float:screenX, Float:screenY, &Float:vX, &Float:vY, &Float:vZ) | |
{ | |
if((0.0 <= screenX <= OnScreenX) && (0.0 <= screenY <= OnScreenY) | |
&& GetPlayerCameraFrontVector(playerid, vX, vY, vZ)) | |
{ | |
new | |
Float:pX = ((screenX / OnScreenX) - 0.5) * 2.0 * InGameX, | |
Float:pZ = ((screenY / OnScreenY) - 0.5) * 2.0 * ((GetPlayerCameraAspectRatio(playerid) > 1.375) ? InGameYw : InGameY), | |
Float:nXx, Float:nYx, Float:nZx, | |
Float:nXz, Float:nYz, Float:nZz; | |
NormCrossProduct(nXx, nYx, nZx, vX, vY, vZ, 0.0, 0.0, 1.0); | |
NormCrossProduct(nXz, nYz, nZz, vX, vY, vZ, nXx, nYx, nZx); | |
vX += nXx * pX + nXz * pZ; | |
vY += nYx * pX + nYz * pZ; | |
vZ += nZx * pX + nZz * pZ; | |
return 1; | |
} | |
return 0; | |
} | |
stock ScreenToWorld_RayCast(playerid, Float:distance, Float:screenX, Float:screenY, &Float:wX, &Float:wY, &Float:wZ) | |
{ | |
if(ScreenToWorld(playerid, screenX, screenY, wX, wY, wZ)) | |
{ | |
new | |
Float:cX, Float:cY, Float:cZ; | |
GetPlayerCameraPos(playerid, cX, cY, cZ); | |
wX = cX + (wX * distance); | |
wY = cY + (wY * distance); | |
wZ = cZ + (wZ * distance); | |
return CA_RayCastLine(cX, cY, cZ, wX, wY, wZ+0.001, wX, wY, wZ) + 1; | |
} | |
return 0; | |
} | |
public OnFilterScriptInit() | |
{ | |
print("\n--------------------------------------"); | |
print(" ColAndreas demo script"); | |
print("--------------------------------------\n"); | |
pBall = CreateObject(1598, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | |
CA_Init(); | |
return 1; | |
} | |
public OnFilterScriptExit() | |
{ | |
return 1; | |
} | |
public OnPlayerCommandText(playerid, cmdtext[]) | |
{ | |
if (strcmp("/weap", cmdtext, true, 10) == 0) | |
{ | |
GivePlayerWeapon(playerid, 26, 1000); | |
return 1; | |
} | |
return 0; | |
} | |
public OnPlayerUpdate(playerid) | |
{ | |
new | |
Float:object_x, Float:object_y, Float:object_z; | |
new | |
lr, ud, keys; | |
GetPlayerKeys(playerid, keys, ud, lr); | |
if(keys & 128) | |
{ | |
new ret = ScreenToWorld_RayCast(playerid, 30.0, (OnScreenX / 2.0) + 20, (OnScreenY / 2.0) - 45, object_x, object_y, object_z); | |
SetObjectPos(pBall, object_x, object_y, object_z); | |
new str[100]; | |
format(str, 100, "ball pos: %f, %f, %f, modelid: %d", object_x, object_y, object_z, ret - 1); | |
SendClientMessage(playerid, -1, str); | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment