SA-MP Forums Archive
auto repair - 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: auto repair (/showthread.php?tid=245169)



auto repair - Madsen - 30.03.2011

hey i am trying to make a auto repair system for my server but it does not work here is what i have done


pawn Code:
new autorepair[MAX_PLAYERS];

forward OnVehicleDamage(playerid);

public OnVehicleDamage(playerid)
{
    new Float:health, cid;
   
    if(autorepair[playerid] == 1)
    {
        if (!IsPlayerInAnyVehicle(playerid))
        {
            cid = GetPlayerVehicleID(playerid);
            GetVehicleHealth(cid, health);
            {
                if (health < 500)
                {
                SetVehicleHealth(cid, 1000);
                }
            }
        }
    }
    return 1;
}
public OnGameModeInit()
pawn Code:
SetTimer("OnVehicleDamage", 1000, 1);

pawn Code:
if (strcmp("/racemap", cmdtext, true, 10) == 0)
    {
        SetPlayerPos(playerid, 5070.8862304688, -2250.9711914063, 403.73211669922+1);
        SendClientMessage(playerid, COLOR_ORANGE, " Thank Speederx for making the race/stunt map");
        autorepair[playerid] = 1;
        return 1;
    }
i get 0 errors but in game it does not work


Re: auto repair - HyperZ - 30.03.2011

pawn Code:
public OnVehicleDamage(playerid)
{
    new Float:VHealth, vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicleid,VHealth);
    if(autorepair[playerid] == 1)
    {
        if (!IsPlayerInAnyVehicle(playerid))
        {
            if(autorepair[playerid] == 1)
            {
                if(VHealth < 500)
                {
                    SetVehicleHealth(vehicleid,1000);
                }
            }
        }
    }
    return 1;
}



Re: auto repair - Ћilvėnas - 30.03.2011

WAIT

Code:
if (strcmp("/racemap", cmdtext, true, 10) == 0)
    {
        SetPlayerPos(playerid, 5070.8862304688, -2250.9711914063, 403.73211669922+1);
        SendClientMessage(playerid, COLOR_ORANGE, " Thank Speederx for making the race/stunt map");
         GetVehicleHealth(playerid, 100);
        return 1;
    }
Try this.But..it's simple.And well :]


AW: Re: auto repair - xerox8521 - 30.03.2011

Quote:
Originally Posted by Clive
View Post
pawn Code:
public OnVehicleDamage(playerid)
{
    new Float:VHealth, vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicleid,VHealth);
    if(autorepair[playerid] == 1)
    {
        if (!IsPlayerInAnyVehicle(playerid))
        {
            if(autorepair[playerid] == 1)
            {
                if(VHealth < 500)
                {
                    SetVehicleHealth(vehicleid,1000);
                }
            }
        }
    }
    return 1;
}
Replace the

pawn Code:
public OnVehicleDamage(playerid)
{
                    SetVehicleHealth(vehicleid,1000);
 
}
to
pawn Code:
public OnVehicleDamage(playerid)
{
                    RepairVehicle(vehicleid);
// things like Doors / Tires get fixed too( Visible Damage)
// Health get set to 1000 too

 
}



Re: auto repair - Madsen - 30.03.2011

it still does not work :O?


Re: auto repair - Zh3r0 - 30.03.2011

It's because you are checking if the player is NOT(!) in the vehicle! Notice the '!' Exclamation Point near the function, that means the opposite of what it should do, so it check if he is NOT.

So delete the ! from the front of the function of IsPlayerInAnyVehicle


Re: auto repair - Madsen - 30.03.2011

hmm, ty


Re: auto repair - Madsen - 31.03.2011

Quote:
Originally Posted by Zh3r0
View Post
It's because you are checking if the player is NOT(!) in the vehicle! Notice the '!' Exclamation Point near the function, that means the opposite of what it should do, so it check if he is NOT.

So delete the ! from the front of the function of IsPlayerInAnyVehicle
thx alot it works now , i even asked my friend about it and he just said it was right -_-


Re: auto repair - Madsen - 01.04.2011

can anyone tell me why its only the first one that join the autorepair thing works for :S?


Re: auto repair - Madsen - 01.04.2011

it looks like this now:
pawn Code:
//at the top
new autorepair[MAX_PLAYERS];
pawn Code:
forward AutoR(playerid);

public AutoR(playerid)
{
    new Float:VHealth, vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicleid,VHealth);
    if(autorepair[playerid] == 1)
    {
        if (IsPlayerInAnyVehicle(playerid))
        {
            if(VHealth < 999)
            {
            RepairVehicle(vehicleid);
            }
        }
    }
    return 1;
}
onplayercommand
pawn Code:
if (strcmp("/offroadmap", cmdtext, true, 10) == 0)
    {
        SetPlayerPos(playerid, -2644, -2130, 1704+1);
        SendClientMessage(playerid, COLOR_ORANGE, "Thank Thanator for making the offroad road");
        autorepair[playerid] = 1;
        SetPlayerCheckpoint(playerid, 79.8441, -1531.5741, 2413.0000, 5);
        return 1;
    }