Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- **************************************************
- * @Script: Surface To Air Missiles (SAMs) *
- * @Author: Grim_ *
- * @License: N/A *
- **************************************************
- ** If you use my script, please give me credits **
- **************************************************
- native CreateSAM(bool:create_object, Float:x, Float:y, Float:z, Float:range, Float:damage, Float:speed, delay, teamID=NO_TEAM);
- native DestroySAM(samid);
- native MoveSAM(samid, Float:newx, Float:newy, Float:newz);
- native CreatedSAMs();
- native IsValidSAM(samid);
- native GetSAMRange(samid);
- native GetSAMDamage(samid);
- native GetSAMSpeed(samid);
- native GetSAMDelay(samid);
- native GetSAMTeamID(samid);
- native SetSAMRange(samid, Float:range);
- native SetSAMDamage(samid, Float:damage);
- native SetSAMSpeed(samid, Float:speed);
- native SetSAMDelay(samid, delay);
- native SetSAMTeamID(samid, teamID);
- native FireSAM(samid, targetid, bool:force);
- public OnSAMFired(samid, targetid);
- public OnSAMDie(samid, reason);
- */
- #include <a_samp>
- #define MAX_SAM_SITES 10
- #define REASON_SAM_TARGET_HIT 1
- #define REASON_SAM_TARGET_DIED 2
- #define REASON_SAM_DESTROYED 3
- #define REASON_SAM_FORCE_FIRE 4
- enum SamInfo
- {
- Float:SamX,
- Float:SamY,
- Float:SamZ,
- Float:SamRange,
- Float:SamDamage,
- Float:SamSpeed,
- SamObject,
- SamIsChasing,
- SamDelay,
- SamMissile,
- bool:SamCreated,
- SamTeamID,
- SamNextTarget
- }
- new SamData[MAX_SAM_SITES][SamInfo];
- new Sams;
- /*
- FUNCTION: CreateSAM
- PARAMATERS:
- bool:create_object - whether or not to create the SAM object
- Float:x - The X position of the SAM
- Float:y - The Y position of the SAM
- Float:z - The Z position of the SAM
- Float:range - The range the SAM will fire at (If the vehicle is in that range)
- damage - The amount of damage the SAM will inflict on the vehicle it hits
- speed - How quickly the SAM missile moves
- delay - The amount of time the SAM must wait to fire another missile
- USE: Creates a SAM missile at the desired location with the specified stats
- RETURNS: The ID of the SAM created (If none, returns -1)
- */
- stock CreateSAM(bool:create_object, Float:x, Float:y, Float:z, Float:range, Float:damage, Float:speed, delay, teamID=NO_TEAM)
- {
- for(new i = 0; i < MAX_SAM_SITES; i++)
- {
- if(SamData[i][SamCreated] == true) continue;
- if(create_object == true)
- {
- SamData[i][SamObject] = CreateObject(3884, x, y, z, 0.00, 0.00, 0.00);
- }
- SamData[i][SamX] = x;
- SamData[i][SamY] = y;
- SamData[i][SamZ] = z;
- SamData[i][SamRange] = range;
- SamData[i][SamDamage] = damage;
- SamData[i][SamSpeed] = speed;
- SamData[i][SamDelay] = delay*1000;
- SamData[i][SamCreated] = true;
- SamData[i][SamTeamID] = teamID;
- Sams++;
- return i;
- }
- return -1;
- }
- /*
- FUNCTION: DestroySAM
- PARAMATERS:
- samid - The ID of the SAM to destroy
- USE: Destroys the desired SAM
- RETURNS: 1 if successful, 0 if not
- */
- stock DestroySAM(samid)
- {
- if(!IsValidSAM(samid)) return 0;
- DestroyObject(SamData[samid][SamObject]);
- SamData[samid][SamX] = 0.00;
- SamData[samid][SamY] = 0.00;
- SamData[samid][SamZ] = 0.00;
- SamData[samid][SamRange] = 0.00;
- SamData[samid][SamDamage] = 0.00;
- SamData[samid][SamSpeed] = 0.00;
- SamData[samid][SamDelay] = 0;
- SamData[samid][SamCreated] = false;
- if(SamData[samid][SamMissile] != -1)
- {
- new Float:x, Float:y, Float:z;
- GetObjectPos(SamData[samid][SamMissile], x, y, z);
- CreateExplosion(x, y, z, 1, 8);
- DestroyObject(SamData[samid][SamMissile]);
- OnSAMDie(samid, REASON_SAM_DESTROYED);
- }
- SamData[samid][SamMissile] = -1;
- SamData[samid][SamObject] = -1;
- SamData[samid][SamIsChasing] = -1;
- SamData[samid][SamTeamID] = NO_TEAM;
- SamData[samid][SamNextTarget] = -1;
- Sams--;
- return 1;
- }
- /*
- FUNCTION: MoveSAM
- PARAMATERS:
- samid - The ID of the SAM you want to move
- Float:newx - The new X position of the SAM
- Float:newy - The new Y position of the SAM
- Float:newz - The new Z position of the SAM
- USE: Moves the desired SAM to the new specified location
- RETURNS: 1 if successful, 0 if not
- */
- stock MoveSAM(samid, Float:newx, Float:newy, Float:newz)
- {
- if(!IsValidSAM(samid)) return 0;
- SamData[samid][SamX] = newx;
- SamData[samid][SamY] = newy;
- SamData[samid][SamZ] = newz;
- return 1;
- }
- /*
- FUNCTION: GetSAMRange
- PARAMATERS:
- samid - The ID of the SAM to get the range from
- USE: Returns the Range of the specified SAM
- RETURNS: Range of the specified SAM, 0 if failure
- */
- stock Float:GetSAMRange(samid)
- {
- if(!IsValidSAM(samid)) return 0.0;
- return SamData[samid][SamRange];
- }
- /*
- FUNCTION: SetSAMRange
- PARAMATERS:
- samid - The ID of the SAM to change the range of
- Float:range - The new range of the SAM
- USE: Sets the range of the specified SAM
- RETURNS: 1 if successful, 0 if not
- */
- stock SetSAMRange(samid, Float:range)
- {
- if(!IsValidSAM(samid)) return 0;
- SamData[samid][SamRange] = range;
- return 1;
- }
- /*
- FUNCTION: GetSAMDamage
- PARAMATERS:
- samid - The ID of the SAM to get the damage count from
- USE: Returns the damage of the specified SAM
- RETURNS: Damage Count for the specified SAM, 0 if failure
- */
- stock Float:GetSAMDamage(samid)
- {
- if(!IsValidSAM(samid)) return 0.0;
- return SamData[samid][SamDamage];
- }
- /*
- FUNCTION: SetSAMDamage
- PARAMATERS:
- samid - The ID of the SAM to set the damage count of
- Float:damage - The new damage of the SAM
- USE: Sets the damage of the specified SAM
- RETURNS: 1 if successful, 0 if not
- */
- stock SetSAMDamage(samid, Float:damage)
- {
- if(!IsValidSAM(samid)) return 0;
- SamData[samid][SamDamage] = damage;
- return 1;
- }
- /*
- FUNCTION: GetSAMSpeed
- PARAMATERS:
- samid - The ID of the SAM to get the speed from
- USE: Returns the speed of the specified SAM
- RETURNS: Speed of the specified SAM, 0 if failure
- */
- stock Float:GetSAMSpeed(samid)
- {
- if(!IsValidSAM(samid)) return 0.0;
- return SamData[samid][SamSpeed];
- }
- /*
- FUNCTION: SetSAMSpeed
- PARAMATERS:
- samid - The ID of the SAM to set the speed of
- Float:speed - The new speed of the specified SAM
- USE: Sets the speed of the specified SAM
- RETURNS: 1 if successful, 0 if not
- */
- stock SetSAMSpeed(samid, Float:speed)
- {
- if(!IsValidSAM(samid)) return 0;
- SamData[samid][SamSpeed] = speed;
- return 1;
- }
- /*
- FUNCTION: GetSAMDelay
- PARAMATERS:
- samid - The ID of the SAM to get the delay from
- USE: Returns the delay of the specified SAM
- RETURNS: Delay of the specified SAM, 0 if failure
- */
- stock GetSAMDelay(samid)
- {
- if(!IsValidSAM(samid)) return 0;
- return SamData[samid][SamDelay];
- }
- /*
- FUNCTION: SetSAMDelay
- PARAMATERS:
- samid - The ID of the SAM to set the delay of
- delay - The new delay of the specified SAM
- USE: Sets the delay of the specified SAM
- RETURNS: 1 if successful, 0 if not
- */
- stock SetSAMDelay(samid, delay)
- {
- if(!IsValidSAM(samid)) return 0;
- SamData[samid][SamDelay] = delay;
- return 1;
- }
- /*
- FUNCTION: GetSAMTeamID
- PARAMATERS:
- samid - The ID of the SAM to get the team ID from
- USE: Returns the team ID of the specified SAM
- RETURNS: The team ID of the specified SAM, 0 if failure
- */
- stock GetSAMTeamID(samid)
- {
- if(!IsValidSAM(samid)) return 0;
- return SamData[samid][SamTeamID];
- }
- /*
- FUNCTION: SetSAMTeamID
- PARAMATERS:
- samid - The ID of the SAM to set the team ID of
- teamID - The new team ID of the specified SAM
- USE: Sets the team ID of the specified SAM
- RETURNS: 1 if successful, 0 if not
- */
- stock SetSAMTeamID(samid, teamID)
- {
- if(!IsValidSAM(samid)) return 0;
- SamData[samid][SamTeamID] = teamID;
- return 1;
- }
- /*
- FUNCTION: CreatedSAMs
- PARAMATERS: N/A
- USE: Returns the number of SAMS in the server
- RETURNS: Number of SAMS in the server
- */
- stock CreatedSAMs() return Sams;
- /*
- FUNCTION: IsValidSAM
- PARAMATERS:
- samid - The SAM you want to check is valid
- USE: Checks whether or not the specified SAM is valid (created)
- RETURNS: 1 if the SAM is created, 0 if not
- */
- stock IsValidSAM(samid)
- {
- if(SamData[samid][SamCreated] == true) return 1;
- return 0;
- }
- /*
- FUNCTION: FireSAM
- PARAMATERS:
- samid - The SAM you want to fire
- targetid - The vehicle ID that you want to fire at
- USE: Fires a missile directly at targetid
- RETURNS: 1 if successful, 0 if not
- */
- stock FireSAM(samid, targetid, bool:force)
- {
- new Float:x, Float:y, Float:z;
- GetVehiclePos(targetid, x, y, z);
- if(x == 0.00 && y == 0.00 && z == 0.00) return 0;
- if(SamData[samid][SamMissile] != -1)
- {
- if(force == false)
- {
- SamData[samid][SamNextTarget] = targetid;
- return 1;
- }
- GetObjectPos(SamData[samid][SamMissile], x, y, z);
- CreateExplosion(x, y, z, 1, 8.0);
- DestroyObject(SamData[samid][SamMissile]);
- SamData[samid][SamIsChasing] = -1;
- OnSAMDie(samid, REASON_SAM_FORCE_FIRE);
- }
- OnSAMFired(samid, targetid);
- SamData[samid][SamMissile] = CreateObject(354, SamData[samid][SamX], SamData[samid][SamY], SamData[samid][SamZ], 0.00, 0.00, 0.00);
- SamData[samid][SamIsChasing] = targetid;
- UpdateSam(targetid, samid);
- return 1;
- }
- /*
- CALLBACK: OnSAMFired
- ARGUMENTS:
- samid - The SAM that was fired
- targetid - The vehicleid the SAM's missile is chasing
- CALLED: When A SAM's missile is fired
- */
- forward OnSAMFired(samid, targetid);
- //public OnSAMFired(samid, targetid) return 1;
- /*
- CALLBACK: OnSAMDie
- ARGUMENTS:
- samid - The SAM's missile that died
- reason - The reason the missile died
- REASON_SAM_TARGET_HIT - The vehicle the missile was chasing was hit
- REASON_SAM_TARGET_DIED - The vehicle the missile was chasing died
- REASON_SAM_DESTROYED - The SAM site was destroyed
- REASON_SAM_FORCE_FIRE - The SAM site was forced to fire, killing the missile (FireSAM)
- CALLED: When a SAM's missile dies
- */
- forward OnSAMDie(samid, reason);
- //public OnSAMDie(samid, reason) return 1;
- // ---------------------------------------------------------------------------------------------------
- // ---------------------------------------------------------------------------------------------------
- // ---------------------------------------------------------------------------------------------------
- forward OnSamInit();
- public OnSamInit()
- {
- SetTimer("CheckSams", 1000, true);
- for(new s = 0; s < MAX_SAM_SITES; s++)
- {
- SamData[s][SamIsChasing] = -1;
- SamData[s][SamObject] = -1;
- SamData[s][SamMissile] = -1;
- SamData[s][SamTeamID] = -1;
- SamData[s][SamNextTarget] = -1;
- }
- }
- forward OnVehicleDeathX(vehicleid, killerid);
- public OnVehicleDeathX(vehicleid, killerid)
- {
- for(new s = 0; s < MAX_SAM_SITES; s++)
- {
- if(SamData[s][SamIsChasing] == vehicleid)
- {
- new Float:x, Float:y, Float:z;
- GetObjectPos(SamData[s][SamMissile], x, y, z);
- CreateExplosion(x, y, z, 1, 8);
- DestroyObject(SamData[s][SamMissile]);
- OnSAMDie(s, REASON_SAM_TARGET_DIED);
- SetTimerEx("ClearSam", SamData[s][SamDelay], false, "i", s);
- }
- }
- return 1;
- }
- forward CheckSams();
- public CheckSams()
- {
- for(new i = 0; i < GetMaxPlayers(); i++)
- {
- if(!IsPlayerConnected(i)) continue;
- if(IsPlayerVehicleAirVehicle(i))
- {
- for(new s = 0; s < MAX_SAM_SITES; s++)
- {
- if(!IsValidSAM(s)) continue;
- if(SamData[s][SamMissile] != -1) continue;
- if(GetPlayerTeam(i) == SamData[s][SamTeamID]) continue;
- if(IsPlayerInRangeOfPoint(i, SamData[s][SamRange], SamData[s][SamX], SamData[s][SamY], SamData[s][SamZ]))
- {
- OnSAMFired(s, GetPlayerVehicleID(i));
- SamData[s][SamMissile] = CreateObject(354, SamData[s][SamX], SamData[s][SamY], SamData[s][SamZ], 0.00, 0.00, 0.00);
- SamData[s][SamIsChasing] = GetPlayerVehicleID(i);
- UpdateSam(GetPlayerVehicleID(i), s);
- }
- }
- }
- }
- return 1;
- }
- forward UpdateSam(chasingid, samid);
- public UpdateSam(chasingid, samid)
- {
- new Float:x, Float:y, Float:z;
- GetVehiclePos(chasingid, x, y, z);
- if(IsObjectInRangeOfPoint(SamData[samid][SamMissile], 5, x, y, z))
- {
- new Float:vhealth;
- CreateExplosion(x, y, z, 1, 8.0);
- SetVehicleHealth(chasingid, GetVehicleHealth(chasingid, vhealth)-SamData[samid][SamDamage]);
- DestroyObject(SamData[samid][SamMissile]);
- SamData[samid][SamIsChasing] = -1;
- OnSAMDie(samid, REASON_SAM_TARGET_HIT);
- SetTimerEx("ClearSam", SamData[samid][SamDelay], false, "i", samid);
- return 1;
- }
- MoveObject(SamData[samid][SamMissile], x, y, z, SamData[samid][SamSpeed]);
- SetTimerEx("UpdateSam", 100, false, "ii", chasingid, samid);
- return 1;
- }
- forward ClearSam(samid);
- public ClearSam(samid)
- {
- SamData[samid][SamMissile] = -1;
- if(SamData[samid][SamNextTarget] != -1)
- {
- FireSAM(samid, SamData[samid][SamNextTarget], true);
- SamData[samid][SamNextTarget] = -1;
- }
- return 1;
- }
- IsPlayerVehicleAirVehicle(playerid)
- {
- new AirVeh[] = { 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469 };
- for(new i = 0; i < sizeof(AirVeh); i++)
- {
- if(GetVehicleModel(GetPlayerVehicleID(playerid)) == AirVeh[i])
- {
- return 1;
- }
- }
- return 0;
- }
- IsObjectInRangeOfPoint(objectid, Float:range, Float:x, Float:y, Float:z)
- {
- new Float:oldpos[3];
- new Float:temppos[3];
- GetObjectPos(objectid, oldpos[0], oldpos[1], oldpos[2]);
- temppos[0] = (oldpos[0] -x);
- temppos[1] = (oldpos[1] -y);
- temppos[2] = (oldpos[2] -z);
- if(((temppos[0] < range) && (temppos[0] > -range)) && ((temppos[1] < range) && (temppos[1] > -range)) && ((temppos[2] < range) && (temppos[2] > -range)))
- {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement