Got an other one. I was fooling arround, trying to create a "burst fire" effect for a weapon, and I finally did it, and it works, also. The downside is that the effect would only work properly if you use the F5, F6 or F7 keys, manually, not so much. Also, the AI can't seem to be able to fully use it (it would only fire one burst at you).
So, here it is:
MACHINE "Burst_Fire"
State Main
Rule event in
:action
SelectEx(s.this:Devtype=#*weapon*,
RequestFiredEvent(s.this,1);
);
:end
END
Rule event Fired
condition IsValid(E.location)&e.location:devtype=#*weapon*
:action
if(e.location:count=1,
EnableDevice(e.location,0);
weap:=e.location;
Timer(Reload,3,e.dev:=weap);
);
:end
END
Rule event Reload
:action
enabledevice(e.dev,1);
LoadWeapon(e.dev,10);
:end
END
END
END
The problem with this code is the fact that I had to use ammunition as a way to control the bursts, if only I could safely use a regular counter...
EDIT: Seriously, there's got to be something magical about this place, the solution came to me no more than 5 seconds after I finished posting this... perhaps it's the fact to express something out loud (in a figure of speech, that is), dunno.
Anyhow, all I had to do was to tell the weapon to open fire to the ship it was firing to before, if it existed, that is. It now works like a charm.
The revised code, if somebody wants it:
MACHINE "Burst_Fire"
State Main
Rule event in
:action
SelectEx(s.this:Devtype=#*weapon*,
RequestFiredEvent(s.this,1);
);
:end
END
Rule event Fired
condition IsValid(E.location)&e.location:devtype=#*weapon*
:action
if(e.location:count=1,
weap:=e.location;
targ:=e.location:target;
ownr:=e.location:owner;
Debug("The weapon's owner is", ownr, "and the target would be",targ);
EnableDevice(e.location,0);
Timer(Reload,3,e.dev:=weap;e.targ:=targ;e.ownr:=ownr);
);
:end
END
Rule event Reload
:action
enabledevice(e.dev,1);
LoadWeapon(e.dev,10);
Debug("The weapon's owner is", e.ownr, "and the target would be",e.targ);
if(IsValid(e.targ)&IsValid(e.ownr),
TargetWeapon(e.dev,e.targ);
);
:end
END
END
END