PDA

View Full Version : The vehicle can be repaired every 60 seconds. Help!


interpol
19/01/2012, 02:44 PM
#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 (http://wiki.sa-mp.com/wiki/SetTimer) and SetTimerEx (http://wiki.sa-mp.com/wiki/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.

sameer419
19/01/2012, 02:58 PM
The car should be fixed for all players yea?


#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


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

interpol
19/01/2012, 03:25 PM
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.

OPremium
19/01/2012, 03:28 PM
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));
}
}

Konstantinos
19/01/2012, 03:30 PM
The callback you made has to have the same name as the forward
#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;
}

OPremium
19/01/2012, 03:35 PM
#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:


SetTimerEx("RVehicle", 1000, 60000, "i", playerid);


should be:


SetTimerEx("RVehicle", 1000, false, "i", playerid);

interpol
19/01/2012, 04:00 PM
#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.

OPremium
19/01/2012, 04:13 PM
#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;
}

interpol
19/01/2012, 04:27 PM
Thanks OPremium! Finally it working!!! :D
And thanks also everyone who tried to help me! :D