SA-MP Forums Archive
The vehicle can be repaired every 60 seconds. Help! - 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: The vehicle can be repaired every 60 seconds. Help! (/showthread.php?tid=312009)



The vehicle can be repaired every 60 seconds. Help! - interpol - 19.01.2012

Код:
#define FILTERSCRIPT
#define COLOR_LIGHTBLUE 0x0080FFFF
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define IsPlayerNotInVehicle(%0) (!IsPlayerInAnyVehicle(%0))
#include <a_samp>
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Car Fix by pressing 2 to fix your car.");
	print("--------------------------------------\n");

	return 1;

}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
		if(PRESSED(KEY_SUBMISSION))
		{
		new vehicleid = GetPlayerVehicleID(playerid);
		if(IsPlayerInVehicle(playerid, vehicleid))
		{
		SetVehicleHealth(vehicleid,1000.0);
		RepairVehicle(GetPlayerVehicleID(playerid));
	    PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
		SendClientMessage(playerid,COLOR_LIGHTBLUE,"You have successfully repaired your car!");
		}
		}
		if(PRESSED(KEY_ACTION))
		{
		if(IsPlayerNotInVehicle(playerid))
		{
		SendClientMessage(playerid,COLOR_LIGHTBLUE,"You have to be in a car to be able to repair your car!");
		}
		}
}
#endif
or

Код:
#include <a_samp>

#define CZERWONY 0xFF0000FF
#define ZIELONY 0x00FF00FF

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
	{
	new currentveh; // flip
    	new Float:angle; // flip
    	currentveh = GetPlayerVehicleID(playerid); // flip
    	GetVehicleZAngle(currentveh, angle); // flip
    	SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0); 
	RepairVehicle(GetPlayerVehicleID(playerid)); 
      	PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
	return 1;
	}

	return 1;
}
This is not mine scripts. I found it from this forum. I wonder how to be able to repair the car every 60 seconds? I know about SetTimer and SetTimerEx, but I do not have sufficient knowledge to use this information. So I ask for your help, please. How to do this?

PS: Sorry for my English, but I'm not from English-speaking country.


Re: The vehicle can be repaired every 60 seconds. Help! - sameer419 - 19.01.2012

The car should be fixed for all players yea?

pawn Код:
#include <a_samp>

#define CZERWONY 0xFF0000FF
#define ZIELONY 0x00FF00FF

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
    new currentveh; // flip
        new Float:angle; // flip
        currentveh = GetPlayerVehicleID(playerid); // flip
        GetVehicleZAngle(currentveh, angle); // flip
        SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
    RepairVehicle(GetPlayerVehicleID(playerid));
        PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
    return 1;
    }

    return 1;
}
to

pawn Код:
#include <a_samp>

#define CZERWONY 0xFF0000FF
#define ZIELONY 0x00FF00FF

forward RepairVehicle(playerid);

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
        SetTimerEx("RVehicle", 1000, 60000, "i", playerid);
        return 1;
    }

    return 1;
}
public RVehicle(playerid)
{
        new currentveh; // flip
        new Float:angle; // flip
        currentveh = GetPlayerVehicleID(playerid); // flip
        GetVehicleZAngle(currentveh, angle); // flip
        SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
        RepairVehicle(GetPlayerVehicleID(playerid));
        PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
        return 1;
}



Re: The vehicle can be repaired every 60 seconds. Help! - interpol - 19.01.2012

I get 1 error and 1 warning.

Код:
rvehicle.pwn(6) : error 021: symbol already defined: "RepairVehicle"
rvehicle.pwn(18) : warning 235: public function lacks forward declaration (symbol "RVehicle")

1 Error.



Respuesta: The vehicle can be repaired every 60 seconds. Help! - OPremium - 19.01.2012

pawn Код:
public OnGameModeInit() //or OnFilterScriptInit if its a filterscript
{
    SetTimer("RepairCars", 60000, true); //We set a timer that will call the function "RepairCars" every 60000ms (~60 sec)
}

forward RepairCars();
public RepairCars() //This is the function that the timer will call
{
    for(new i; i < MAX_PLAYERS; i++) //You can also use foreach, its faster and more effective :)
    {
        if(!IsPlayerConnected(i)) continue; //Ignores players that aren't connected
        if(GetPlayerVehicleSeat(i) != 0) continue; //Ignores players that aren't in the driver seat
        //Now we can repair the car...
        SetVehicleHealth(GetPlayerVehicleID(i), 1000.0);
        RepairVehicle(GetPlayerVehicleID(i));
    }
}



Re: The vehicle can be repaired every 60 seconds. Help! - Konstantinos - 19.01.2012

The callback you made has to have the same name as the forward
pawn Код:
#include <a_samp>

#define CZERWONY 0xFF0000FF
#define ZIELONY 0x00FF00FF

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
        SetTimerEx("RVehicle", 1000, 60000, "i", playerid);
        return 1;
    }

    return 1;
}
forward RVehicle(playerid);
public RVehicle(playerid)
{
        new currentveh; // flip
        new Float:angle; // flip
        currentveh = GetPlayerVehicleID(playerid); // flip
        GetVehicleZAngle(currentveh, angle); // flip
        SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
        RepairVehicle(GetPlayerVehicleID(playerid));
        PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
        return 1;
}



Respuesta: Re: The vehicle can be repaired every 60 seconds. Help! - OPremium - 19.01.2012

Quote:
Originally Posted by sameer419
Посмотреть сообщение
pawn Код:
#include <a_samp>

#define CZERWONY 0xFF0000FF
#define ZIELONY 0x00FF00FF

forward RepairVehicle(playerid);

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
        SetTimerEx("RVehicle", 1000, 60000, "i", playerid);
        return 1;
    }

    return 1;
}
public RVehicle(playerid)
{
        new currentveh; // flip
        new Float:angle; // flip
        currentveh = GetPlayerVehicleID(playerid); // flip
        GetVehicleZAngle(currentveh, angle); // flip
        SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
        RepairVehicle(GetPlayerVehicleID(playerid));
        PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
        return 1;
}
That will only delay the repair by 1 second.... And your usage of SetTimerEx is wrong:

pawn Код:
SetTimerEx("RVehicle", 1000, 60000, "i", playerid);
should be:

pawn Код:
SetTimerEx("RVehicle", 1000, false, "i", playerid);



Re: Respuesta: Re: The vehicle can be repaired every 60 seconds. Help! - interpol - 19.01.2012

Код:
#include <a_samp>

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
        SetTimerEx("RVehicle", 20000, false, "i", playerid);
        return 1;
    }

    return 1;
}
forward RVehicle(playerid);
public RVehicle(playerid)
{
        new currentveh; // flip
        new Float:angle; // flip
        currentveh = GetPlayerVehicleID(playerid); // flip
        GetVehicleZAngle(currentveh, angle); // flip
        SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
        RepairVehicle(GetPlayerVehicleID(playerid));
        PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
        return 1;
}
Thanks guys for response. This code almost working fine. But when I click key '2', my car is repaired after 20 seconds, I want when I click key '2' car is repaired immediatly and next repair is available after 20 seconds.


Respuesta: Re: Respuesta: Re: The vehicle can be repaired every 60 seconds. Help! - OPremium - 19.01.2012

pawn Код:
#include <a_samp>

new LastRepair[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION && !GetPlayerVehicleSeat(playerid))
    {
        if((gettime()-LastRepair[playerid]) < 20)
        {
            //Here you can send a message saying that you need to wait before repairing again or whatever you want
            return 1;
        }
        LastRepair[playerid] = gettime();
        new currentveh; // flip
        new Float:angle; // flip
        currentveh = GetPlayerVehicleID(playerid); // flip
        GetVehicleZAngle(currentveh, angle); // flip
        SetVehicleZAngle(currentveh, angle); // flip
        SetVehicleHealth(GetPlayerVehicleID(playerid),1000.0);
        RepairVehicle(GetPlayerVehicleID(playerid));
        PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
    }
    return 1;
}



Re: Respuesta: Re: Respuesta: Re: The vehicle can be repaired every 60 seconds. Help! - interpol - 19.01.2012

Thanks OPremium! Finally it working!!!
And thanks also everyone who tried to help me!