Custom Po Po lights problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Custom Po Po lights problem (
/showthread.php?tid=241040)
Custom Po Po lights problem -
austin070 - 17.03.2011
I have a custom police light system. When you are in a certain vehicle and press H or Caps Lock, a light is attached to your vehicle. The thing is, I can't get it to destroy when the key is pressed again. Here is the code:
pawn Код:
new pdlight;
if(newkeys & KEY_CROUCH)
{
if(light == 0)
{
if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
{
pdlight = CreateObject(18646, 0, 0, -500,0, 0, 0, 5000);
AttachObjectToVehicle(pdlight, GetPlayerVehicleID(playerid), 0.4, 0.6, 0.41, 0 ,0 ,0);
light = 1;
}
}else {
if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10])) {
DestroyObject(pdlight);
light = 0;
}
}
}
PS: Is there any way to define a new key?
Re: Custom Po Po lights problem -
Marricio - 17.03.2011
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new pdlight = CreateObject(18646, 0, 0, -500,0, 0, 0, 5000);
if(newkeys & KEY_CROUCH)
{
if(light[vehicleid] == 0)
{
if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
{
AttachObjectToVehicle(pdlight, GetPlayerVehicleID(playerid), 0.4, 0.6, 0.41, 0 ,0 ,0);
light[vehicleid] = 1;
}
}
else if(light[vehicleid] != 0)
{
if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
{
RemoveAttachedObject(pdlight);
light[vehicleid] = 0;
}
}
}
return 1;
}
Change your
pawn Код:
new light; // I assume that here you're doing a GLOBAL variable. (for all cars and players)
to
pawn Код:
new light[MAX_VEHICLES]; // And here you doing a variable for a vehicle.
But i still see the createobject useless cause when you add AttachObjectToVehicle the object creates automaticly?
Re: Custom Po Po lights problem -
austin070 - 17.03.2011
Quote:
Originally Posted by Marricio
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { new pdlight = CreateObject(18646, 0, 0, -500,0, 0, 0, 5000); if(newkeys & KEY_CROUCH) { if(light[vehicleid] == 0) { if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10])) { AttachObjectToVehicle(pdlight, GetPlayerVehicleID(playerid), 0.4, 0.6, 0.41, 0 ,0 ,0); light[vehicleid] = 1; } } else if(light[vehicleid] != 0) { if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10])) { RemoveAttachedObject(pdlight); light[vehicleid] = 0; } } } return 1; }
Change your
pawn Код:
new light; // I assume that here you're doing a GLOBAL variable. (for all cars and players)
to
pawn Код:
new light[MAX_VEHICLES]; // And here you doing a variable for a vehicle.
But i still see the createobject useless cause when you add AttachObjectToVehicle the object creates automaticly?
|
I made light an array, but still no go. BTW, AttachObjectToVehicle doesn't create the object. I tried it.
I can get the object to create, just can't get it to destroy.
Re: Custom Po Po lights problem -
Marricio - 17.03.2011
Did you even test it? I changed DestroyObject to RemovePlayerAttachedObject
Re: Custom Po Po lights problem -
austin070 - 17.03.2011
Yes, I tested it. I just changed it to a command, which works. I'll fix the key later.