Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******** OnPlayerLookAtVehicle Include by iPLEOMAX, (c) 2012. ****************/
- /******** Credit me, if you use anything from here. ****************/
- /******** Thanks to: ****************/
- /******** JernejL - DistanceCameraTargetToLocation. ****************/
- /******** CracK - Trignometry Help (because of his post). ****************/
- /******** Thank you for Downloading! ;) ****************/
- /******************************************************************************/
- #if defined _inc_vlook
- #endinput
- #endif
- #define _inc_vlook
- #include <a_samp>
- #define VLA_UPDATE_RATE 200 //in Milliseconds.
- #define MAX_VLA_DISTANCE 200 //in San Andreas Map Unit
- //native EnableVehicleLookAt(forplayerid);
- //native DisableVehicleLookAt(forplayerid);
- //native Callback - OnPlayerLookAtVehicle(playerid, oldvehicle, newvehicle);
- new
- bool:VLA_ENABLED[MAX_PLAYERS],
- bool:VEH_ON_SIGHT[MAX_PLAYERS],
- VLA_CURRENT[MAX_PLAYERS],
- VLA_TEMP[MAX_PLAYERS],
- VLA_Timer,
- Float:VLA_VX[MAX_VEHICLES],
- Float:VLA_VY[MAX_VEHICLES],
- Float:VLA_VZ[MAX_VEHICLES],
- Float:VLA_Dis[MAX_PLAYERS],
- Float:VLA_PX[MAX_PLAYERS],
- Float:VLA_PY[MAX_PLAYERS],
- Float:VLA_PZ[MAX_PLAYERS]
- ;
- public OnPlayerDisconnect(playerid, reason)
- {
- VEH_ON_SIGHT[playerid] = false;
- VLA_CURRENT[playerid] = 0;
- VLA_TEMP[playerid] = 0;
- VLA_Dis[playerid] = 0;
- VLA_PX[playerid] = 0;
- VLA_PY[playerid] = 0;
- VLA_PZ[playerid] = 0;
- if (funcidx("vla_OnPlayerDisconnect") != -1) return CallLocalFunction("vla_OnPlayerDisconnect", "ii", playerid, reason);
- return true;
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect vla_OnPlayerDisconnect
- public OnFilterScriptInit()
- {
- printf(" * OnPlayerLookAtVehicle (c) iPLEOMAX 2012.");
- VLA_Timer = SetTimer("ScanVehicleLookAt", VLA_UPDATE_RATE, true);
- if (funcidx("vla_OnFilterScriptInit") != -1) return CallLocalFunction("vla_OnFilterScriptInit", "");
- return true;
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit vla_OnFilterScriptInit
- public OnFilterScriptExit()
- {
- KillTimer(VLA_Timer);
- if (funcidx("vla_OnFilterScriptExit") != -1) return CallLocalFunction("vla_OnFilterScriptExit", "");
- return true;
- }
- #if defined _ALS_OnFilterScriptExit
- #undef OnFilterScriptExit
- #else
- #define _ALS_OnFilterScriptExit
- #endif
- #define OnFilterScriptExit vla_OnFilterScriptExit
- forward ScanVehicleLookAt();
- public ScanVehicleLookAt()
- {
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(!IsPlayerConnected(i)) continue;
- VEH_ON_SIGHT[i] = false;
- if(VLA_ENABLED[i])
- {
- VLA_Dis[i] = MAX_VLA_DISTANCE;
- for(new v=0; v<MAX_VEHICLES; v++)
- {
- if(!GetVehicleModel(v)) continue;
- if(GetPlayerVehicleID(i) == v) continue;
- if(!IsVehicleStreamedIn(v, i)) continue;
- GetVehiclePos(v, VLA_VX[v], VLA_VY[v], VLA_VZ[v]);
- GetPlayerPos(i, VLA_PX[i], VLA_PY[i], VLA_PZ[i]);
- new Float:radius = 2.0, Float:Distance =
- floatround
- (
- floatsqroot
- (
- floatpower(floatabs(floatsub(VLA_PX[i],VLA_VX[v])),2)+
- floatpower(floatabs(floatsub(VLA_PY[i],VLA_VY[v])),2)+
- floatpower(floatabs(floatsub(VLA_PZ[i],VLA_VZ[v])),2)
- )
- )
- ;
- if (Distance > MAX_VLA_DISTANCE) continue;
- if (Distance < 5) radius = 3.5;
- if(VehicleAimed(i, v, radius))
- {
- VEH_ON_SIGHT[i] = true;
- if(Distance < VLA_Dis[i]) VLA_TEMP[i] = v;
- VLA_Dis[i] = Distance;
- }
- }
- }
- switch(VEH_ON_SIGHT[i])
- {
- case true: {
- if(VLA_TEMP[i] != VLA_CURRENT[i])
- {
- CallLocalFunction("OnPlayerLookAtVehicle", "iii", i, VLA_CURRENT[i], VLA_TEMP[i]);
- VLA_CURRENT[i] = VLA_TEMP[i];
- }
- }
- case false: {
- if(VLA_CURRENT[i]) CallLocalFunction("OnPlayerLookAtVehicle", "iii", i, VLA_CURRENT[i], 0);
- VLA_CURRENT[i] = 0;
- }
- }
- }
- return true;
- }
- Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
- new Float:TGTDistance;
- TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
- new Float:tmpX, Float:tmpY, Float:tmpZ;
- tmpX = FrX * TGTDistance + CamX;
- tmpY = FrY * TGTDistance + CamY;
- tmpZ = FrZ * TGTDistance + CamZ;
- return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
- }
- stock VehicleAimed(playerid, vehicleid, Float:radius)
- {
- new
- Float:CamX, Float:CamY, Float:CamZ,
- Float:VecX, Float:VecY, Float:VecZ
- ;
- GetPlayerCameraPos(playerid, CamX, CamY, CamZ);
- GetPlayerCameraFrontVector(playerid, VecX, VecY, VecZ);
- return (radius >= DistanceCameraTargetToLocation(CamX, CamY, CamZ,
- VLA_VX[vehicleid], VLA_VY[vehicleid], VLA_VZ[vehicleid], VecX, VecY, VecZ));
- }
- stock EnableVehicleLookAt(forplayerid) VLA_ENABLED[forplayerid] = true;
- stock DisableVehicleLookAt(forplayerid) VLA_ENABLED[forplayerid] = false;
- forward OnPlayerLookAtVehicle(playerid, oldvehicle, newvehicle);
- /*
- native EnableVehicleLookAt(forplayerid);
- native DisableVehicleLookAt(forplayerid);
- native Callback - OnPlayerLookAtVehicle(playerid, oldvehicle, newvehicle);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement