Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Setshape2 generator (https://forums.graalonline.com/forums/showthread.php?t=134257548)

DustyPorViva 01-06-2010 12:48 AM

Setshape2 generator
 
3 Attachment(s)
Made this little script up at the spur of the moment. With larger setshape's I know it can be a pain to make via text so I made this up. It works in game by holding 'T' and making a selection of tiles with your mouse(this means you should lay the shape out in the level first), when you let go of your mouse it will pop up with the code. Let go of 'T' first to cancel it. After the code pops up you can change the indentation to more easily copy/paste into your code(in case you may need to put it in a few nested statements). Newly added GS1 option as well.
Attachment 50141
Attachment 50142
And just for the hell of it!
Attachment 50143
PHP Code:

//#CLIENTSIDE
function onKeyPressed(keycode,key) {
  if (
key == "t"setTimer(0.05);
}

function 
onTimeout() {
  if (
keydown2(keycode(t),true)) {
    if (
leftmousebutton) {
      if (!
this.mousepressed) {
        
this.origmouse = {int(mousex+.5),int(mousey+.5)};
        
this.mousepressed true;
      } else {
        
this.newmouse = {int(mousex+.5),int(mousey+.5)};
        
this.selectionpos = {{this.origmouse[0],this.origmouse[1]},{this.newmouse[0],this.newmouse[1]}};
        
// IF MOUSE POSITION IS BEHIND ORIGINAL CLICK, FLIP SELECTION HORIZONTALLY
        
if (this.selectionpos[1][0] < this.selectionpos[0][0]) {
          
this.selectionpos[0][0] = this.newmouse[0];
          
this.selectionpos[1][0] = this.origmouse[0];
        }
        
// IF MOUSE POSITION IS BEHIND ORIGINAL CLICK, FLIP SELECTION VERTICALLY
        
if (this.selectionpos[1][1] < this.selectionpos[0][1]) {
          
this.selectionpos[0][1] = this.newmouse[1];
          
this.selectionpos[1][1] = this.origmouse[1];
        }
        
ShowSelection();
      }
    } else {
      if (
this.mousepressed == trueSaveSelection(this.selectionpos[0],this.selectionpos[1]);
      
hideimgs(200,201);
      
this.mousepressed false;
    }
    
setTimer(0.05);
  } else {
    
this.mousepressed false;
    
hideimgs(200,201);
  }
}

function 
ShowSelection() {
  
// BLACK OUTLINE
  
showpoly(200,{
    
// OUTLINE
    
this.selectionpos[0][0]-(3/16),this.selectionpos[0][1]-(3/16),
    
this.selectionpos[1][0]+(3/16), this.selectionpos[0][1]-(3/16),
    
this.selectionpos[1][0]+(3/16), this.selectionpos[1][1]+(3/16),
    
this.selectionpos[0][0]-(3/16),this.selectionpos[1][1]+(3/16),
    
this.selectionpos[0][0]-(3/16),this.selectionpos[0][1]-(3/16),
    
// INTERIOR
    
this.selectionpos[0][0],this.selectionpos[0][1],
    
this.selectionpos[1][0], this.selectionpos[0][1],
    
this.selectionpos[1][0], this.selectionpos[1][1],
    
this.selectionpos[0][0],this.selectionpos[1][1],
    
this.selectionpos[0][0],this.selectionpos[0][1],
  });
  
changeimgvis(200,0);
  
changeimgmode(200,2);
  
changeimgcolors(200,1,1,1,.65);
  
// WHITE OUTLINE
  
showpoly(201,{
    
// OUTLINE
    
this.selectionpos[0][0]-(1/16),this.selectionpos[0][1]-(1/16),
    
this.selectionpos[1][0]+(1/16), this.selectionpos[0][1]-(1/16),
    
this.selectionpos[1][0]+(1/16), this.selectionpos[1][1]+(1/16),
    
this.selectionpos[0][0]-(1/16),this.selectionpos[1][1]+(1/16),
    
this.selectionpos[0][0]-(1/16),this.selectionpos[0][1]-(1/16),
    
// INTERIOR
    
this.selectionpos[0][0],this.selectionpos[0][1],
    
this.selectionpos[1][0], this.selectionpos[0][1],
    
this.selectionpos[1][0], this.selectionpos[1][1],
    
this.selectionpos[0][0],this.selectionpos[1][1],
    
this.selectionpos[0][0],this.selectionpos[0][1],
  });
  
changeimgvis(201,1);
}

function 
SaveSelection(om,nm) {
  
temp.selectionwidth nm[0] - om[0];
  
temp.selectionheight nm[1] - om[1];
  
temp.tilearray = new[selectionwidth selectionheight];
  if (
tilearray.size() == 0) return; // STOP IF THERE IS NO SELECTION
  
for (temp.i=0;i<tilearray.size();i++) {
    
tilearray[i] = tiletype(om[0]+(i%selectionwidth),om[1]+int(i/selectionwidth));
  }
  
RenderOutput(tilearray,selectionwidth,selectionheight);
}

function 
RenderOutput(arr,w,h) {
  
// CREATE NEW GUI IF THERE ISN'T ONE ALREADY PRESENT
  
if (Dusty_ss2_Win.text == null) {
    new 
GuiWindowCtrl("Dusty_ss2_Win") {
      
profile GuiBlueWindowProfile;
      
width 300;
      
height 200;
      
= (screenwidth width)/2;
      
= (screenheight height)/2;
      
minextent = {width,height};
      
text "SetShape2 Output";
    
      new 
GuiScrollCtrl("Dusty_ss2_scroll") {
        
profile GuiBlueScrollProfile;
        
10;
        
28;
        
width Dusty_ss2_Win.width - (x*2);
        
height Dusty_ss2_Win.height - (x+y) - 25;
        
hScrollBar "dynamic";
        
vScrollBar "dynamic";

        new 
GuiMLTextCtrl("Dusty_ss2_output") {
          
profile GuiBlueMLTextProfile;
          
useownprofile true;
          
profile.fonttype "courier new";
          
profile.fontcolor = {255,255,255,255};
          
5;
          
2;
          
width Dusty_ss2_scroll.width - (Dusty_ss2_scroll.x*4);
          
height Dusty_ss2_scroll.height;
          
wordwrap false;
          
text "";
        }
      }

      new 
GuiTextEditSliderCtrl("Dusty_ss2_indents") {
        
profile GuiBlueTextEditSliderProfile;
        
Dusty_ss2_scroll.x;
        
Dusty_ss2_scroll.Dusty_ss2_scroll.height 5;
        
width 80;
        
height 20;
        
format "Indent: %d";
        
range = {0,20};
        
value 1;
      }

      new 
GuiButtonCtrl("Dusty_ss2_closebtn") {
        
profile GuiBlueButtonProfile;
        
width 80;
        
height 20;
        
Dusty_ss2_Win.width width 10;
        
Dusty_ss2_indents.y;
        
text "Close";
      }

      new 
GuiCheckBoxCtrl("Dusty_ss2_chkbox") {
        
profile GuiBlueCheckBoxProfile;
        
Dusty_ss2_indents.Dusty_ss2_indents.width 10;
        
Dusty_ss2_indents.y;
        
width 100;
        
height 20;
        
text " GS1";
      }

    }
  }
  
Dusty_ss2_indents.value 1;  // RESET INDENT
  
Dusty_ss2_chkbox.checked 0// RESET GS1
  
Dusty_ss2_Win.show();
  
// THIS WILL BE OUR INDENT 'TEMPLATE'
  
temp.emptyspace "                                          ";

  
temp.output = new[int(arr.size()/w)+2];
  
temp.indent emptyspace.substring(0,Dusty_ss2_indents.value*2);
  
output[0] = indent "setshape2(" "," ",{";
  for (
temp.i=0;i<arr.size();i++) {
    
// CREATE A NEW LINE WHEN ARRAY VALUE EXCEEDS WIDTH OF SELECTION
    
if (i%== 0output[int(i/w)+1] = indent "  " arr[i] @ (arr[i].length() == " " "") @ ",";
    
// OTHERWISE APPEND THE REST OF THE ARRAY
    
else output[int(i/w)+1] @= arr[i] @ (arr[i].length() == " " "") @ ",";
  }
  
output[int(arr.size()/w)+1] = indent "});";
  
Dusty_ss2_output.text "";
  
Dusty_ss2_output.setlines(output);
}

// REFORM CONTROLS ON RESIZE
function Dusty_ss2_Win.onResize(nw,nh) {
  
Dusty_ss2_scroll.width nw - (Dusty_ss2_scroll.x*2);
  
Dusty_ss2_scroll.height nh - (Dusty_ss2_scroll.x+Dusty_ss2_scroll.y) - 23;
  
Dusty_ss2_indents.Dusty_ss2_scroll.Dusty_ss2_scroll.height 3;
  
Dusty_ss2_closebtn.nw Dusty_ss2_closebtn.width 10;
  
Dusty_ss2_closebtn.Dusty_ss2_indents.y;
  
Dusty_ss2_chkbox.Dusty_ss2_indents.y;
}

// DESTROY WINDOW WHEN CLOSE BUTTON IS HIT
function Dusty_ss2_closebtn.onAction() {
  
Dusty_ss2_Win.destroy();
}

// REPLACE GS2 WITH GS1 AND VICE-VERSA WHEN CHECKBOX IS TOGGLED
function Dusty_ss2_chkbox.onAction() {
  if (
Dusty_ss2_chkbox.checked) {
    
Dusty_ss2_output.text shared.replacetext(Dusty_ss2_output.text,"setshape2(","setshape2 ");
    
Dusty_ss2_output.text shared.replacetext(Dusty_ss2_output.text,"});","};");
  } else {
    
Dusty_ss2_output.text shared.replacetext(Dusty_ss2_output.text,"setshape2 ","setshape2(");
    
Dusty_ss2_output.text shared.replacetext(Dusty_ss2_output.text,"};","});");
  }
}

// APPARENTLY TEXTEDITSLIDERS DON'T CALL ONACTION, SO I HAD TO HACK THIS UP
function Dusty_ss2_indents.onMouseDown() {
  while (
leftmousebuttonglobal) {
    
// LOOP THROUGH LINES OF TEXT TO RE-INDENT
    
temp.emptyspace "                                          ";
    
temp.indent emptyspace.substring(0,Dusty_ss2_indents.value*2);
    
temp.output Dusty_ss2_output.getlines();
    for (
temp.i=0;i<output.size();i++) {
      
// GET RID OF PREVIOUS NEWLINES AS TO AVOID CREATING MANY BLANK NEWLINES
      
output[i] = shared.replacetext(output[i],"\n","");
      
// TRIM OLD INDENTS
      
output[i] = output[i].trim();
      
// ADD NEW INDENT
      
output[i] = (i in |1,output.size()-2| ? "  " "") @ indent output[i];
    }
    
Dusty_ss2_output.text "";
    
Dusty_ss2_output.setlines(output);
    
sleep(0.05);
  }



cbk1994 01-06-2010 12:58 AM

Heh, that's pretty awesome. I never thought of doing it this way. Nice work.

cyan3 01-06-2010 01:05 AM

Nice idea :)

Tigairius 01-06-2010 01:07 AM

Nice :)

LoneAngelIbesu 01-06-2010 01:09 AM

If you're inclined, a GUI where you can 'draw' the shape over an NPC image, and where you can choose the tiletype to draw, would be very awesome. Essentially, you would select an image, which would be shown inside a GUI. From there, you select your tiletype and click on parts of the image.

Every now and then, I get the urge to make something like that. I'm always too lazy, though.

This script should help out a lot of LATs. Good job. :D

DustyPorViva 01-06-2010 01:20 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1548463)
If you're inclined, a GUI where you can 'draw' the shape over an NPC image, and where you can choose the tiletype to draw, would be very awesome. Essentially, you would select an image, which would be shown inside a GUI. From there, you select your tiletype and click on parts of the image.

Every now and then, I get the urge to make something like that. I'm always too lazy, though.

This script should help out a lot of LATs. Good job. :D

I have to admit, this idea intrigues me a lot... but I wonder if it'll really be worth the effort in the end. I'm wondering if the benefit of it all being in one integrated system would actually be that noticeable. Especially when you consider that people are more familiar and comfortable working with tiles(pics1) than say, a color-coded layout of blocks to define the tiles. In the end I'd have a system that replicated all the functions of a level editor(in order for it to be as familiar as possible, it'd have to function like the level editor with bucket-fill and such), but for a very simple purpose. Ideally something like this would work way better in a level editor itself, like the hex-generator, than as a stand-alone, but that's not really possible to do.

fowlplay4 01-06-2010 01:40 AM

You just saved me some time down the road with this one!

Edit: The comments look angry.

DustyPorViva 01-06-2010 02:01 AM

Well added a GS1 checkbox that will toggle between GS1 and GS2, since I figured this is something that would be used in the offline level editing as well.

12171217 01-06-2010 05:51 AM

This is really cool!

Cool stuff, I'm now going to experiment with setshape2. I was never aware of the potential this command actually has.

LoneAngelIbesu 01-06-2010 06:01 AM

Quote:

Originally Posted by DustyPorViva (Post 1548467)
I have to admit, this idea intrigues me a lot... but I wonder if it'll really be worth the effort in the end. I'm wondering if the benefit of it all being in one integrated system would actually be that noticeable. Especially when you consider that people are more familiar and comfortable working with tiles(pics1) than say, a color-coded layout of blocks to define the tiles. ...

I personally think it would be valuable. Valikorlia is uses NPCs for so many different things that can't easily be replicated in tiles. For a large block of trees, which are used to make a kind of modular forest, it took me about a half our to get the setshape2 right, so that players are able to walk through it.

It does sound like a lot of work, though, which is why I've never tackled the project myself.

DustyPorViva 01-06-2010 02:06 PM

Quote:

Originally Posted by fowlplay4 (Post 1548481)
Edit: The comments look angry.

lol I tend to cap my comments so they're easily distinguishable from the code at a glance, rather than hunting through.

DarkReaper0 01-07-2010 12:47 AM

Thank you so much, this will make using setshape for our online needs a tad easier :D


All times are GMT +2. The time now is 07:09 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.