SetVehicleHealth on empty vehicle
#1

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?
Reply
#2

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

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...
Reply
#4

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;
}
Reply
#5

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
Reply
#6

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.
Reply
#7

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?
Reply
#8

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); 
Reply
#9

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++) 
Reply
#10

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

rep+ for the two
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)