Author Topic: Looping a Schedule/ Obtaining Health of a Vehicle [Fixed]  (Read 1204 times)

Ok, so I'm trying to make a schedule loop. However I'm completely baffled on how to do this. I've thought and thought but I'm just too much of a beginner.
Code: [Select]
function armor::onMount(%this,%obj,%col,%slot)
{
%driver = %obj;
%driver_client = %obj.client;
%vehicle = %col; //FIND VEHICLE
%vehicledb = %col.getDatablock(); //FIND THE DATABLOCK OF THE VEHICLE (Like the Jeep datablock), gotta find function variables
schedule(2000,0,commandToClient,%driver_client,'bottomPrint', "Vehicle Health:" SPC %vehicledb.maxDamage - %vehicle.getDamageLevel());
}


How can I make this repeat itself so that the bottom print constantly renews every second?
« Last Edit: October 12, 2010, 07:25:28 PM by KuriousGeorge »

The best way is to create a function that reschedules itself.

The IOCCC(Contest where people who write the most unreadable C code, with extreme size restrictions as well) way would be to write a quine function and schedule an eval that incorperates it to "loop" itself.

You should use the first solution.

Right, that made a load of sense. I'm not quite getting you here.

This shouldn't be on a schedule, but instead tell the vehicle health to all the players in the vehicle when it gets damaged or healed.

I tried but Vehicle::Damage isn't a call, I was looking for it using .dump(); too. But I couldn't find an onVehicleDamaged or anything. I had to have a friend give me the current call.

Excuse me if call isn't the right term. Call, function... they all mean the same thing to me right now.

It might be WheeledVehicle::Damage and FlyingVehicle::Damage

and it uses the same arguments as Armor:onMount?

Code: [Select]
function loopa(){
schedule(1000,0,loopb);
}

function loopb(){
dostuff
loopa();
}

?

and it uses the same arguments as Armor:onMount?
No, but probably the same as ::damage

Code: [Select]
function loopa(){
schedule(1000,0,loopb);
}

function loopb(){
dostuff
loopa();
}

?
As much as it would work, I could see several problems that could come from it.

Now we're getting off topic from the orginal post, but let me make sure I have my arguments right.

function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)

%this is the vehicle
%obj is the driver
%sourceObject is the one inflicting damage
%damage is the amount of damage dealt

Are these arguments right?
Btw, thanks Chrono for helping me out.

No no, you wouldn't use Armor::damage

You'd use WheeledVehicleData:: and FlyingVehicleData::

%this is the datablock.
%obj is the vehicle
bla bla bla

Oh sorry. That's what I meant anyhow, it was the arguments I got wrong.

so if I would want to message the driver after the vehicle took damage

Code: [Select]
messageClient(%obj.driver.client, 'bottom print', "Your vehicle took" SPC %damage SPC "damage.");

You wouldn't do that because if someone shot at the vehicle with a machine gun, the driver would get spammed.

I'd say stick to a right aligned center print, like this:

CenterPrint(%obj.getMountedObject(0).client,"<just:right><color:ffffff>Vehicle: <color:00ff00>" @  (1-%obj.getDamagePercent())*100 @ "%",3);

%obj is the vehicle
.getMountedObject(0) is the driver
.client is the driver's client
<just:right> puts the message to the right side of the screen.
(1-%obj.getDamagePercent())*100
%obj.getDamagePercent is a number between 0 and 1 to show how much damage the vehicle has taken.
1- that^ gets the health percent, multiply by 100 to get a number between 0 and 100.
3 shows the center print for 3 seconds.
Do this AFTER the Parent::damage

Code: [Select]
package NewPackage
{
function wheeledVehicle::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
Parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
        centerPrint(%obj.getMountedObject(0).client,"<just:right><color:ffffff>Vehicle: <color:00ff00>" @  (1-%obj.getDamagePercent())*100 @ "%",3);
}
};

activatePackage(NewPackage);

1. Chrono your ideas are as good as your add-ons, I like the right aligned thing.
2. Thank god for Package/Syntax Tutorial or else I would have had no idea what to do
3. I tried executing it but the console doesn't like it. Can someone help me wrap this up?
4. why won't simply %obj.driver.client work?

You forgot the ; at the end of Parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)