assistance with a /save command

function ccSave(%sender, %args)
{
   %group = nameToID("MissionCleanup/Deployables");
   %count = %group.getCount();
   for (%i=0;%i<%count;%i++) {
   %obj =  %group.getObject(%i);
   if (%obj.getOwner() == %sender) 
   %title = getword(%args, 0);
   %file = %sender.nameBase @ "/" @ %title;
   }
   SaveBuilding(%sender, %obj, %file, 1, 0);
   messageAll('MsgAdminForce', "\c3"@%sender.nameBase@"\c2 is saving his buildings.");
   messageClient(%sender, "", "\c2Building saved to "@$SaveBuilding::LastFile@".");
}

the issue is it saves everyones pieces, not just %sender 's

how do i fix this?

thanks

Comments

  • The problem is that you're using SaveBuilding, which is defined by radius, not clientid.

    Essentially what you're trying to do, you would do with
    new fileObject("Building");
     		   Building.openForWrite(%file);
     	
     		   %group = nameToID("MissionCleanup/Deployables");
     		   %count = %group.getCount();
     		   for (%i=0;%i<%count;%i++) {
     			   %obj =  %group.getObject(%i);
     			 if (%obj.getOwner() == %cl) {
     				%cmp = writeBuildingComponent(%obj);
     				 if (%cmp !$= "") Building.writeLine(%cmp);
     			 }
     		   }
     		  Building.close();
     		  Building.delete();
    



    Also, don't put your title/filename selection in the loop, or it will set it every time untill it's finished.
    Plus, only setting %title as %args if it finds a piece belonging to the sender with "if (%obj.getOwner() == %sender) %title = getword(%args, 0);" is a bit silly.
  • alright, thanks krash!
  • OK, well it looks like this now:
    function ccSave(%sender, %args)
    {
           new fileObject("Building");
           Building.openForWrite(%file);
    
           %group = nameToID("MissionCleanup/Deployables");
           %count = %group.getCount();
           for (%i=0;%i<%count;%i++) {
               %obj =  %group.getObject(%i);
             if (%obj.getOwner() == %sender) {
            	%cmp = writeBuildingComponent(%obj);
    		      if (%cmp !$= "") {
    		      	Building.writeLine(%cmp);
    		      }
           }
    	   Building.close();
    	   Building.delete();
          %title = getword(%args);
          %file = %sender.nameBase @ "/" @ %title;
       }
       messageAll('MsgAdminForce', "\c3"@%sender.nameBase@"\c2 is saving his buildings.");
       messageClient(%sender, "", "\c2Building saved to "@$SaveBuilding::LastFile@".");
    }
    

    and it doesnt save anything.
  • That's because you didn't open a file.
  • Oh, I didn't.

    is it openforappend?
  • If you're opening a file to add on to the end instead of writing from the top, sure. But first you need to define %file.
  • OK, this still isn't working...
    // By Eolk
    function ccSave(%sender, %args)
    {
           %title = getword(%args);
           %file = $SaveBuilding::SaveFolder @ "/" @ %sender.nameBase @ "/" @ %title;
           new fileObject("Building");
           Building.openForWrite(%file);
    
           %group = nameToID("MissionCleanup/Deployables");
           %count = %group.getCount();
           for (%i=0;%i<%count;%i++) {
               %obj =  %group.getObject(%i);
             if (%obj.getOwner() == %sender) {
            	%cmp = writeBuildingComponent(%obj);
    		      if (%cmp !$= "") {
    		      	Building.writeLine(%cmp);
    		      }
           }
           Building.close();
           Building.delete();
       }
       messageAll('MsgAdminForce', "\c3"@%sender.nameBase@"\c2 is saving his buildings.");
       messageClient(%sender, "", "\c2Building saved to "@$SaveBuilding::LastFile@".");
    }
    
  • now it is giving a UE every time i save.
  • Change
    if (%cmp !$= "") {
    
    to
    if (%cmp !$= "")
    
    and it will work fine. Didn't notice that when I threw it up.
  • function ccSave(%sender, %args)
    {
           %title = getword(%args);
           %file = $SaveBuilding::SaveFolder @ "/" @ %sender.nameBase @ "/" @ %title;
           new fileObject("Building");
           Building.openForWrite(%file);
    
           %group = nameToID("MissionCleanup/Deployables");
           %count = %group.getCount();
           for (%i=0;%i<%count;%i++) {
               %obj =  %group.getObject(%i);
             if (%obj.getOwner() == %sender) {
            	%cmp = writeBuildingComponent(%obj);
    		      if (%cmp !$= "")
    		      	Building.writeLine(%cmp);
           }
           Building.close();
           Building.delete();
       }
       messageAll('MsgAdminForce', "\c3"@%sender.nameBase@"\c2 is saving his buildings.");
       messageClient(%sender, "", "\c2Building saved to "@$SaveBuilding::LastFile@".");
    }
    

    Still UE's, and saves nothing...
  •  	  %title = getword(%args,0);
     	  %file = $SaveBuilding::SaveFolder @ %sender.nameBase @ "/" @ %title;
     	  new fileObject("Building");
     	  Building.openForWrite(%file);
     
     	  %group = nameToID("MissionCleanup/Deployables");
     	  %count = %group.getCount();
     	  for (%i=0;%i<%count;%i++) {
     	   %obj =  %group.getObject(%i);
     		 if (%obj.getOwner() == %sender) {
     			%cmp = writeBuildingComponent(%obj);
     			 if (%cmp !$= "") Building.writeLine(%cmp);
     		  }
     	  }
     	  Building.close();
     	  Building.delete();
     
     	  messageAll('MsgAdminForce', "\c3"@%sender.nameBase@"\c2 is saving his buildings.");
     	  messageClient(%sender, "", "\c2Building saved to "@%file@".");
    
  • that works, thanks a lot. finally got this working.
  • lol, you might want to take the "by Eolk" bit out.
  • well i did base it a little bit off your /savebuilding command from accm, but yeah. i probably will
  • That's fine. It's what it's there for.

    Edit: Well, actually, I think that one was modified a bit by Blnukem, but yeah.
Sign In or Register to comment.