Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-06-2010, 12:48 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Setshape2 generator

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.
Click image for larger version

Name:	graal_1262687868.png
Views:	1101
Size:	46.9 KB
ID:	50141
Click image for larger version

Name:	graal_1262722856.png
Views:	1135
Size:	56.0 KB
ID:	50142
And just for the hell of it!
Click image for larger version

Name:	graal_1262722921.png
Views:	1150
Size:	281.5 KB
ID:	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 == true) SaveSelection(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;
      
x = (screenwidth - width)/2;
      
y = (screenheight - height)/2;
      
minextent = {width,height};
      
text = "SetShape2 Output";
    
      new 
GuiScrollCtrl("Dusty_ss2_scroll") {
        
profile = GuiBlueScrollProfile;
        
x = 10;
        
y = 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};
          
x = 5;
          
y = 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;
        
x = Dusty_ss2_scroll.x;
        
y = Dusty_ss2_scroll.y + 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;
        
x = Dusty_ss2_Win.width - width - 10;
        
y = Dusty_ss2_indents.y;
        
text = "Close";
      }

      new 
GuiCheckBoxCtrl("Dusty_ss2_chkbox") {
        
profile = GuiBlueCheckBoxProfile;
        
x = Dusty_ss2_indents.x + Dusty_ss2_indents.width + 10;
        
y = 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(" @ w @ "," @ h @ ",{";
  for (
temp.i=0;i<arr.size();i++) {
    
// CREATE A NEW LINE WHEN ARRAY VALUE EXCEEDS WIDTH OF SELECTION
    
if (i%w == 0) output[int(i/w)+1] = indent @ "  " @ arr[i] @ (arr[i].length() == 1 ? " " : "") @ ",";
    
// OTHERWISE APPEND THE REST OF THE ARRAY
    
else output[int(i/w)+1] @= arr[i] @ (arr[i].length() == 1 ? " " : "") @ ",";
  }
  
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.y = Dusty_ss2_scroll.y + Dusty_ss2_scroll.height + 3;
  
Dusty_ss2_closebtn.x = nw - Dusty_ss2_closebtn.width - 10;
  
Dusty_ss2_closebtn.y = Dusty_ss2_indents.y;
  
Dusty_ss2_chkbox.y = 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);
  }
} 

Last edited by DustyPorViva; 01-06-2010 at 02:02 PM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:23 AM.


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