Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAX_CANNON_RANGE 200
- #define MIN_CANNON_RANGE 15
- new firedcannon[MAX_PLAYERS];
- new CannonRange[MAX_PLAYERS] = 50;
- new HPDeathCallTimer[MAX_PLAYERS];
- stock randomEx(min, max)
- {
- new rand9 = random(max-min)+min;
- return rand9;
- }//credits to yless
- stock GetPlayerVSpeed(playerid)
- {
- new Float:x,Float:y,Float:z,Float:speed,final_speed;
- GetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z);
- speed = floatsqroot(((x*x)+(y*y))+(z*z))*100;
- final_speed = floatround(speed,floatround_round);
- return final_speed;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 601)
- {
- new string[128];
- if(HOLDING(65536))//yes
- {
- if(CannonRange[playerid] < MAX_CANNON_RANGE)
- {
- CannonRange[playerid] = CannonRange[playerid]+1;
- format(string, sizeof(string), "~g~Cannon's Range Increased To %i",CannonRange[playerid]);
- GameTextForPlayer(playerid,string,5000,4);
- }
- else
- {
- GameTextForPlayer(playerid,"~r~Cannon is at the maximum range of 200 meters",5000,4);
- }
- }
- else if(HOLDING(131072))//no
- {
- if(CannonRange[playerid] > MIN_CANNON_RANGE)
- {
- CannonRange[playerid] = CannonRange[playerid]-1;
- format(string, sizeof(string), "~r~Cannon's Range Decreased To %i",CannonRange[playerid]);
- GameTextForPlayer(playerid,string,5000,4);
- }
- else
- {
- GameTextForPlayer(playerid,"~r~Cannon is at the minimum range of 15 meters",5000,4);
- }
- }
- }
- if(newkeys & KEY_FIRE)
- {
- if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 601)
- {
- if(firedcannon[playerid] == 0)
- {
- firedcannon[playerid] = 1;
- SetTimerEx("cannonfired", 2500, false,"i",playerid);
- new
- Float:x8, Float:y8, Float:z8,
- Float:x2, Float:y2, Float:z2,
- Float:x7, Float:y7, Float:z7,
- Float:object_x1, Float:object_y1, Float:object_z1;
- GetPlayerPos(playerid,x7,y7,z7);
- GetPlayerCameraPos(playerid, x8,y8,z8);
- GetPlayerCameraFrontVector(playerid, x2,y2,z2);
- new sa2 = randomEx(-1, 1)*((CannonRange[playerid]-5)/10);
- new sa3 = randomEx(-1, 1)*((CannonRange[playerid]-5)/10);
- new Float:speedt2 = GetPlayerVSpeed(playerid);
- //dispersion by speed
- new speedt;
- if(speedt2 < 5.0)
- {
- speedt = 1;
- }
- else if(speedt2 > 5.0 && speedt2 < 40.0)
- {
- speedt = 2;
- }
- else if(speedt2 > 40.0)
- {
- speedt = 3;
- }
- //
- object_x1 = x8 + floatmul(x2, CannonRange[playerid]);
- object_y1 = y8 + floatmul(y2, CannonRange[playerid]);
- MapAndreas_FindZ_For2DCoord(object_x1, object_y1, object_z1);
- if(z8+floatmul(z2, CannonRange[playerid]) <= object_z1)
- {
- CreateExplosion(object_x1+sa2*speedt, object_y1+sa3*speedt, object_z1, 12, 3.5);
- foreach(new i : Player)
- {
- if(GetPlayerTeam(i) != GetPlayerTeam(playerid) || group[playerid][gid] != group[i][gid])
- {
- if(i != playerid)
- {
- if(IsPlayerInRangeOfPoint(i,3.5,object_x1+sa2*speedt, object_y1+sa3*speedt, object_z1) && GetPlayerTeam(playerid) != (GetPlayerTeam(i)))
- {
- HPDeathCallTimer[i] = SetTimerEx("DeathCall",300,false,"iifi",i, playerid, 5.0, 51);
- }
- }
- }
- }
- }
- else if(z8+floatmul(z2, CannonRange[playerid]) > object_z1)
- {
- CreateExplosion(object_x1+sa2*speedt, object_y1+sa3*speedt, z8+floatmul(z2, CannonRange[playerid]), 12, 5.0);
- foreach(new i : Player)
- {
- if(i != playerid && GetPlayerTeam(i) != GetPlayerTeam(playerid) || group[playerid][gid] != group[i][gid])
- {
- if(IsPlayerInRangeOfPoint(i,5.0,object_x1+sa2*speedt, object_y1+sa3*speedt, z8+floatmul(z2, CannonRange[playerid])) && GetPlayerTeam(playerid) != (GetPlayerTeam(i)))
- {
- HPDeathCallTimer[i] = SetTimerEx("DeathCall",300,false,"iifi",i, playerid, 5.0, 51);
- }
- }
- }
- }
- }
- }
- }
- return 1;
- }
- forward DeathCall(playerid,killerid,Float:HP,reason);
- public DeathCall(playerid,killerid,Float:HP,reason)
- {
- new Float:hitp;
- GetPlayerHealth(playerid, hitp);
- if((hitp - HP) <= 0.0)
- {
- return CallLocalFunction("OnPlayerDeath", "iii", playerid, killerid, reason);
- }
- return 1;
- }
- forward cannonfired(playerid);
- public cannonfired(playerid)
- {
- firedcannon[playerid] = 0;
- return 1;
- }
Add Comment
Please, Sign In to add comment