Is this the right way to do it?.
#1

So I try to create a script where if the vehicle's health reach 300 then the vehicle's engine will stop, it works, but I want your(s) opinion to see if there's a more efficient method, and there's also some bugs, here's the codes:

pawn Код:
//Forwarding the timer.
forward vehhealthtimer(playerid, vehicleid, veh);
   
//Then below OnGameModeInIt callback (or wherever you like and think is better) put this timer.
SetTimer("vehhealthtimer", 1000, 1);

//The public function.
public vehhealthtimer(playerid, vehicleid, veh)
{
if(IsPlayerInAnyVehicle(playerid))
{
new engine,lights,alarm,doors,bonnet,boot,objective;
new Float:health;
    new vehhealth;
    vehhealth = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehhealth, health);
    if(health <300)return SetVehicleParamsEx(GetPlayerVehicleID(playerid), 0 - engine, lights, alarm, doors, bonnet, boot, objective);
    return 1;
    }
    return 1;
And if I put SendClientMessage to says "Vehicle is totalled." Then the message will appear every single seconds if the players is in any vehicles lol, so, any suggestions?.

I'm not so good at scripting :S.
Reply
#2

Well, the timer is set to repeat every second ( to check for vehicles health ), that`s why if you put a message, it`ll repeat it every second while the car's health is below 300.
Reply
#3

@Antonio: I noticed that, but what confusing me is even if the vehicle's health is not below 300 it will still shows the messages if we're in any car.

And if we have loads of timers running at the same time in the server does it makes the server lagging?.
Reply
#4

Quote:
Originally Posted by [BKR]LUCAGRABACR
Посмотреть сообщение
@Antonio: I noticed that, but what confusing me is even if the vehicle's health is not below 300 it will still shows the messages if we're in any car.

And if we have loads of timers running at the same time in the server does it makes the server lagging?.
Make a new variable, So when the health is below 300 is calls that variable and sets it to one then do like
pawn Код:
if(health <  300 && variable == 0)
{
//send message here and toggle the engine
variable = 1;
return 1;
}
if(health > 300 && variable ==  1)//Basically what this is doing is seeing if the car health is above 300 and if the variable is true
{
variable = 0;
}
That should work. How good i'm not sure but it shouldn't spam messages when you put it there
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)