Auto Car Repair? -
BlackbirdXd - 10.03.2017
I found some FS about that, though of making my own. Somehow I made it but seems it's not working tho. It's not repairing car.
PHP код:
new bool:Autorepair[MAX_PLAYERS];
forward AutoRepair();
CMD:af(playerid)
{
if(Autorepair[playerid])
{
Autorepair[playerid] = false;
SendClientMessage(playerid, COLOR_RED, "Pakistan Drift Zone: Auto Car Repair Disabled.");
}
else
{
Autorepair[playerid] = true;
SendClientMessage(playerid, COLOR_RED, "Pakistan Drift Zone: Auto Car Repair enabled.");
}
return 1;
}
public AutoRepair()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(!Autorepair[i])
{
return 0;
}
new float:gvh; // Get vehicle health
new gvid; // Get vehicle ID
if(IsPlayerInAnyVehicle(i))
{
gvid = GetPlayerVehicleID(i);
GetVehicleHealth(gvid, gvh);
if(gvh < 999)
{
SetVehicleHealth(gvid, 1000);
RepairVehicle(gvid);
}
}
}
}
return 1;
}
Edit:
PHP код:
public OnPlayerConnect(playerid)
{
Autorepair[playerid] = false;
return 1;
}
Re: Auto Car Repair? -
Toroi - 10.03.2017
You could do that, or you could compress all of that in a callback
https://sampwiki.blast.hk/wiki/OnVehicleDamageStatusUpdate
With your actual variables, add a check if the player should get their vehicle repaired, and add
RepairVehicle(GetPlayerVehicleID(playerid)); under
OnVehicleDamageStatusUpdate, although it wont work if the vehicle gets shot, but it will if the player crashes against something.
Re: Auto Car Repair? -
NaS - 10.03.2017
Код:
if(!Autorepair[i])
{
return 0;
}
This will stop the whole callback if AutoRepair isn't allowed for a player.
Replace "return 0" with "continue", this will jump to the next ID if AutoRepair is disabled for a player.
If you set the timer correctly, it should then work as expected.
Troydere's solution is still better, since it will not require a timer. You can also use OnPlayerWeaponShot to restore any health that a vehicle lost by shooting.
PS: You can use GetPlayerVehicleID to determine if a player is in any vehicle (will return 0 if player is not in a vehicle), also RepairVehicle also restores the health, no need to set it seperately.
Re: Auto Car Repair? -
BlackbirdXd - 10.03.2017
@Nas
PHP код:
if(!Autorepair[i])
{
continue;
}
I face this problem before when I was returning Zero here, but same happen again, As if you look up in SS it's just setting vehicle health to 999999 according to loop. Not repairing it tho. Second, Why would I need to add timer since loop isn't enough for this case.
http://imgur.com/a/Z6SWd
@Troy I'll appreciate if you compress all of this under one callback, little bit confused tho by doing myself.
Re: Auto Car Repair? -
TitanX - 10.03.2017
why so much things ?
simply do this,
PHP код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
if(Autorepair[playerid])
{
SetVehicleHealth(vehicleid, 1000);
RepairVehicle(vehicleid);
}
return 1;
}
Re: Auto Car Repair? -
BlackbirdXd - 10.03.2017
Quote:
Originally Posted by TitanX
why so much things ?
simply do this,
PHP код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
if(Autorepair[playerid])
{
SetVehicleHealth(vehicleid, 1000);
RepairVehicle(vehicleid);
}
return 1;
}
|
Wow, lol.
between got any idea why my code only setting vehicle health and not repairing it.
One more question: these mapping lines are pretty much annoying and waste of scrolling time. Is there anyhow I can save them somewhere else than include them in my gamemode? example would be good.
Re: Auto Car Repair? -
TitanX - 10.03.2017
Quote:
Originally Posted by BlackbirdXd
Wow, lol.
between got any idea why my code only setting vehicle health and not repairing it.
One more question: these mapping lines are pretty much annoying and waste of scrolling time. Is there anyhow I can save them somewhere else than include them in my gamemode? example would be good.
|
must be
and what is "mapping lines" ?
Re: Auto Car Repair? -
BlackbirdXd - 10.03.2017
Quote:
Originally Posted by TitanX
must be
and what is "mapping lines" ?
|
What's wrong in this condition, and why you're condition would work instead of this meaning of both condition is same.
PHP код:
CreateDynamicObject(973, 2972.29882812, -990.15380859, 13.38950634, 0.00000000, 0.00000000, 131.00933838);
Spammed into gm.
Re: Auto Car Repair? -
NaS - 10.03.2017
Quote:
Originally Posted by BlackbirdXd
What's wrong in this condition, and why you're condition would work instead of this meaning of both condition is same.
PHP код:
CreateDynamicObject(973, 2972.29882812, -990.15380859, 13.38950634, 0.00000000, 0.00000000, 131.00933838);
Spammed into gm.
|
You can use gvh < 999 as well, it will just repair the vehicle once the health drops below 999, whereas gvh != 1000 repairs the vehicle if it is not 1000 (higher or lower than 1000).
Regarding the mappings, depends what you are using to map.
If it's MTA for example, there are includes or plugins that can load a .map file so you don't need to paste that code into your gm. Good solution, you can edit the map without recompiling the script, etc.
Re: Auto Car Repair? -
Toroi - 10.03.2017
Quote:
Originally Posted by BlackbirdXd
Wow, lol.
between got any idea why my code only setting vehicle health and not repairing it.
One more question: these mapping lines are pretty much annoying and waste of scrolling time. Is there anyhow I can save them somewhere else than include them in my gamemode? example would be good.
|
I use to add my maps to the GM in filterscripts. Apart of saving tons of lines, I can add/delete the maps while inside the game, it's pretty useful.