Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <streamer>
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_FIRE)
- {
- if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- new Float:pos[6], Float:m_pos[6], Float:v_pos[7], vehicleid = GetPlayerVehicleID(playerid), Float:distance = 120.0, Float:speed = distance + 30.0;
- GetVehiclePos(vehicleid, v_pos[0], v_pos[1], v_pos[2]);
- GetVehicleRotation(vehicleid, v_pos[3], v_pos[4], v_pos[5]);
- GetVehicleZAngle(vehicleid, v_pos[6]);
- for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
- {
- if(IsPlayerConnected(i))
- {
- if(i == playerid) continue;
- new Float:vel = GetVehicleSpeed(vehicleid);
- if(IsPlayerInRangeOfPoint(i, distance, v_pos[0], v_pos[1], v_pos[2]) && vel <= 5.0)
- {
- new Float:tmpx, Float:tmpy, Float:tmpz, Float:tmpang;
- GetPlayerPos(i, tmpx, tmpy, tmpz);
- tmpang = (90 - atan2(tmpy - v_pos[1], tmpx - v_pos[0]) );
- if(tmpang < 0) tmpang = 360.0 + tmpang;
- tmpang = 360.0 - tmpang;
- if(floatabs(tmpang - v_pos[6]) < 5.0)
- {
- distance = GetPlayerDistanceFromPoint(i, v_pos[0], v_pos[1], v_pos[2]);
- }
- }
- }
- }
- conversion(v_pos[0], v_pos[1], v_pos[2], v_pos[3], v_pos[4], v_pos[5], 0.0, 3.5, -0.4, 0.0, 0.0, 0.0, pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
- conversion(pos[0], pos[1], pos[2], pos[3], pos[4], pos[5], 0.0, distance, 0.2, 0.0, 0.0, 0.0, m_pos[0], m_pos[1], m_pos[2], m_pos[3], m_pos[4], m_pos[5]);
- new id = CreateDynamicObject(345, pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
- new areaid = CreateDynamicSphere(0.0, 0.0, 0.0, 5.5);
- AttachDynamicAreaToObject(areaid, id);
- new ob_info[2]; ob_info[0] = true; ob_info[1] = areaid;
- new area_info[3]; area_info[0] = true; area_info[1] = id; area_info[2] = playerid;
- Streamer_SetArrayData(STREAMER_TYPE_OBJECT, id, E_STREAMER_EXTRA_ID, ob_info, 2);
- Streamer_SetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, area_info, 3);
- MoveDynamicObject(id, m_pos[0], m_pos[1], m_pos[2], speed);
- Streamer_Update(playerid);
- return 1;
- }}
- return true;
- }
- public OnDynamicObjectMoved(objectid)
- {
- new ob_info[2];
- Streamer_GetArrayData(STREAMER_TYPE_OBJECT, objectid, E_STREAMER_EXTRA_ID, ob_info, 2);
- if(ob_info[0])
- {
- DestroyDynamicArea(ob_info[1]);
- new Float:pos[3];
- GetDynamicObjectPos(objectid, pos[0], pos[1], pos[2]);
- SHOOTER_CreateExplosion(pos[0], pos[1], pos[2], 0, 15.0);
- DestroyDynamicObject(objectid);
- }
- return 1;
- }
- forward Float:GetVehicleSpeed(vehicleid);
- public Float:GetVehicleSpeed(vehicleid)
- {
- new Float:vx, Float:vy, Float:vz;
- GetVehicleVelocity(vehicleid, vx, vy, vz);
- new Float:vel = floatmul(floatsqroot(floatadd(floatadd(floatpower(vx, 2), floatpower(vy, 2)), floatpower(vz, 2))), 181.5);
- return vel;
- }
- stock GetVehicleRotation(vehicleid,&Float:rx,&Float:ry,&Float:rz)
- {
- new Float:qw,Float:qx,Float:qy,Float:qz;
- GetVehicleRotationQuat(vehicleid,qw,qx,qy,qz);
- rx = asin(2*qy*qz-2*qx*qw);
- ry = -atan2(qx*qz+qy*qw,0.5-qx*qx-qy*qy);
- rz = -atan2(qx*qy+qz*qw,0.5-qx*qx-qz*qz);
- }
- //-------------------------------------------------- STYLOCK --------------------------------------------------
- conversion(Float:or_pos_x, Float:or_pos_y, Float:or_pos_z, Float:or_rot_x, Float:or_rot_y, Float:or_rot_z, Float:off_x, Float:off_y, Float:off_z, Float:rot_x, Float:rot_y, Float:rot_z, &Float:X, &Float:Y, &Float:Z, &Float:RX, &Float:RY, &Float:RZ) // By Stylock - http://forum.sa-mp.com/member.php?u=114165
- {
- static
- Float:sin[3],
- Float:cos[3],
- Float:pos[3],
- Float:rot[3];
- pos[0] = or_pos_x;
- pos[1] = or_pos_y;
- pos[2] = or_pos_z;
- rot[0] = or_rot_x;
- rot[1] = or_rot_y;
- rot[2] = or_rot_z;
- EDIT_FloatEulerFix(rot[0], rot[1], rot[2]);
- cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
- pos[0] = pos[0] + off_x * cos[1] * cos[2] - off_x * sin[0] * sin[1] * sin[2] - off_y * cos[0] * sin[2] + off_z * sin[1] * cos[2] + off_z * sin[0] * cos[1] * sin[2];
- pos[1] = pos[1] + off_x * cos[1] * sin[2] + off_x * sin[0] * sin[1] * cos[2] + off_y * cos[0] * cos[2] + off_z * sin[1] * sin[2] - off_z * sin[0] * cos[1] * cos[2];
- pos[2] = pos[2] - off_x * cos[0] * sin[1] + off_y * sin[0] + off_z * cos[0] * cos[1];
- rot[0] = asin(cos[0] * cos[1]); rot[1] = atan2(sin[0], cos[0] * sin[1]) + rot_z; rot[2] = atan2(cos[1] * cos[2] * sin[0] - sin[1] * sin[2], cos[2] * sin[1] - cos[1] * sin[0] * -sin[2]);
- cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
- rot[0] = asin(cos[0] * sin[1]); rot[1] = atan2(cos[0] * cos[1], sin[0]); rot[2] = atan2(cos[2] * sin[0] * sin[1] - cos[1] * sin[2], cos[1] * cos[2] + sin[0] * sin[1] * sin[2]);
- cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
- rot[0] = atan2(sin[0], cos[0] * cos[1]) + rot_x; rot[1] = asin(cos[0] * sin[1]); rot[2] = atan2(cos[2] * sin[0] * sin[1] + cos[1] * sin[2], cos[1] * cos[2] - sin[0] * sin[1] * sin[2]);
- cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
- rot[0] = asin(cos[1] * sin[0]); rot[1] = atan2(sin[1], cos[0] * cos[1]) + rot_y; rot[2] = atan2(cos[0] * sin[2] - cos[2] * sin[0] * sin[1], cos[0] * cos[2] + sin[0] * sin[1] * sin[2]);
- X = pos[0];
- Y = pos[1];
- Z = pos[2];
- RX = rot[0];
- RY = rot[1];
- RZ = rot[2];
- }
- EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
- {
- EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
- if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
- && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
- {
- rot_y = 0.0000002;
- }
- return 1;
- }
- EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
- {
- EDIT_FloatRemainder(rot_x, 360.0);
- EDIT_FloatRemainder(rot_y, 360.0);
- EDIT_FloatRemainder(rot_z, 360.0);
- return 1;
- }
- SHOOTER_CreateExplosion(Float:x, Float:y, Float:z, type, Float:radius)
- {
- for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
- {
- if(IsPlayerConnected(i))
- {
- CreateExplosionForPlayer(i, x, y, z, type, radius);
- }
- }
- return 1;
- }
- EDIT_FloatRemainder(&Float:remainder, Float:value)
- {
- if(remainder >= value)
- {
- while(remainder >= value)
- {
- remainder = remainder - value;
- }
- }
- else if(remainder < 0.0)
- {
- while(remainder < 0.0)
- {
- remainder = remainder + value;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment