SA-MP Forums Archive
SetVehicleHealth on empty vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetVehicleHealth on empty vehicle (/showthread.php?tid=629311)



SetVehicleHealth on empty vehicle - Cheleber_Pausini - 24.02.2017

It's not possible to repair and setvehiclehealth with vehicle empty (no players inside the vehicle)?

I was trying to do a repair command outside of the vehicle but it dont repair the vehicle outside, just inside or if a player is inside...

sry my bad english (:

EDIT@
I saiw this
https://sampwiki.blast.hk/wiki/OnUnoccupiedVehicleUpdate

but how can i use it in the repair vehicle command?


Re: SetVehicleHealth on empty vehicle - GoldenLion - 24.02.2017

It is possible.
Код:
CMD:repair(playerid, params[])
    return RepairVehicle(strval(params));



Re: SetVehicleHealth on empty vehicle - Cheleber_Pausini - 24.02.2017

Ok thank you, but in my CMD i dont want the player to write the id of the vehicle, i get the id vehicle near to the player...


Re: SetVehicleHealth on empty vehicle - GoldenLion - 24.02.2017

Like this?
Код:
CMD:repair(playerid, params[])
{
	new Float:x, Float:y, Float:z;
	
	for (new i = 1, j = GetVehiclePoolSize(); i <= j) if (IsValidVehicle(i) && GetVehicleVirtualWorld(i) == GetPlayerVirtualWorld(playerid))
	{
		GetVehiclePos(i, x, y, z);
		
		if (IsPlayerInRangeOfPoint(5.0, x, y, z))
		{
			RepairVehicle(i);
			return 1;
		}
	}
	SendClientMessage(playerid, -1, "You are not in range of any vehicle.");
	return 1;
}



Re: SetVehicleHealth on empty vehicle - Cheleber_Pausini - 24.02.2017

I think you dont understand...
i already have the command, and is returning the correct VEHICLE ID, is just not repairing if the vehicle is not occupped


Re: SetVehicleHealth on empty vehicle - Private200 - 24.02.2017

Just use a function that can get the ID of the vehicle nearby the player;

PHP код:
#define VEHICLE_DISTANCE 3
stock GetVehicleNearPlayer(playerid)
{
     new 
Float:xFloat:yFloat:z;
     for(new 
0MAX_VEHICLESi++)
     {
          if(
IsValidVehicle(i))
          {
               
GetVehiclePos(ixyz);
               if(
IsPlayerInRangeOfPoint(playeridVEHICLE_DISTANCExyz);
               {
                    return 
i;
               }     
          }
     }
     return 
INVALID_VEHICLE_ID;

The command up there would be something like:

PHP код:
CMD:repair(playeridparams[])
    return 
RepairVehicle(GetVehicleNearPlayer(playerid)); 
EDIT: Man before me got it before. There's no way the vehicle will not get fixed. Either you are not getting an ID returned from our function as the vehicle is desynced (moved from the main position) or you are getting an incorrect ID. Make sure you debug the variable you are using for the vehicle ID so you can see if it is really the one the vehicle you are trying to repair has.


Re: SetVehicleHealth on empty vehicle - GoldenLion - 24.02.2017

Quote:
Originally Posted by Cheleber_Pausini
Посмотреть сообщение
I think you dont understand...
i already have the command, and is returning the correct VEHICLE ID, is just not repairing if the vehicle is not occupped
Then it's probably not the correct vehicle ID, because RepairVehicle works on unoccupied vehicles as well.

EDIT: What about just showing the whole command?


Re: SetVehicleHealth on empty vehicle - Cheleber_Pausini - 24.02.2017

Ok is in portuguese but i could show you>

PHP код:
new Float:vidaFloatdistanceFloatx,  Floaty,  FloatzFloata;
  new 
carro;
  if(!
IsPlayerInAnyVehicle(playerid))
  {
     
carro GetClosestVehicleFromPlayer(playerid);
     
GetPlayerPos(playeridxyz);
     
distance GetVehicleDistanceFromPoint(carroxyz);
     if(
distance 4) return SendClientMessage(playerid, -1"Deves estar perto de um veнculo!");
     
GetVehicleHealth(carrovida);
     if(
vida >= 1000) return SendClientMessage(playerid, -1"O veнculo nгo precisa de ser reparado.");
     
SetTimerEx("RepararCarro"100000"ii"playeridcarro);
     
TimerSomRepararCarro[playerid] = SetTimerEx("SomRepararCarro"25001"i"playerid);
     
GameTextForPlayer(playerid,"~w~Reparando...",10000,3);
     
TogglePlayerControllable(playerid,0);
     
SetPlayerFacingAngle(playerida+90);
     
ApplyAnimation(playerid,"CAR","Fixn_Car_Loop",5.0,0,1,1,0,10000,1);
     for(new 
1MAX_PLAYERS i++)
     {
        
distance GetPlayerDistanceFromPoint(ixyz);
        if(
distance 15)
        {
           
PlayerPlaySound(i32000000);
        }
     }
     return 
1;
  }
  return 
1;

And the functions

PHP код:
public SomRepararCarro(playerid)
{
    new 
FloatxFloatyFloatz;
    
GetPlayerPos(playeridxyz);
    for(new 
1MAX_PLAYERS i++)
    {
        new 
Float:distance GetPlayerDistanceFromPoint(ixyz);
        if(
distance 15)
        {
           
PlayerPlaySound(i32000000);
        }
    }
    return 
1;

PHP код:
public RepararCarro(playeridcarro)
{
    
KillTimer(TimerSomRepararCarro[playerid]);
    
SetVehicleHealth(carro,1000);
    
RepairVehicle(carro);
    
TogglePlayerControllable(playerid,1);
    
SendClientMessage(playerid, -1,"Carro reparado com sucesso!");
    new 
FloatxFloatyFloatz;
    
GetPlayerPos(playeridxyz);
    for(new 
1MAX_PLAYERS i++)
    {
        new 
Float:distance GetPlayerDistanceFromPoint(ixyz);
        if(
distance 15)
        {
           
PlayerPlaySound(i1133000);
        }
    }
    return 
1;

EDIT
I will try this to see if i get the correct id
PHP код:
new string[128];
     
format(stringsizeof(string), "%d"carro);
     
SendClientMessage(playerid, -1string); 



Re: SetVehicleHealth on empty vehicle - Private200 - 24.02.2017

Player loop must start from ID 0 though, not from 1:

PHP код:
for(new 1MAX_PLAYERS i++) 
must be
PHP код:
for(new 0MAX_PLAYERS i++) 



Re: SetVehicleHealth on empty vehicle - Cheleber_Pausini - 24.02.2017

yes is working know! I was getting the wrong id, thank you very much for the help (:

rep+ for the two