Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- new Firehold[MAX_PLAYERS];
- stock Float:GetDistanceBetweenPoints(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ)
- {
- new Float:Distance;
- Distance = floatabs(floatsub(X, PointX)) + floatabs(floatsub(Y, PointY)) + floatabs(floatsub(Z, PointZ));
- return Distance;
- }
- stock GetNearestVehicle(playerid, Float:Distance = 1000.0)
- {
- Distance = floatabs(Distance);
- if(Distance == 0.0) Distance = 1000.0;
- new Float:X[2], Float:Y[2], Float:Z[2];
- new Float:NearestPos = Distance;
- new NearestVehicle = INVALID_VEHICLE_ID;
- GetPlayerPos(playerid, X[0], Y[0], Z[0]);
- for(new i; i<MAX_VEHICLES; i++)
- {
- if(!IsVehicleStreamedIn(i, playerid) || i == GetPlayerVehicleID(playerid)) continue;
- GetVehiclePos(i, X[1], Y[1], Z[1]);
- if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
- }
- if(NearestPos < Distance) return NearestVehicle;
- return INVALID_VEHICLE_ID;
- }
- forward ResprayTimer(playerid,vehicleid);
- public OnPlayerKeyStateChange(playerid,newkeys,oldkeys){
- if(newkeys & KEY_FIRE &&(GetPlayerWeapon(playerid) == 41 && !IsPlayerInAnyVehicle(playerid))){
- new nearveh=GetNearestVehicle(playerid,5);
- if(IsPlayerFacingVehicle(playerid,nearveh)){
- SetTimerEx("ResprayTimer",3000,0,"ii",playerid,GetNearestVehicle(playerid,5));
- Firehold[playerid] = 1;
- }
- }
- if(oldkeys & KEY_FIRE && (Firehold[playerid] == 1)) Firehold[playerid] = 0;
- return 1;
- }
- public ResprayTimer(playerid,vehicleid){
- if(GetPlayerWeapon(playerid) == 41 && GetNearestVehicle(playerid,8) == vehicleid && Firehold[playerid] == 1){
- if(IsPlayerFacingVehicle(playerid,vehicleid)){
- ChangeVehicleColor(GetNearestVehicle(playerid,8),random(127),random(127));
- RepairVehicle(GetNearestVehicle(playerid,8));
- GameTextForPlayer(playerid,"~g~Respray sucessfull",3000,4);
- }
- }
- return 1;
- }
- public OnPlayerCommandText(playerid,cmdtext[]){
- if(strcmp("/spray",cmdtext,true) == 0){
- GivePlayerWeapon(playerid,41,50000);
- return 1;
- }
- return 0;
- }
- stock IsPlayerFacingVehicle(playerid,vehicleid)
- {
- new Float:pX,Float:pY,Float:pZ,Float:X,Float:Y,Float:Z,Float:ang;
- if(!IsPlayerConnected(playerid)) return 0;
- GetVehiclePos(vehicleid, X, Y, Z);
- GetPlayerPos(playerid, pX, pY, pZ);
- if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
- else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
- else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
- if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
- else ang = (floatabs(ang) - 180.0);
- new Float:russia;
- GetPlayerFacingAngle(playerid,russia);
- if(ang-russia<-130 || ang-russia>130) return 0;
- else return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement