Repair Abuse
#1

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
Reply
#2

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!");
    }
Reply
#3

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.
Reply
#4

Thanks I will try
Reply
#5

Dude i try 2nd one not work
Reply
#6

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;
}
Reply
#7

Quote:
Originally Posted by MBilal
View Post
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.
Reply
#8

dude i compile it show this
error 017: undefined symbol "changeme"
Reply
#9

i said you change that to second like "changeme" to "1" or "2" second.... "60" = 1 minutes use

pawn Code:
#define SECOND 60
SECOND 60 = 1 minute

instead of

pawn Code:
#define SECOND changeme
Reply
#10

see this dude it still not working i try both codes
http://i41.tinypic.com/30k4rjb.png
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)