autorepair does not work
#8

Quote:
Originally Posted by CyberGhost
Посмотреть сообщение
With enable/disable

Edited ur code:
pawn Код:
//Top of script
new AutoFix[MAX_PLAYERS];

//OnGameModeInit
SetTimer("AutoRepair", 1000, 1);

//OnPlayerConnect
AutoFix[playerid] = 0;

//Command
COMMAND:autorepair(playerid, params[])
{
    if(AutoFix[playerid] == 0)
    {
        AutoFix[playerid] = 1;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned on autorepair.");
    }
    else
    {
        AutoFix[playerid] = 0;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned off autorepair.");
    }
    return 1;
}

//Anywhere in your script but not in other Callbacks :P
forward AutoRepair();
public AutoRepair()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new Float:VH;
        GetVehicleHealth(GetPlayerVehicleID(i), VH);
        if(AutoFix[i] == 1)
        {
            if(IsPlayerInAnyVehicle(i) && VH < 1000)
            {
                RepairVehicle(GetPlayerVehicleID(i));
            }
        }
    }
    return 1;
}
My code:
pawn Код:
new AutoFix[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    AutoFix[playerid] = 0;
    return 1;
}

COMMAND:autorepair(playerid, params[])
{
    if(AutoFix[playerid] == 0)
    {
        AutoFix[playerid] = 1;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned on autorepair.");
    }
    else
    {
        AutoFix[playerid] = 0;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned off autorepair.");
    }
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(AutoFix[playerid] == 1 && IsPlayerInAnyVehicle(playerid))
    {
        RepairVehicle(GetPlayerVehicleID(playerid));
    }
    return 1;
}
thank you alot i changed your callback a bit and now it works
Reply


Messages In This Thread
autorepair does not work - by Madsen - 31.05.2011, 14:24
Re: autorepair does not work - by xir - 31.05.2011, 14:41
Re: autorepair does not work - by Madsen - 31.05.2011, 16:47
Re: autorepair does not work - by sleepysnowflake - 31.05.2011, 16:59
Re: autorepair does not work - by Sasino97 - 31.05.2011, 17:25
Re: autorepair does not work - by Markx - 31.05.2011, 17:26
Re: autorepair does not work - by Laronic - 31.05.2011, 17:36
Re: autorepair does not work - by Madsen - 03.06.2011, 12:35

Forum Jump:


Users browsing this thread: 1 Guest(s)