SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/03/2020, 05:24 PM   #1
FineMeX
Little Clucker
 
Join Date: Jun 2016
Posts: 6
Reputation: 0
Question If VehicleHealth is max

Hey guys! I was making some simple commands to repair my car, it look like this.

Code:
CMD:fix(playerid, params[])
{
	new Float:health;
	new vehicleid = GetPlayerVehicleID(playerid);
	health = GetVehicleHealth(vehicleid, health);
	
	if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000FC, "Error you are not in a vehicle!");
	if(health == 1000)return SendClientMessage(playerid, 0xFF0000FC, "The vehicle is not damaged!");
	RepairVehicle(GetPlayerVehicleID(playerid));
	SendClientMessage(playerid, 0xBFDF, "Vehicle has been repaired!");
	return 1;
}
The thing is that I wanna do is that if my vehicle has max health and I try to repair it using /fix it will say that "The vehicle is not damaged" but it is not working and I have no errors.

Any help is welcome, thank you.
FineMeX is offline   Reply With Quote
Old 26/03/2020, 05:28 PM   #2
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,241
Reputation: 160
Default Re: If VehicleHealth is max

Code:
CMD:fix(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if (vehicleid == 0) return SendClientMessage(playerid, 0xFF0000FC, "Error you are not in a vehicle!");
    new Float:health;
    GetVehicleHealth(vehicleid, health);
    if (health == 1000.0) return SendClientMessage(playerid, 0xFF0000FC, "The vehicle is not damaged!");
    RepairVehicle(vehicleid);
    SendClientMessage(playerid, 0xBFDF, "Vehicle has been repaired!");
    return 1;
}
__________________
beckzy is online now   Reply With Quote
Old 26/03/2020, 05:29 PM   #3
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,118
Reputation: 175
Default Re: If VehicleHealth is max

pawn Code:
health = GetVehicleHealth(vehicleid, health);
Health is passed by reference and then you re-assign a success value (what `GetVehicleHealth` returned) so the value of `health` is 1.0

Change to:
pawn Code:
GetVehicleHealth(vehicleid, health);
Health is returned with .0 so checking
pawn Code:
if (health == 1000.0)
can work but when working with floating-point numbers, avoid checking directly.
__________________
Calisthenics is online now   Reply With Quote
Old 26/03/2020, 05:33 PM   #4
FineMeX
Little Clucker
 
Join Date: Jun 2016
Posts: 6
Reputation: 0
Default Re: If VehicleHealth is max

Thanks for the fast response, however I fixed it using this code

Code:
CMD:fix(playerid, params[])
{
	CMD:fix(playerid, params[])
{
	new Float:healthe;
	new veh = GetPlayerVehicleID(playerid);
	GetVehicleHealth(veh, healthe);
	
	if (!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFF0000FC, "Error you are not in a vehicle!");
	if(healthe == 1000.0)return SendClientMessage(playerid, 0xFF0000FC, "The vehicle is not damaged!");
	SetVehicleHealth(veh, 1000.0);
	SendClientMessage(playerid, 0xBFDF, "Vehicle has been repaired!");
	return 1;
}

}

Again thanks so much for the help!
FineMeX is offline   Reply With Quote
Old 26/03/2020, 05:42 PM   #5
l0gic
Big Clucker
 
Join Date: Aug 2019
Posts: 103
Reputation: 16
Default Re: If VehicleHealth is max

do you even understand what are you doing?
this is wrong
health = GetVehicleHealth(vehicleid, health);
float is passed by reference
GetVehicleHealth(vehicleid, health);
__________________
Coding experience with: PAWN, Java, Python, Javascript, PHP and SQL for about 6 years.
l0gic is offline   Reply With Quote
Old 26/03/2020, 05:46 PM   #6
FineMeX
Little Clucker
 
Join Date: Jun 2016
Posts: 6
Reputation: 0
Default Re: If VehicleHealth is max

Sorry @l0gic, I am just learning, not so good at this.
FineMeX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VehicleHealth HELPPP yaron0600 Scripting Help 6 29/11/2013 05:35 PM
[Ajuda] Seta VehicleHealth à 1000 após ser guinchado EditPawn Português/Portuguese 10 08/12/2012 04:28 PM
VehicleHealth=PlayerHealth Gooday Scripting Help 3 03/04/2012 09:35 PM
Player name is not saving properly + vehiclehealth FujiNNN Help Archive 23 25/10/2010 03:51 PM
Vehiclehealth Goobiiify Help Archive 3 01/12/2009 12:13 AM


All times are GMT. The time now is 08:48 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.