Using timers - 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: Using timers (
/showthread.php?tid=123982)
Using timers -
wangdata - 28.01.2010
I am using timers in an auto repair script and am wondering if it is best to have a timer running constantly presuming there will be at least 1 player in a car at all times?
Re: Using timers -
WrathOfGenesis - 28.01.2010
loop players
IsPlayerInVehicle
GetVehicleHealth
if less than the lowest health you want,
SetVehicleHealth
Put them in a timer and that should do it
Re: Using timers -
biltong - 28.01.2010
Or map it to a key:
pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
RepairVehicle(vehicleid);
SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
return 1;
}
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_RED,"You're not the driver of this vehicle!");
return 1;
}
if(IsPlayerInAnyVehicle(playerid) != PLAYER_STATE_DRIVER )
{
SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!");
return 1;
}
}
}
}
Although the "You're not in a vehicle" bit is broken, no idea why :S
Easiest way to do it IMO
Re: Using timers -
WrathOfGenesis - 28.01.2010
He wants a script that autorepairs without the need for a key press for stunt servers etc
Also biltong, try this
pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
{
if( !IsPlayerInAnyVehicle ( playerid ) )
{
SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!");
return 1;
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
RepairVehicle(vehicleid);
SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired.");
return 1;
}
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_RED,"You're not the driver of this vehicle!");
return 1;
}
}
}
return 1;
}
Re: Using timers -
wangdata - 28.01.2010
Thank you for your help.
Re: Using timers -
biltong - 28.01.2010
Quote:
|
Originally Posted by WrathOfGenesis
He wants a script that autorepairs without the need for a key press for stunt servers etc
Also biltong, try this
pawn Код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys) { if(IsPlayerInAnyVehicle(playerid)) { new vehicleid = GetPlayerVehicleID(playerid); if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)) { if( !IsPlayerInAnyVehicle ( playerid ) ) { SendClientMessage(playerid,COLOR_RED, "You're not in a vehicle!"); return 1; }
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) { RepairVehicle(vehicleid); SendClientMessage(playerid,COLOR_GREEN, "Your vehicle has been repaired."); return 1; } if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) { SendClientMessage(playerid,COLOR_RED,"You're not the driver of this vehicle!"); return 1; } } }
return 1; }
|
Yeah thanks, I deserve a facepalm, I used IsPlayerInAnyVehicle to chek the player state -.-
Changed to yours, about to test