void dc_spin(int delay) {
if(typeof(delay) != openborconstant("VT_INTGER")) {
log("\n ERROR dc_spin(" + delay + ") - Missing or invalid parameter.");
return;
}
void acting_entity = getlocalvar("self");
// Zero, NULL(), or a negative delay switches the effect off.
if (!delay || delay < 0) {
setentityvar(acting_entity, "dc_spin_delay", 0);
setentityvar(acting_entity, "dc_spin_remaining", 0);
changedrawmethod(acting_entity, "rotate", 0);
changedrawmethod(acting_entity, "enabled", 0);
return;
}
// Restart the countdown only when the delay changes.
// Repeating the same command during an animation loop
// preserves both the countdown and the current angle.
if (getentityvar(acting_entity, "dc_spin_delay") != delay) {
setentityvar(acting_entity, "dc_spin_remaining", delay);
}
setentityvar(acting_entity, "dc_spin_delay", delay);
changedrawmethod(acting_entity, "enabled", 1);
}
void dc_spin_sentinel() {
void acting_entity = getlocalvar("self");
int delay = getentityvar(acting_entity, "dc_spin_delay");
int remaining;
int angle;
// Unset or zero means this entity is not spinning.
if (!delay) {
return;
}
remaining = getentityvar(acting_entity, "dc_spin_remaining") - 1;
if (remaining <= 0) {
// Advance two degrees whenever the countdown expires.
angle = (getdrawmethod(acting_entity, "rotate") + 2) % 360;
changedrawmethod(acting_entity, "rotate", angle);
remaining = delay;
}
setentityvar(acting_entity, "dc_spin_remaining", remaining);
}