SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/09/2013, 12:50 PM   #1
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Angry Repair Abuse

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
MBilal is offline   Reply With Quote
Old 30/09/2013, 01:06 PM   #2
EiresJason
Gangsta
 
Join Date: Mar 2013
Location: Dublin.
Posts: 685
Reputation: 76
Default Re: Repair Abuse

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!");
    }
EiresJason is offline   Reply With Quote
Old 30/09/2013, 01:08 PM   #3
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: Repair Abuse

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.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 30/09/2013, 01:09 PM   #4
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Default Re: Repair Abuse

Thanks I will try
MBilal is offline   Reply With Quote
Old 30/09/2013, 01:28 PM   #5
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Default Re: Repair Abuse

Dude i try 2nd one not work
MBilal is offline   Reply With Quote
Old 30/09/2013, 01:28 PM   #6
xganyx
Gangsta
 
xganyx's Avatar
 
Join Date: May 2013
Posts: 675
Reputation: 7
Default Re: Repair Abuse

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;
}
__________________
xganyx is offline   Reply With Quote
Old 30/09/2013, 01:34 PM   #7
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: Repair Abuse

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.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 30/09/2013, 01:38 PM   #8
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Default Re: Repair Abuse

dude i compile it show this
error 017: undefined symbol "changeme"
MBilal is offline   Reply With Quote
Old 30/09/2013, 01:49 PM   #9
xganyx
Gangsta
 
xganyx's Avatar
 
Join Date: May 2013
Posts: 675
Reputation: 7
Default Re: Repair Abuse

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
__________________
xganyx is offline   Reply With Quote
Old 30/09/2013, 02:05 PM   #10
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Default Re: Repair Abuse

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Auto Car Repair [Full Repair] Vikshay Filterscripts 1 12/07/2013 10:11 PM
Something must be done againt the -rep abuse... L.Hudson Everything and Nothing 15 03/05/2013 11:25 AM
[Help]Kinda abuse [CG]Milito Scripting Help 2 02/12/2012 01:49 AM
Pause/Esc abuse happyface General 0 13/04/2011 08:56 PM


All times are GMT. The time now is 10:42 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.