autorepair does not work - 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: autorepair does not work (
/showthread.php?tid=258595)
autorepair does not work -
Madsen - 31.05.2011
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;
}
Re: autorepair does not work -
xir - 31.05.2011
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;
}
Re: autorepair does not work -
Madsen - 31.05.2011
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.
Re: autorepair does not work -
sleepysnowflake - 31.05.2011
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.
Re: autorepair does not work -
Sasino97 - 31.05.2011
Isn't this more simple ?:
pawn Код:
public OnPlayerUpdate(playerid)
{
if(IsPlayerInAnyVehicle(playerid)) RepairVehicle(GetPlayerVehicleID(playerid));
return 1;
}
This will make all the cars undestructible
Re: autorepair does not work -
Markx - 31.05.2011
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.
Re: autorepair does not work -
Laronic - 31.05.2011
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;
}
Re: autorepair does not work -
Madsen - 03.06.2011
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