SA-MP Forums Archive
Vehicle Autofix - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicle Autofix (/showthread.php?tid=54306)



Vehicle Autofix - stieben - 30.10.2008

Hello,

I am trying to make an autofix for vehicles so you don't have to type /fix over and over again. BUT I don't know how to make it. Can anyone help me?

Please?


Re: Vehicle Autofix - Nero_3D - 30.10.2008

You need a timer and an variable


Re: Vehicle Autofix - stieben - 30.10.2008

yes, I already thought so, but how to make it??


Re: Vehicle Autofix - Nero_3D - 30.10.2008

Way 1:
pawn Код:
//OnGameModeInit
SetTimer("Timer", 1000, true);
pawn Код:
new bool:AutoFix[MAX_PLAYERS];
pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
    if(AutoFix[playerid])
    {
        AutoFix[playerid] = false;
        return SendClientMessage(playerid, COLOR, "Autofix stoped");
    }
    else
    {
        if(!IsPlayerInAnyVehicle(i)) return SendClientMessage(playerid, COLOR, "You need to be in a vehicle to start autofix");
        AutoFix[playerid] = true;
        return SendClientMessage(playerid, COLOR, "Autofix started");
    }
    return 1;
}
pawn Код:
forward Timer();
public Timer()
{
    new Float:health, var1;
    for(new i = 0, m = GetMaxPlayers(); i < m; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(AutoFix[i] && IsPlayerInAnyVehicle(i))
        {
            var1 = GetPlayerVehicleID(i);
            GetVehicleHealth(var1 , health);
            if(health < 500) SetVehicleHealth(var1, 1000.0);
        }
    }
}
Way 2:
pawn Код:
new AutoFixTimer[MAX_PLAYERS];
pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
    if(AutoFixTimer[playerid])
    {
        KillTimer(AutoFixTimer[playerid]);
        AutoFixTimer[playerid] = false;
        return SendClientMessage(playerid, COLOR, "Autofix stoped");
    }
    else
    {
        if(!IsPlayerInAnyVehicle(i)) return SendClientMessage(playerid, COLOR, "You need to be in a vehicle to start autofix");
        AutoFixTimer[playerid] = SetTimerEx("AutoFix", 1000, true, "i", playerid);
        return SendClientMessage(playerid, COLOR, "Autofix started");
    }
    return 1;
}
pawn Код:
forward AutoFix(playerid);
public AutoFix(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vid = GetPlayerVehicleID(playerid), Float:health;
        GetVehicleHealth(vid , health);
        if(health < 500) SetVehicleHealth(vid , 1000.0);
    }
}



Re: Vehicle Autofix - kaisersouse - 30.10.2008

You can also just set the vehicle's health to something insanely high like 999999.9. Doesn't require a timer.


Re: Vehicle Autofix - stieben - 30.10.2008

thanks nero!!! It works!


Re: Vehicle Autofix - XtremeTeam - 04.05.2009

Quote:
Originally Posted by ♣ ⓐⓢⓢ
Way 1:
pawn Код:
//OnGameModeInit
SetTimer("Timer", 1000, true);
pawn Код:
new bool:AutoFix[MAX_PLAYERS];
pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
    if(AutoFix[playerid])
    {
        AutoFix[playerid] = false;
        return SendClientMessage(playerid, COLOR, "Autofix stoped");
    }
    else
    {
        if(!IsPlayerInAnyVehicle(i)) return SendClientMessage(playerid, COLOR, "You need to be in a vehicle to start autofix");
        AutoFix[playerid] = true;
        return SendClientMessage(playerid, COLOR, "Autofix started");
    }
    return 1;
}
pawn Код:
forward Timer();
public Timer()
{
    new Float:health, var1;
    for(new i = 0, m = GetMaxPlayers(); i < m; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(AutoFix[i] && IsPlayerInAnyVehicle(i))
        {
            var1 = GetPlayerVehicleID(i);
            GetVehicleHealth(var1 , health);
            if(health < 500) SetVehicleHealth(var1, 1000.0);
        }
    }
}
Way 2:
pawn Код:
new AutoFixTimer[MAX_PLAYERS];
pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
    if(AutoFixTimer[playerid])
    {
        KillTimer(AutoFixTimer[playerid]);
        AutoFixTimer[playerid] = false;
        return SendClientMessage(playerid, COLOR, "Autofix stoped");
    }
    else
    {
        if(!IsPlayerInAnyVehicle(i)) return SendClientMessage(playerid, COLOR, "You need to be in a vehicle to start autofix");
        AutoFixTimer[playerid] = SetTimerEx("AutoFix", 1000, true, "i", playerid);
        return SendClientMessage(playerid, COLOR, "Autofix started");
    }
    return 1;
}
pawn Код:
forward AutoFix(playerid);
public AutoFix(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vid = GetPlayerVehicleID(playerid), Float:health;
        GetVehicleHealth(vid , health);
        if(health < 500) SetVehicleHealth(vid , 1000.0);
    }
}
Help C:\DOCUME~1\PC\ESCRIT~1\SAMPSE~1\SAMP2X~1\GAMEMO~1 \STUNER~1.PWN(543) : error 017: undefined symbol "i"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.



Re: Vehicle Autofix - Bearfist - 04.05.2009

Change that
Код:
if(!IsPlayerInAnyVehicle(i))
to that
Код:
if(!IsPlayerInAnyVehicle(playerid))



Re: Vehicle Autofix - CristianTdj - 07.01.2010

Thanks!


Re: Vehicle Autofix - Calon - 07.01.2010

Quote:
Originally Posted by kaisersouse
You can also just set the vehicle's health to something insanely high like 999999.9. Doesn't require a timer.
^ this.

There's no need to create a timer at all.

pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
  if(IsPlayerInAnyVehicle(playerid))
  {
    SetVehicleHealth(GetPlayerVehicleID(playerid), 100000);
  }
  return 1;
}