Author Topic: Curiosity: How did the v8 wrench event mod save events?  (Read 746 times)

This is perhaps a question for Space Guy - how did the old v8 wrench events addon save events?

I'm half-curious of it but I also feel that it might be useful in some way for *gasp* SAVING ALTERNATIVE VALUES ON BRICKS.
Or Badspot should implement a system for adding extra values that are saved on bricks. That'd be loving great. Hear me? loving great. Do it already. Please.

...it wasn't, by any chance, saving the transform and datablock of each brick with events, and loading made a box search at each evented brick's position, finding a brick matching that transform and datablock and adding events to it? I'm not entirely sure that'd be efficient but it seems viable and it's what came to mind, but there's probably some other/better way I couldn't figure.

Someone actually PMed me the original wrench events a few months ago; they wanted me to remake the lazer events or something. I have the link, but mediafire isn't working right now, so when it's up I'll edit it into this post.

(Or if someone knows the name of the .zip I can find it in my downloads folder with over 500+ items much more easily...)

EDIT:

Full add-on link removed, I guess it'd be considered releasing without author's consent.

Code: [Select]
function servercmdSaveEvents(%client,%file)
{
 %file = strReplace(%file,".Wsave","");
 if(%file $= "")
 {
  messageclient(%client,"\c5You need to choose a file to save to.");
  return;
 }
 %file = %file @ ".Wsave";
  messageclient(%client,'',"\c5Saving... (base/config/client/wrenchsaves/" @ %file @ ")");
 commandtoclient(%client,'clearwrenchsavefile',%file);
 for(%i=0;%i<$wrenchCtrl.count;%i++)
 {
  %val = $wrenchCtrl.getValue(%i);
  %str = "";
  commandtoclient(%client,'appendwrenchsavefile',%file,strReplace(%val.getposition()," ","_"),"CLEAR");
  commandtoclient(%client,'appendwrenchsavefile',%file,strReplace(%val.getposition()," ","_"),"MISC" SPC strReplace(%val.evGroup," ","_") SPC %val.evTrust);
  for(%j=0;%j<10;%j++)
  {
   commandtoclient(%client,'appendwrenchsavefile',%file,strReplace(%val.getposition()," ","_"),
   "EVENT" TAB
   strReplace(%val.evName[%j]," ","_") TAB
   %val.evState[%j] TAB
   %val.evGroup TAB
   strReplace(%val.evParam[%j,0]," ","_") TAB
   strReplace(%val.evParam[%j,1]," ","_") TAB
   strReplace(%val.evParam[%j,2]," ","_") TAB
   strReplace(%val.evParam[%j,3]," ","_") TAB
   strReplace(%val.evParam[%j,4]," ","_"));
  }
 }
  messageclient(%client,'',"\c5Finished.");
}
« Last Edit: June 03, 2009, 05:43:53 PM by Truce »


EDIT:

Full add-on link removed, I guess it'd be considered releasing without author's consent.


NOOOO, i was too late. i need that for making a database

It used a separate file. The system was hard for some people to understand. Please do not use this system if it is possible to avoid it.

I'm more interested in simply the way it found the bricks to add the events to when loading it. I'm interested in this because I want to be able to save per-brick values, specifically, upgrades on certain special bricks - the mod I'm planning it for isn't something I'd release publicly, so ease of use isn't a big factor for me. I just want to know the backend method that was being used for loading.

Code: [Select]
function loadEvents(%client,%file)
{
 %oldbrick = %client.wrenchbrick;
 %f = new fileobject();
 %f.openForRead(%file);
 %count = 0;
 %typecount = 0;
 for(%i=0;(%line=%f.readLine()) !$= "";%i++)
 {
  if(%line $= ""){continue;}
  %p = getWord(%line,0); //firstWord doesn't take into account TAB
  initContainerBoxSearch(strReplace(%p,"_"," "),"0.1 0.1 0.1",$TypeMasks::FXBrickObjectType);
  %obj = containerSearchNext();
  if(!%type[%p]){%type[%p] = 1;%typecount++;}
  if(!isObject(%obj) || %obj.isDead() || !%obj.isPlanted){continue;}
  if(!%found[%p]){%found[%p] = 1;%count++;}
  %client.wrenchbrick = %obj;
  if(getWord(%line,1) $= "CLEAR")
  {
   servercmdClearWrenchEvents(%client);
  }
  else if(getWord(%line,1) $= "MISC")
  {
   servercmdWrenchEvGroup(%client,strReplace(getWord(%line,2),"_"," "),getWord(%line,3));
  }
  else
  {
   //%client,%type,%length,%group,%e0,%e1,%e2,%e3,%e4
   if(getWord(%line,2) !$= "")
   {
    servercmdWrenchEventAdd(%client,
strReplace(getWord(%line,2),"_"," "),
strReplace(getWord(%line,3),"_"," "),
strReplace(getWord(%line,4),"_"," "),
strReplace(getWord(%line,5),"_"," "),
strReplace(getWord(%line,6),"_"," "),
strReplace(getWord(%line,7),"_"," "),
strReplace(getWord(%line,8),"_"," "),
strReplace(getWord(%line,9),"_"," "),
strReplace(getWord(%line,10),"_"," "));
   }
  }
 }
 %f.close();
 %f.delete();
 messageall('MsgProcessComplete',"\c0" @ %count @ " / " @ %typecount @ " bricks loaded successfully.");
 %client.wrenchbrick = %oldbrick;
}

This method is probably very slow as it does a container search for every single loading line.

What you could try to do is a clientside hack of the save file to add your parts in the saving procedure (e.g. "+-LEVEL 3" in accordance with the others) and then use $LastLoadedBrick during the loading procedure. As nobody but you would be saving the levels of bricks, this method would work.

Ahaa. Thanks very much, and good idea.

Lockin' since it's solved.