SA-MP Forums Archive
Help CMD repair - 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: Help CMD repair (/showthread.php?tid=630608)



Help CMD repair - AlexPalermitano97 - 16.03.2017

Код:
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?


Re: Help CMD repair - GoldenLion - 16.03.2017

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.


Re: Help CMD repair - AlexPalermitano97 - 16.03.2017

What function I must use?


Re: Help CMD repair - RyderX - 16.03.2017

* sigh *


Re: Help CMD repair - Bolex_ - 16.03.2017

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!


Re: Help CMD repair - Toroi - 16.03.2017

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);



Re: Help CMD repair - AlexPalermitano97 - 16.03.2017

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


Re: Help CMD repair - Toroi - 16.03.2017

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)) 



Re: Help CMD repair - AlexPalermitano97 - 16.03.2017

Ah,thank'sss


Re: Help CMD repair - AlexPalermitano97 - 16.03.2017

I have solved,thank you very much