Help autofix command
#1

Hello, I am trying to execute the / autofix command that automatically repairs the vehicles without having to type it again, then I leave the code.

What I need is to see and optimize it in the best way so that it does not cause lag, what would be the best option? I listen to comments and / or codes, thank you.

PHP код:
new AutoFix[MAX_PLAYERS];
public 
OnPlayerUpdate(playerid)
{
if(
AutoFix[playerid] == && IsPlayerInAnyVehicle(playerid))
{
RepairVehicle(GetPlayerVehicleID(playerid));
}
return 
1;
}
CMD:autofix(playerid,params[])
{
       if (
AutoFix[playerid] == 0)
    {
        
AutoFix[playerid] = 1;
    }
    else if (
AutoFix[playerid] == 1)
    {
        
AutoFix[playerid] = 0;
    }
    return 
1;

Reply
#2

I don't see why that would cause lag. There's nothing to optimize.

Only problem I see is that you're using IsPlayerInAnyVehicle which could cause complications. If a player's the passenger of a vehicle and the driver doesn't have their autofix on, it'll still repair that car. Use GetPlayerState to see if the player is the driver of the vehicle.
Reply
#3

It is better to use one second timer or OnVehicleDamageStatusUpdate + setting vehicle health to very high value.
Reply
#4

You could use "switch(Autofix[playerid])" into the command
Reply
#5

Don't use OnPlayerUpdate

Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(hittype == BULLET_HIT_TYPE_VEHICLE)
    {
        new p = GetVehicleOwner(vehicleid);
		if(IsPlayerConnected(p) && AutoFix[p] == 1)
		{
			RepairVehicle(p);
		}
    }
    return 1;
}

public GetVehicleOwner(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(vehicleid == GetPlayerVehicleID(i) && IsPlayerConnected(i)) return i;
	}
	return -1;
}
Reply
#6

PHP код:
new AutoFix[MAX_PLAYERS];
public 
OnPlayerUpdate(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(
AutoFix[playerid] == 1)
        {
            
RepairVehicle(GetPlayerVehicleID(playerid));
        }
    }
    return 
1;
}
CMD:autofix(playerid,params[])
{
    switch(
AutoFix[playerid])
    {
        case 
0AutoFix[playerid] = 1;
        case 
1AutoFix[playerid] = 0;
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by AlamoTR
Посмотреть сообщение
PHP код:
new AutoFix[MAX_PLAYERS];
public 
OnPlayerUpdate(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(
AutoFix[playerid] == 1)
        {
            
RepairVehicle(GetPlayerVehicleID(playerid));
        }
    }
    return 
1;
}
CMD:autofix(playerid,params[])
{
    switch(
AutoFix[playerid])
    {
        case 
0AutoFix[playerid] = 1;
        case 
1AutoFix[playerid] = 0;
    }
    return 
1;

PHP код:
new AutoFix[MAX_PLAYERS];
public 
OnPlayerUpdate(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(
AutoFix[playerid] == 1)
        {
            
RepairVehicle(GetPlayerVehicleID(playerid));
        }
    }
    return 
1;
}
CMD:autofix(playerid,params[])
{
       
AutoFix[playerid] = !AutoFix[playerid];
       return 
1;

Reply
#8

Both codes codes are horrible. OPU is executed pretty much every few milliseconds, terrible.
Reply
#9

PHP код:
new AutoFix[MAX_PLAYERS];
public 
OnVehicleDamageStatusUpdate (vehicleidplayerid)
{
     if(
AutoFix[playerid] == 1)
     {
          
RepairVehicle(vehicleid);
     }
     return 
1;
}
CMD:autofix(playerid,params[])
{
    switch(
AutoFix[playerid])
    {
        case 
0AutoFix[playerid] = 1SendClientMessage(playerid,-1,"Auto-Fixed Disabled !");
        case 
1AutoFix[playerid] = 0SendClientMessage(playerid,-1,"Auto-Fixed Enabled !");
    }
    return 
1;

Try my one,
It's faster, better.
Reply
#10

Quote:
Originally Posted by FuNkYTheGreat
Посмотреть сообщение
PHP код:
new AutoFix[MAX_PLAYERS];
public 
OnVehicleDamageStatusUpdate (vehicleidplayerid)
{
     if(
AutoFix[playerid] == 1)
     {
          
RepairVehicle(vehicleid);
     }
     return 
1;
}
CMD:autofix(playerid,params[])
{
    switch(
AutoFix[playerid])
    {
        case 
0AutoFix[playerid] = 1SendClientMessage(playerid,-1,"Auto-Fixed Disabled !");
        case 
1AutoFix[playerid] = 0SendClientMessage(playerid,-1,"Auto-Fixed Enabled !");
    }
    return 
1;

Try my one,
It's faster, better.


Many thanks to all, I will try the code of FuNkYTheGreat and I warn you that such was me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)