SA-MP Forums Archive
Is this the right way to do it?. - 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: Is this the right way to do it?. (/showthread.php?tid=243845)



Is this the right way to do it?. - [BKR]LUCAGRABACR - 25.03.2011

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.


Re: Is this the right way to do it?. - antonio112 - 25.03.2011

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.


Re: Is this the right way to do it?. - [BKR]LUCAGRABACR - 25.03.2011

@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?.


Re: Is this the right way to do it?. - ihatetn931 - 25.03.2011

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