Author Topic: Change item image rate of fire on the fly?  (Read 977 times)

I've spent hours trying to figure this out only to come to the conclusion it's not possible. I've tried the obvious stateTimeoutValue[x] edits in-game, etc.

Right now, what I'm doing, is dynamically creating shapeBaseImageData datablocks when the server starts to use at a later point when they're needed, and modifying HammerItem to use the image I want.
They create themselves fine, but it's tedious and the hammer just hits my face when using the modified images.

I can resort to having a click/activate-only method but I'd rather have an item because it's apparently confusing to Blockland players. It looks less lazy too.

Code: [Select]
function convertTempoToMS(%tempo) {
return 60000/%tempo;
}

function initPickaxes() {
%file = new FileObject();

if(!isFile("config/server/MinerTeams/loops.db")) {
%file.openForRead("config/server/MinerTeams/loops/loops.db");
} else {
warn("NO LOOP DATABASE FOUND.");
%file.delete();
return;
}

%tempScript = new FileObject();

while(!%file.isEOF()) {
%data = %file.readLine();

%tempo = getField(%data, 1);
%tempoMS = convertTempoToMS(%tempo);

%datablock = "PickaxeImage_" @ strReplace(%tempo, ".", "_");

if(!isObject(%datablock)) {
echo("Creating dynamic datablock for tempo of" SPC %tempo @ "BPM...");

%tempScript.openForWrite("config/server/MinerTeams/temp.cs");

// this is just too much to eval fml
// dynamic item images when
%tempScript.writeLine("datablock shapeBaseImageData(" @ %datablock @ " : hammerImage) {");
%tempScript.writeLine("stateTimeoutValue[1] = 0;");
%tempScript.writeLine("stateTimeoutValue[2] = 0.01;");
%tempScript.writeLine("stateTimeoutValue[3] = " @ ((%tempoMS/2)/1000)-0.01 @ ";");
%tempScript.writeLine("stateTimeoutValue[4] = 0;");
%tempScript.writeLine("stateTimeoutValue[5] = " @ ((%tempoMS/2)/1000)-0.01 @ ";");
%tempScript.writeLine("stateTimeoutValue[6] = 0;");
%tempScript.writeLine("rotation = eulerToMatrix(\"0 0 0\");");
%tempScript.writeLine("mountPoint = 0;");
%tempScript.writeLine("offset = \"0 0 0\";");
%tempScript.writeLine("emap = true;");
%tempScript.writeLine("eyeOffset = \"0 0 0\";");
%tempScript.writeLine("};");
%tempScript.writeLine("function " @ %datablock @ "::onHitObject(%this, %obj, %slot, %col, %d, %e, %f) {");
%tempScript.writeLine("hitObject(%this, %obj, %slot, %col, %d, %e, %f);");
%tempScript.writeLine("}");

%tempScript.close();

exec("config/server/MinerTeams/temp.cs");
}
}

%tempScript.delete();
%file.close();
%file.delete();
}

You still have to go out of the way to remove the old hammer from everyone's inventory, then add it back.

Is there a better way to do this or does TGE suck this bad?

sounds like the only way to handle this correctly is writing the onfire method to check for timeout, and making all the base timeouts in the sequences 0 or something

Oh yay something I think I can help with. How I'd do that is use the OnLoaded state system along with stateScript[] = "whatever".

So for example, it goes to the "Wait" state and is stuck in there until you load it with the script. To do this, you have stateScript[] = "onWait",

Code: [Select]
function shapeBaseImageData::onWait(%this,%obj,%data){
%waitTime = getRandom(maxWaitTime, minWaitTime);

schedule(%waitTime,0, %obj.setImageLoaded,0,1); //loading the weapon
schedule(%waitTime+1,0,%obj.setImageLoaded,0,0);
}

All you need then is
Code: [Select]
stateTransitionOnLoaded[#] = "Fire"; and I hope it then fires at a random time. If you didn't want it random just change how it gets the wait times.

EDIT: The added bonus is it takes 1 datablock
« Last Edit: February 18, 2016, 02:25:24 PM by Jervan »

since the hammer is a very simple you could literally code the hammer without even using the state system using armor::onTrigger

Leaving unsolved in case anyone else comes across the issue, using %player.playThread(1, activate) and armor::onTrigger with some scheduled loops instead.