Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Vectoral>
- #include <streamer>
- #include <MapAndreas>
- #include <YSI\y_hooks>
- #define Blanco 0xFFFFFFFF
- //==============================================================================
- // Key State
- //==============================================================================
- #define RELEASED(%0) \
- (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define HOLDING(%0) \
- ((newkeys & (%0)) == (%0))
- new VectorBombas;
- hook OnFilterScriptInit()
- {
- VectorBombas = cvector_g();
- }
- hook OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
- {
- if(PRESSED(KEY_YES) && GetPlayerWeapon(playerid) == 40)
- {
- PlayerPlaySound(playerid, 6400, 0.0, 0.0, 0.0);
- for(new i=0; i<cvector_g_size(VectorBombas); i++)
- {
- new MapaBomba = cvector_g_get(VectorBombas, i);
- if(cmap_get(MapaBomba, "jugador") == playerid)
- {
- KillTimer(cmap_get(MapaBomba, "timer"));
- DetonarBomba(MapaBomba);
- }
- }
- }
- if(PRESSED(KEY_FIRE) && HOLDING(KEY_HANDBRAKE))
- {
- for(new i=0; i<cvector_g_size(VectorBombas); i++)
- {
- new MapaBomba = cvector_g_get(VectorBombas, i);
- new objeto = cmap_get(MapaBomba, "objeto");
- new Float:px, Float:py, Float:pz;
- GetDynamicObjectPos(objeto, px, py, pz);
- if(IsPlayerAimingAt(playerid, px, py, pz, 0.2))
- {
- KillTimer(cmap_get(MapaBomba, "timer"));
- DetonarBomba(MapaBomba);
- }
- }
- }
- }
- hook OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128];
- new tmp[128];
- new idx;
- cmd = strtokex(cmdtext, idx);
- if(strcmp(cmd, "/plantbomb", true) == 0)
- {
- tmp = strtokex(cmdtext, idx);
- if(!strlen(tmp) || !IsNumeric(tmp))
- {
- return SendClientMessage(playerid, Blanco, "USE: /plantbomb [Delay] [Car]");
- }
- new segundos = strval(tmp);
- tmp = strtokex(cmdtext, idx);
- if(!strlen(tmp) || !IsNumeric(tmp))
- {
- return SendClientMessage(playerid, Blanco, "USE: /plantbomb [Delay] [Car]");
- }
- new coche = strval(tmp);
- new Float:px, Float:py, Float:pz;
- GetPlayerPos(playerid, px, py, pz);
- MapAndreas_FindZ_For2DCoord(px, py, pz);
- pz = pz+0.4;
- new MapaBomba = cmap();
- cmap_insert_float(MapaBomba, "posX", px);
- cmap_insert_float(MapaBomba, "posY", py);
- cmap_insert_float(MapaBomba, "posZ", pz);
- cmap_insert(MapaBomba, "objeto", CreateDynamicObject(363, px, py, pz, 0.0, 90.0, 0.0));
- cmap_insert(MapaBomba, "jugador", playerid);
- cvector_g_push_back(VectorBombas, MapaBomba);
- if(coche > 0)
- {
- cmap_insert(MapaBomba, "coche", coche);
- AttachDynamicObjectToVehicle(cmap_get(MapaBomba, "objeto"), coche, 0.0, 0.0, -0.6, 90.0, 0.0, 0.0);
- }
- cmap_insert(MapaBomba, "timer", SetTimerEx("DetonarBomba", segundos*1000, 0, "i", MapaBomba));
- return 1;
- }
- return 0;
- }
- forward DetonarBomba(bombamap);
- public DetonarBomba(bombamap)
- {
- new objeto = cmap_get(bombamap, "objeto");
- new Float:px, Float:py, Float:pz;
- new Float:pxa, Float:pya, Float:pza;
- new coche = cmap_get(bombamap, "coche");
- if(coche > 0)
- {
- GetVehicleVelocity(coche, pxa, pya, pza);
- GetVehiclePos(coche, px, py, pz);
- }
- else
- {
- GetDynamicObjectPos(objeto, px, py, pz);
- }
- CreateExplosion(px+pxa*10, py+pya*10, pz+pza*10, 0, 12.0);
- DestroyDynamicObject(cmap_get(bombamap, "objeto"));
- cvector_g_remove_value(VectorBombas, bombamap);
- for(new i=0; i<cvector_g_size(VectorBombas); i++)
- {
- new MapaBomba = cvector_g_get(VectorBombas, i);
- new objetoa = cmap_get(MapaBomba, "objeto");
- GetDynamicObjectPos(objetoa, pxa, pya, pza);
- if(PointToPoint2D(8.0, px, py, pxa, pya))
- {
- KillTimer(cmap_get(MapaBomba, "timer"));
- SetTimerEx("DetonarBomba", 500, 0, "i", MapaBomba);
- }
- }
- }
- stock IsNumeric(stringer[]) { for (new i = 0, j = strlen(stringer); i < j; i++) if (stringer[i] > '9' || stringer[i] < '0') return 0; return 1; }
- stock strtokex(const stringe[], &index)
- {
- new length = strlen(stringe);
- while ((index < length) && (stringe[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (stringe[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = stringe[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- 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 Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y) {
- new Float:DX, Float:DY;
- new Float:angle;
- DX = floatabs(floatsub(x2,X));
- DY = floatabs(floatsub(y2,Y));
- if (DY == 0.0 || DX == 0.0) {
- if(DY == 0 && DX > 0) angle = 0.0;
- else if(DY == 0 && DX < 0) angle = 180.0;
- else if(DY > 0 && DX == 0) angle = 90.0;
- else if(DY < 0 && DX == 0) angle = 270.0;
- else if(DY == 0 && DX == 0) angle = 0.0;
- }
- else {
- angle = atan(DX/DY);
- if(X > x2 && Y <= y2) angle += 90.0;
- else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
- else if(X < x2 && Y >= y2) angle -= 90.0;
- else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
- }
- return floatadd(angle, 90.0);
- }
- stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance) {
- x += (distance * floatsin(-angle, degrees));
- y += (distance * floatcos(-angle, degrees));
- }
- stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius) {
- new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
- GetPlayerCameraPos(playerid, camera_x, camera_y, camera_z);
- GetPlayerCameraFrontVector(playerid, vector_x, vector_y, vector_z);
- new Float:vertical, Float:horizontal;
- switch (GetPlayerWeapon(playerid)) {
- case 34,35,36: {
- if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z) < radius) return true;
- return false;
- }
- case 30,31: {vertical = 4.0; horizontal = -1.6;}
- case 33: {vertical = 2.7; horizontal = -1.0;}
- default: {vertical = 6.0; horizontal = -2.2;}
- }
- new Float:angle = GetPointAngleToPoint(0, 0, floatsqroot(vector_x*vector_x+vector_y*vector_y), vector_z) - 270.0;
- new Float:resize_x, Float:resize_y, Float:resize_z = floatsin(angle+vertical, degrees);
- GetXYInFrontOfPoint(resize_x, resize_y, GetPointAngleToPoint(0, 0, vector_x, vector_y)+horizontal, floatcos(angle+vertical, degrees));
- if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z) < radius) return true;
- return false;
- }
- stock PointToPoint2D(Float:radi, Float:x, Float:y, Float:x2, Float:y2)
- {
- new Float:distance;
- distance= floatsqroot( floatadd ( floatpower( floatsub ( x2 , x) , 2) , floatpower( floatsub ( y2 , y), 2) ) );
- if (distance < radi)
- {
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement