Help CMD repair
#1

Код:
CMD:ripara(playerid, params[])
{
	new id=GetPlayerVehicleID(playerid);
    if(PlayerToPoint(6.0, playerid, 992.987121,-1659.088134,14.559866) || PlayerToPoint(6.0, playerid, 992.834289,-1650.768920,14.559599) && IsPlayerInAnyVehicle(playerid))
	{
	    new Float:health;
	    new str[128];
	    new Float:vh = GetVehicleHealth(id,health);
	    new vhealth = floatround(vh, floatround_round);
		new totale = 999-vhealth;
		RepairVehicle(id);
		format(str,sizeof(str),"Hai riparato il tuo veicolo per %i", totale);
		SCM(playerid, INFO, str);
		GivePlayerMoney(playerid, -totale);
		SetVehicleHealth(id, 999.0);
		VeicoloInfo[(id)][vVita] = 999.0;
		Salvaveh((id));
		Salvataggio(playerid);
	}
	return 1;
}
Why pay 998 ALWAYS? Whatever the life of the vehicle?
Reply
#2

This is not how you use GetVehicleHealth. Have a look here: https://sampwiki.blast.hk/wiki/GetVehicleHealth
The function itself returns 1 if success and 0 if failure. You are subtracting 1 from 999.
Reply
#3

What function I must use?
Reply
#4

* sigh *
Reply
#5

Quote:
Originally Posted by RyderX
Посмотреть сообщение
PHP код:
CMD:repair(playerid,params[])
{
    new 
Float:health;
    new 
veh GetPlayerVehicleID(playerid);
    
GetVehicleHealth(vehhealth);
    if(
health 500) return SendClientMessage(playerid,-1"Vehicle doesn't need repairing!");
    
SetVehicleHealth(veh1000);
    
SendClientMessage(playerid,-1"Vehicle repaired!");

Code is unfinished, instead of this one try to solve his problem!
Reply
#6

PHP код:
CMD:ripara(playeridparams[])
{
    new 
id=GetPlayerVehicleID(playerid);
    if(
PlayerToPoint(6.0playerid992.987121,-1659.088134,14.559866) || PlayerToPoint(6.0playerid992.834289,-1650.768920,14.559599) && IsPlayerInAnyVehicle(playerid))
    {
        new 
Float:health;
        new 
str[128];
        new 
Float:vh GetVehicleHealth(id,health); // pasta pizza bambino, you don't need here to create a new Float:vh as you've already retrieved the vehicle's health on the variable health.
        
new vhealth floatround(vhfloatround_round); // pasta pizza bambino, you need to change vh for health again here
        
new totale 999-vhealth;
        
RepairVehicle(id);
        
format(str,sizeof(str),"Hai riparato il tuo veicolo per %i"totale);
        
SCM(playeridINFOstr);
        
GivePlayerMoney(playerid, -totale);
        
SetVehicleHealth(id999.0);
        
VeicoloInfo[(id)][vVita] = 999.0;
        
Salvaveh((id));
        
Salvataggio(playerid);
    }
    return 
1;

Cappicci? Capecci? Capitzie? Pepperoni?

So, instead of the lines I pointed out up there, they should look like this:

Код:
        GetVehicleHealth(id,health);
        new vhealth = floatround(health);
Reply
#7

Ok but I want to subtract the current life of the vehicle in 1000. How do I?
Reply
#8

Quote:
Originally Posted by AlexPalermitano97
Посмотреть сообщение
Ok but I want to show the current life of the vehicle in 1000. How do I?
How do it, indeed.

If you set the vehicle's health to 999, it'll show 999.

If you don't want to set the vehicle health to 999, remove this line:

Код:
      SetVehicleHealth(id, 999.0);
As you have repaired the vehicle beforehand.

EDIT: As you edited your comment, I don't know if you meant to say this, if this is not the answer you were looking for, let me know

EDIT 2:

Also, adding to my previous post:

I don't know how to explain myself regarding this, but you have to "close" the conditions so the program does not get confused:
PHP код:
 if(PlayerToPoint(6.0playerid992.987121,-1659.088134,14.559866) || PlayerToPoint(6.0playerid992.834289,-1650.768920,14.559599) && IsPlayerInAnyVehicle(playerid)) 
may mean PlayerToPoint(2) && IsPlayerInAnyVehicle(playerid) or PlayerToPoint(1)

I don't know if i'm clear, anyway close them to avoid confusion, like this:

PHP код:
 if( ( PlayerToPoint(6.0playerid992.987121,-1659.088134,14.559866) || PlayerToPoint(6.0playerid992.834289,-1650.768920,14.559599) ) && IsPlayerInAnyVehicle(playerid)) 
Reply
#9

Ah,thank'sss
Reply
#10

I have solved,thank you very much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)