Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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 == 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);
  }


Last edited by DustyPorViva; 01-06-2010 at 02:02 PM..
Reply With Quote
  #2  
Old 01-06-2010, 12:58 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Heh, that's pretty awesome. I never thought of doing it this way. Nice work.
__________________
Reply With Quote
  #3  
Old 01-06-2010, 01:05 AM
cyan3 cyan3 is offline
Registered User
cyan3's Avatar
Join Date: Nov 2005
Location: England
Posts: 2,919
cyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant future
Nice idea
Reply With Quote
  #4  
Old 01-06-2010, 01:07 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Nice
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
Old 01-06-2010, 01:09 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #6  
Old 01-06-2010, 01:20 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
Quote:
Originally Posted by LoneAngelIbesu View Post
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.
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.
Reply With Quote
  #7  
Old 01-06-2010, 01:40 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You just saved me some time down the road with this one!

Edit: The comments look angry.
__________________
Quote:

Last edited by fowlplay4; 01-06-2010 at 06:30 AM..
Reply With Quote
  #8  
Old 01-06-2010, 02:01 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
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.
Reply With Quote
  #9  
Old 01-06-2010, 05:51 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
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.
Reply With Quote
  #10  
Old 01-06-2010, 06:01 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #11  
Old 01-06-2010, 02:06 PM
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
Quote:
Originally Posted by fowlplay4 View Post
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.
Reply With Quote
  #12  
Old 01-07-2010, 12:47 AM
DarkReaper0 DarkReaper0 is offline
No.
DarkReaper0's Avatar
Join Date: May 2005
Location: Texas,USA
Posts: 344
DarkReaper0 will become famous soon enough
Send a message via MSN to DarkReaper0
Thank you so much, this will make using setshape for our online needs a tad easier
Reply With Quote
Reply


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 11:51 PM.


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