Auto Car Repair?
#1

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(playeridCOLOR_RED"Pakistan Drift Zone: Auto Car Repair Disabled.");
    }
    else
    {
        
Autorepair[playerid] = true;
        
SendClientMessage(playeridCOLOR_RED"Pakistan Drift Zone: Auto Car Repair enabled.");
    }
    return 
1;
}
public 
AutoRepair()
{
    for(new 
i=0i<MAX_PLAYERSi++)
    {
        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(gvidgvh);
                if(
gvh 999)
                {
                    
SetVehicleHealth(gvid1000);
                    
RepairVehicle(gvid);
                }
            }
        }
    }
    return 
1;

Edit:
PHP код:
public OnPlayerConnect(playerid)
{
    
Autorepair[playerid] = false;
    return 
1;

Reply
#2

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

Код:
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.
Reply
#4

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

why so much things ?

simply do this,

PHP код:
public OnVehicleDamageStatusUpdate(vehicleidplayerid)
{    
    if(
Autorepair[playerid])
    {
        
SetVehicleHealth(vehicleid1000);
        
RepairVehicle(vehicleid);
    }
    return 
1;

Reply
#6

Quote:
Originally Posted by TitanX
Посмотреть сообщение
why so much things ?

simply do this,

PHP код:
public OnVehicleDamageStatusUpdate(vehicleidplayerid)
{    
    if(
Autorepair[playerid])
    {
        
SetVehicleHealth(vehicleid1000);
        
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.
Reply
#7

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.
PHP код:
if(gvh 999
must be
PHP код:
if(gvh != 1000
and what is "mapping lines" ?
Reply
#8

Quote:
Originally Posted by TitanX
Посмотреть сообщение
PHP код:
if(gvh 999
must be
PHP код:
if(gvh != 1000
and what is "mapping lines" ?
PHP код:
if(gvh 999
What's wrong in this condition, and why you're condition would work instead of this meaning of both condition is same.

PHP код:
CreateDynamicObject(9732972.29882812, -990.1538085913.389506340.000000000.00000000131.00933838); 
Spammed into gm.
Reply
#9

Quote:
Originally Posted by BlackbirdXd
Посмотреть сообщение
PHP код:
if(gvh 999
What's wrong in this condition, and why you're condition would work instead of this meaning of both condition is same.

PHP код:
CreateDynamicObject(9732972.29882812, -990.1538085913.389506340.000000000.00000000131.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.
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)