[Enable / Disable] Vehicle Auto-Fix (Not Working) |Easy & +1 Rep|
#1

I have tried to make a command that lets you toggle vehicle auto-fix on and off but I can't make it work ... :/

This is how far I am right now:

Код:
CMD:autofix(playerid,params[]) {
	#pragma unused params
    	if(PlayerInfo[playerid][Autofix] == 0)	{
   	    	PlayerInfo[playerid][Autofix] = 1;
   	 	    GetVehicleHealth(playerid,250) SetVehicleHealth(playerid,1000);
           	SendClientMessage(playerid,green,"Vehicle Auto-Fix Enabled. Do NOT use in fight.");
		} else {
   	        PlayerInfo[playerid][Autofix] = 0;
       	    SendClientMessage(playerid,red,"Vehicle Auto-Fix Disabled");
        	SetPlayerHealth(playerid, 100);
		} return GivePlayerWeapon(playerid,35,0);
}
When the car reaches 250hp I wan't it to automaticly repair itself so the hp changes to 1000.

Hope someone can help me fixing the code!
Reply
#2

Код:
public OnVehicleDeath(vehicleid) {
  for (new i = 0; i < MAX_PLAYERS; i++) {
      if (IsPlayerInVehicle(i, vehicleid)) {
         new Float:vHealth;
         GetVehicleHealth(vehicleid, vHealth);
         if (PlayerInfo[i][Autofix] == 1 && vHealth =< 250) {
            RepairVehicle(vehicleid);
         }
     }
  }
}
Try this.
Reply
#3

Quote:
Originally Posted by Alternative112
Посмотреть сообщение
Код:
public OnVehicleDeath(vehicleid) {
  if (IsPlayerInVehicle(vehicleid)) {
     new Float:vHealth;
     GetVehicleHealth(vehicleid, vHealth);
     if (PlayerInfo[playerid][Autofix] == 1 && vHealth =< 250) {
        SetVehicleHealth(vehicleid, 1000.0);
     }
  }
}
Try this.
Would I be able to enable/disable that?
Reply
#4

Refresh your page, I edited the code a little.

That will be the code that handles the actual recovery of the car if the player has Autofix enabled. Your /autofix command only needs to set PlayerInfo[playerid][Autofix] equal to 1 so that the OnVehicleDeath knows if the player has it enabled. Make sure that PlayerInfo is global, too. OnVehicleDeath has no access to playerid, this is why I make it loop through MAX_PLAYERS.
Reply
#5

1. Make a function that fixes the vehicle.
2. Make a timer that calls the function.
3. Make a command that enables/disables autofix for a player.

I think it's simple enough
Reply
#6

I still cant get it working..

I tried to change my command like this:

Код:
CMD:autofix(playerid,params[]) {
	#pragma unused params
    	if(PlayerInfo[playerid][Autofix] == 0)	{
   	    	PlayerInfo[playerid][Autofix] = 1;
           	SendClientMessage(playerid,green,"Vehicle Auto-Fix Enabled. Do NOT use in fight.");
		} else {
   	        PlayerInfo[playerid][Autofix] = 0;
		} return SendClientMessage(playerid,red,"Vehicle Auto-Fix Disabled");
}
and OnVehicleDeath like this:

Код:
public OnVehicleDeath(vehicleid,killerid)
{
	if(VehicleInfo[vehicleid][Temp] == 1) SetTimerEx("EraseVehicle", 5000,0,"i",vehicleid);
	if(onsys[vehicleid] == 1) SetTimerEx("EraseVehicle",10000,0,"i",vehicleid);
    SandInEngine[vehicleid] =0;
    
    for (new i = 0; i < MAX_PLAYERS; i++) {
    if (IsPlayerInVehicle(i, vehicleid)) {
    new Float:vHealth;
    GetVehicleHealth(vehicleid, vHealth);
    if (PlayerInfo[i][Autofix] == 1 && vHealth =< 250) {
    RepairVehicle(vehicleid);
	return 1;
}
but I just got a lot of errors.. :/
Reply
#7

I've tried and tried to make this work but still it doesnt work..
anyone that maybe could explain it more in details what I should do and maybe make the code for me and explain me where I should have it.
Reply
#8

Firstly, try changing this:

Код:
 if (PlayerInfo[i][Autofix] == 1 && vHealth =< 250)
to this:

Код:
 if (PlayerInfo[i][Autofix] == 1 && vHealth =< 250.0)
Then make sure that you're returning 1 in your OnVehicleDeath event. If that doesn't work, post the error list that you get on here - it can really help us help you.

Secondly, if you still have problems after you do get it compiling, I suggest you use some SendClientMessage debug codes in your command and event to make the game write where it is in the code - it is very helpful in finding where exactly the script is failing. Is the script getting into the CMD:autofix? Does it do your /autofix script correctly, but fail to jump into the OnPlayerDeath? Does it get into OnPlayerDeath but not recover it correctly? Once you know where the problem is, only then can you address it.

Код:
CMD:autofix(playerid,params[]) {
        SendClientMessage(playerid,green,"Entered command /autofix.");
	#pragma unused params
    	if(PlayerInfo[playerid][Autofix] == 0)	{
                SendClientMessage(playerid,green,"Player has autofix disabled.");
   	    	PlayerInfo[playerid][Autofix] = 1;
           	SendClientMessage(playerid,green,"Vehicle Auto-Fix Enabled. Do NOT use in fight.");
		} else {
                SendClientMessage(playerid,green,"Player has autofix enabled.");
   	        PlayerInfo[playerid][Autofix] = 0;
		} return SendClientMessage(playerid,red,"Vehicle Auto-Fix Disabled");
}
Код:
public OnVehicleDeath(vehicleid,killerid)
{
	if(VehicleInfo[vehicleid][Temp] == 1) SetTimerEx("EraseVehicle", 5000,0,"i",vehicleid);
	if(onsys[vehicleid] == 1) SetTimerEx("EraseVehicle",10000,0,"i",vehicleid);
    SandInEngine[vehicleid] =0;
    
    for (new i = 0; i < MAX_PLAYERS; i++) {
    if (IsPlayerInVehicle(i, vehicleid)) {
    new Float:vHealth;
    GetVehicleHealth(vehicleid, vHealth);
    if (PlayerInfo[i][Autofix] == 1 && vHealth =< 250) {
    RepairVehicle(vehicleid);
	return 1;
}
Again, we would need to see what kind of errors you're getting before we can suggest changes.
Reply
#9

pawn Код:
public OnVehicleDeath(vehicleid,killerid)
{
    if(VehicleInfo[vehicleid][Temp] == 1)
    {
        SetTimerEx("EraseVehicle", 5000, 0, "i", vehicleid);
    }
    if(onsys[vehicleid] == 1)
    {
        SetTimerEx("EraseVehicle", 10000, 0, "i", vehicleid);
    }
    SandInEngine[vehicleid] = 0;
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerInVehicle(i, vehicleid)) continue;
        new Float:vHealth;
        GetVehicleHealth(vehicleid, vHealth);
        if (PlayerInfo[i][Autofix] == 1 && vHealth <= 250.0)
        {
            RepairVehicle(vehicleid);
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)