autorepair does not work
#1

okay this is what i have made so far.
pawn Код:
new autorepair[MAX_PLAYERS];
forward AutoR();

public AutoR()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new Float:VHealth, vehicleid = GetPlayerVehicleID(i);
        GetVehicleHealth(vehicleid,VHealth);
        if(autorepair[i] == 1)
        {
            if (IsPlayerInAnyVehicle(i))
            {
                if(VHealth < 999)
                {
                    RepairVehicle(i);
                }
            }
        }
    }
    return 1;
}

//on game mode in it
SetTimer("AutoR", 1000, 1);

//onplayerconnect
autorepair[playerid] = 0;

// the command
CMD:autorepair(playerid, params[])
    {
        if(autorepair[playerid] == 1)
        {
            autorepair[playerid] = 0;
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned off autorepair.");
        }
        else
        if(autorepair[playerid] == 0)
        {
            autorepair[playerid] = 1;
            SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned on autorepair.");
        }
        return 1;
    }
Reply
#2

pawn Код:
CMD:autorepair(playerid, params[])
{
    if(autorepair[playerid] == 0)
    {
        autorepair[playerid] = 1;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned on autorepair.");

    }
    if(autorepair[playerid] == 1)
    {
        autorepair[playerid] = 0;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned off autorepair.");
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by xir
Посмотреть сообщение
pawn Код:
CMD:autorepair(playerid, params[])
{
    if(autorepair[playerid] == 0)
    {
        autorepair[playerid] = 1;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned on autorepair.");

    }
    if(autorepair[playerid] == 1)
    {
        autorepair[playerid] = 0;
        SendClientMessage(playerid, COLOR_GREEN, "( ! ) You turned off autorepair.");
    }
    return 1;
}
if you do like that it wont work at all. It is not because of the command it has something with the public place to do.
Reply
#4

pawn Код:
forward Repair(playerid);
public Repair(playerid)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
        new Float:health;
        new vehicleid = GetPlayerVehicleID(playerid);
        GetVehicleHealth(vehicleid, health);
        if (health <= 999)
        {
            RepairVehicle(vehicleid);
        }
    }
}
Far more simple ?
NOTE: this will not be enabled or disabled by a command. It will fix all the time.
Reply
#5

Isn't this more simple ?:

pawn Код:
public OnPlayerUpdate(playerid)
{
  if(IsPlayerInAnyVehicle(playerid)) RepairVehicle(GetPlayerVehicleID(playerid));
  return 1;
}
This will make all the cars undestructible
Reply
#6

Quote:
Originally Posted by [GF]Sasino97
Посмотреть сообщение
Isn't this more simple ?:

pawn Код:
public OnPlayerUpdate(playerid)
{
  if(IsPlayerInAnyVehicle(playerid)) RepairVehicle(GetPlayerVehicleID(playerid));
  return 1;
}
This will make all the cars undestructible
Just what i was going to post, lol.
Reply
#7

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;
}
Reply
#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


Forum Jump:


Users browsing this thread: 3 Guest(s)