Repair Abuse - 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)
+--- Thread: Repair Abuse (
/showthread.php?tid=466949)
Repair Abuse -
MBilal - 30.09.2013
hi guyz this is my repair Code i need help with that player abuse it so much can any budy tell me how to set timer on it
plz
Code:
if(IsPlayerInAnyVehicle(playerid))
{
if(newkeys & KEY_ANALOG_UP) // NumPad 8
{
new vehicleid = GetPlayerVehicleID(playerid);
SetVehicleHealth(vehicleid, 1000.0);
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, 0x800080FF, "[ Server ] Vehicle repaired.");
return 1;
}
Thanks
Re: Repair Abuse -
EiresJason - 30.09.2013
Try this:
pawn Code:
new bool:RepairedCar[MAX_PLAYERS]; //put this outside the command/function/callback
new RepairedCarTimer[MAX_PLAYERS]; //put this outside the command/function/callback
forward RepairedCarReset(playerid); //put this outside the command/function/callback
public RepairedCarReset(playerid) //put this outside the command/function/callback
{
if(RepairedCar[playerid])
{
RepairedCar[playerid] = false;
}
return 1;
}
if(IsPlayerInAnyVehicle(playerid))
{
if(newkeys & KEY_ANALOG_UP) // NumPad 8
{
if(!RepairedCar[playerid])
{
new vehicleid = GetPlayerVehicleID(playerid);
SetVehicleHealth(vehicleid, 1000.0);
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, 0x800080FF, "[ Server ] Vehicle repaired.");
RepairedCar[playerid] = true;
RepairedCarTimer[playerid] = SetTimerEx("RepairedCarReset",10000,false,"i",playerid); //10000 is the timer, it's set as 10seconds. After the command, they have to wait 10seconds to do it again. Change this to whatever you want. 25seconds would be 250000.
return 1;
}
else return SendClientMessage(playerid, 0x800080FF, "[ Server ] You cannot do this command yet!");
}
Re: Repair Abuse -
Konstantinos - 30.09.2013
Try avoiding timers wherever you can use GetTickCount/gettime instead. Change 5 to the seconds you want; for example, every 5 seconds a player can repair their vehicle.
pawn Code:
new
Allow_Repair[ MAX_PLAYERS ]
;
public OnPlayerConnect( playerid )
{
Allow_Repair[ playerid ] = -1;
return 1;
}
public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
{
if( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
{
if( ( newkeys & KEY_ANALOG_UP ) && !( oldkeys & KEY_ANALOG_UP ) )
{
if( Allow_Repair[ playerid ] == -1 || ( Allow_Repair[ playerid ] != -1 && ( gettime( ) - Allow_Repair[ playerid ] ) > 5 ) )
{
new
vehicleid = GetPlayerVehicleID( playerid )
;
SetVehicleHealth( vehicleid, 1000.0 );
RepairVehicle( vehicleid );
SendClientMessage( playerid, 0x800080FF, "[ Server ] Vehicle repaired." );
Allow_Repair[ playerid ] = gettime( );
}
}
}
return 1;
}
EDIT: I improved something in OnPlayerKeyStateChange callback. In case you used the code I gave, replace it with the new one.
Re: Repair Abuse -
MBilal - 30.09.2013
Thanks I will try
Re: Repair Abuse -
MBilal - 30.09.2013
Dude i try 2nd one not work
Re: Repair Abuse -
xganyx - 30.09.2013
Try this man
pawn Code:
#include <a_samp>
#define SECOND changeme
new RepairVehiclesAllowed[MAX_PLAYERS];
forward AllowedRepairSystem(playerid);
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_ANALOG_UP)
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,-1,"[ Server ] Man!! You have to got a vehicle to use this");
if(RepairVehiclesAllowed[playerid] != 0) return SendClientMessage(playerid,-1,"[ Server ] Wait a minute until the repair system complete...");
new vehicleid = GetPlayerVehicleID(playerid);
SetVehicleHealth(vehicleid, 1000.0);
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, 0x800080FF, "[ Server ] Vehicle repaired.");
SetTimer("AllowedRepairSystem",SECOND*1000,false);
}
return 1;
}
public AllowedRepairSystem(playerid)
{
RepairVehiclesAllowed[playerid] = 0;
return 1;
}
Re: Repair Abuse -
Konstantinos - 30.09.2013
Quote:
Originally Posted by MBilal
Dude i try 2nd one not work
|
I just tested and it worked. I had a mistake and I edited my post before, try the new one.
@xganyx: It's always better not to use timer for something is done without the use of a timer.
Re: Repair Abuse -
MBilal - 30.09.2013
dude i compile it show this
error 017: undefined symbol "changeme"
Re: Repair Abuse -
xganyx - 30.09.2013
i said you change that to second like "changeme" to "1" or "2" second.... "60" = 1 minutes use
SECOND 60 = 1 minute
instead of
Re: Repair Abuse -
MBilal - 30.09.2013
see this dude it still not working i try both codes
http://i41.tinypic.com/30k4rjb.png