[SOLVED] Admin Vehicle Script
#1

Hi guys! Its me again with another noobish question! lol


Please reply to this!
I have made a tuned command script for admins! what it does is IT Makes the vehicle an admin vehicle so no-one else can get in! But i dont know how to the vehicle health to infinite.

Here is the script:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
  printf("ID %d was at %d and changed to state %d",playerid,oldstate,newstate);
  new currentState = GetPlayerState(playerid);
  if (currentState == PLAYER_STATE_DRIVER)
	{
		//It's a driveby, take some money
    if(IsPlayerInVehicle(playerid, tuned))
		{
 			if(IsPlayerLAdmin(playerid))
			{
				SendClientMessage(playerid, 0xFFFF00FF,"Welcome to your admin car");
                          new vehicleid = GetPlayerVehicleID(playerid);
				SetVehicleHealth(vehicleid,999999999.0);
			}
			else
			RemovePlayerFromVehicle(playerid);
		}
	}
	return 1;
}
It gives me no errors when i compile but in the script, the set vehicle health doesn't work, so the vehicle does blow up!
Please can u explain what I should do!

By the way, im rubbish at scripting as u might know from my recent posts so i would prefer it if u explained it detail
Thank you guys!
Reply
#2

You could do a repeating timer, to reset it to 1000 every so seconds you put.
https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

Thnx , and I know what u mean! But, as i said, im not the best at scripting, so could u advance on the script above and tell me what to write and where!

Thank u
Reply
#4

Quote:
Originally Posted by Chaprnks
You could do a repeating timer, to reset it to 1000 every so seconds you put.
https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetTimerEx
That would waste memory.
Instead you could run a timer checking if the health is below 1000, if it is, then it resets the car's health to 1000 or 100, or whatever the default is.

Try this:

pawn Код:
// --- at the top of your script
new carvar;
new thetimer;
forward timer();
// ---

// --- Somewhere in your script
public timer()
{
new Float:chp;
GetVehicleHealth(tuned, chp);
if(chp < 9)
{
SetVehicleHealth(tuned, 1000);
return 1;
}
else
{
return 1;
}
}
// ---

// --- On your OnPlayerEnterVehicle
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(vehicleid == tuned)
{
if(IsPlayerAdmin(playerid))
{
thetimer = SetTimer("timer", 20000, true);
carvar = 1;
}
}
}
// ---

// --- On your OnPlayerExitVehicle
public OnPlayerExitVehicle(playerid, vehicleid)
{
if(vehicleid == tuned)
{
if(IsPlayerAdmin(playerid))
{
if(carvar == 1)
{
carvar = 0;
KillTimer(thetimer);
}
}
}
}
// --- Enjoy
// By Micro
I still suggest you read through this:
SET TIMER
Reply
#5

Thnx man! This is what I wanted!
But, will it work for my tuned cmd! Ill check l8r and reply btw thnx again!

Quote:

I still suggest you read through this:
SET TIMER

I already read that but im new to scripting so i couldnt understand half of it lol!
Reply
#6

you put SetVehicleHealth(vehicleid, 9999999.0) needs to be SetVehicleHealth(vehicleid, -9999999.0)
Reply
#7

thanks you sooo much ive been looking for an admin only code
Reply
#8

to set the vehicle health Max:

Код:
SetVehicleHealth(vehicleid, 100.0);
New in 0.3, (vehicleHealth 100 and no scratches or dents):

Код:
RepairVehicle(vehicleid);
Reply
#9

Quote:
Originally Posted by CAR
to set the vehicle health Max:

Код:
SetVehicleHealth(vehicleid, 100.0);
New in 0.3, (vehicleHealth 100 and no scratches or dents):

Код:
RepairVehicle(vehicleid);
Max Vehicle health is 1000, not 100.
Reply
#10

ok if it's true, do:
Код:
SetVehicleHealth(vehicleid, 1000.0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)