Graal Forums  

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

View Poll Results: Is this a good idea?
Yes 33 100.00%
No 0 0%
Voters: 33. You may not vote on this poll

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-07-2006, 01:33 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Ok. I have made an example for the second lesson - a practical based lesson. 400 lines of code but not all mine (<3 Jamilla/Novo) and comments/styling help to fill up that number. This also forced me to use 2 posts . No ripping off my tripple post

PHP Code:
/* Lesson 2 : Practical */
//#CLIENTSIDE
function onCreated()
  
addGUIControls();

function 
onWeaponFired()
  
showLesson();
  
public function 
showLesson()
{
  new 
GuiWindowCtrl("Lesson2Window")
  {
    
profile       "GuiBlueWindowProfile";
    
extent        "450 300";
    
position      "5 5";
    
text          "Lesson 2 : Practical Lesson. By Twinny";
    
destroyonhide true;
    
canmaximize   false;
    
canresize     false;
    
    new 
GuiTextCtrl("Lesson2Title")
    {
      
profile          "GuiBlueTextProfile";
      
position         "10 25";
      
profile.fontsize 40;
      
text "Practical Lesson on Objects";
    }
    
    new 
GuiScrollCtrl("Lesson2Scroll")
    {
      
profile    "GuiBlueScrollProfile";
      
position   "15 75";
      
extent     "420 140";
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
visible    true;
      
canmove    true;
    
      new 
GuiMLTextCtrl("Lesson2Body")
      {
        
profile  "GuiBlueMLTextProfile";
        
position "5 5";
        
extent   "390 110";
      }
    }
    new 
GuiButtonCtrl("Lesson2Prac1")
    {
      
profile  "GuiBlueButtonProfile";
      
position "15 220";
      
extent   "420 30";
      
text     "Practical Lesson 1";
    }
    new 
GuiButtonCtrl("Lesson2Prac2")
    {
      
profile  "GuiBlueButtonProfile";
      
position "15 255";
      
extent   "420 30";
      
text     "Practical Lesson 2";
    }
          
  }
  
GraalControl.addControl(Lesson2Window);
  
setLesson();
}

function 
setLesson()
{
  
Lesson2Body.setText(
  
"Below are two practical lessons. The first prac lesson is a
  basic lesson. It shows all the functions, objects and variables
  contained within an object of your choosing." 
NL "" NL
  
  
"The second lesson is a bit more advanced. The second lesson 
  shows the interconnected ness of objects within graal.
  Objects and arrays can be expanded. The functions and variables
  are present just to show you what is in each object you find." 
NL "" NL
  
  
"Next lesson will involve some questions based on objects as well 
  as some examples and tasks. It is hoped by then you will have a 
  basic understanding of objects. All credit for the practical lessons
  should go to Jamilla/Novo. I modified the first practical lesson
  a fair bit but the second one is generally the same as his
  original work. Ask the lesson provider if you wish to receive
  the practical lesson's code." 
NL "" NL
  
  
"As always if this lesson was confusing as hell - just mail me at
  [email protected]"
  
);
}

function 
Lesson2Prac1.onAction()
  
showPrac1();

function 
Lesson2Prac2.onAction()
{
  if (
this.on
    
turnoff();
  else
    
turnon();
}
  
/* And now for the practical lessons. Once more - credit
goes to Jamilla/Novo */

/* Practical Lesson 1 */
/* Modified quite a bit */
function showPrac1()
{
  new 
GuiWindowCtrl("L2P1")
  {
    
profile  "GuiBlueWindowProfile";
    
position "5 5";
    
extent   "450 300";
    
text     "Lesson 2 : Practical 1. By Twinny";
    
destroyonhide true;
    
canmaximize   false;
    
canresize     false;
  
    new 
GuiTextCtrl("L2Prac1Title")
    {
      
profile  "GuiBlueTextProfile";
      
profile.fontsize 22;
      
position "90 25";
      
text     "Select your object than parse";
    }
    
    new 
GuiPopUpMenuCtrl("L2Prac1PopUp")
    {
      
profile "GuiBluePopUpMenuProfile"// -_-
      
position "10 55";
      
extent   "280 25";
    }
    new 
GuiButtonCtrl("L2Prac1B1")
    {
      
profile  "GuiBlueButtonProfile";
      
position "300 55";
      
extent   "140 25";
      
text     "Parse";
    }
    new 
GuiScrollCtrl("L2Prac1Scroll")
    {
      
profile    "GuiBlueScrollProfile";
      
position   "15 90";
      
extent     "420 200";
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
visible    true;
      
canmove    true;
    
      new 
GuiMLTextCtrl("L2Prac1Dump")
      {
        
profile  "GuiBlueMLTextProfile";
        
position "5 5";
        
extent   "390 180";
      }
    }
  }
  
GraalControl.addControl(L2P1);
  
setObjects();
}

function 
setObjects()
{
  
temp.objs = {"Player","Level""Allplayers",
  
"Allplayers[1]""GuiControl","Weapon"};
  for (
tp temp.objs)
    
L2Prac1PopUp.addrow(1,tp);
}

function 
L2Prac1B1.onAction()
{
  
L2Prac1Dump.text "";
  if (
L2Prac1PopUp.text == "Player")
    
var_dump(player);
  else if (
L2Prac1PopUp.text == "Level")
    
var_dump(player.level);
  else if (
L2Prac1PopUp.text == "Allplayers")
    
var_dump(allplayers);
  else if (
L2Prac1PopUp.text == "Allplayers[1]")
    
var_dump(allplayers[1]);
  else if (
L2Prac1PopUp.text == "GuiControl")
    
var_dump(new GuiControl(Test));
  else if (
L2Prac1PopUp.text == "Weapon")
    
var_dump(player.weapon);  
}

function 
var_dumpobj )
{
  if ( 
obj.type() in {0,1,3} )
  {
    
L2Prac1Dump.addtextobj SPC "=" SPC ParseValuemakevar(obj) ) @";" NL "",);
    return 
true;
  }
  
L2Prac1Dump.addtext"new" SPC obj.objectType() @"(\""obj.name @"\"){" NL "",);
  
temp.functions obj.getFunctions();
  for ( 
temp.functemp.functions )
    
L2Prac1Dump.addtext("  function" SPC temp.func@"()" NL "",1);
  
temp.vars obj.getVarNames();
  for (
temp.varitemp.vars )
    
L2Prac1Dump.addtext"  "temp.vari SPC "=" SPC ParseValueobj.(@ temp.vari ) ) @";" NL "",1);
  
L2Prac1Dump.addtext"};" NL "",);
}

function 
ParseValueobj )
{
  switch ( 
obj.type() )
  {
    case 
"0":
      return 
obj;
    case 
"1":
      return 
"\""obj @"\"";
    case 
"2":
      return 
obj.objectType();
    case 
"3":
      
temp.arr "{";
      
temp.0;
      for ( 
temp.subobjobj )
      {
        
temp.arr @= ParseValuetemp.subobj );
        if ( 
temp.!= obj.size() - 1)
          
temp.arr @= ", ";
        
temp.++;
      }
      
temp.arr @= "}";
      return 
temp.arr;
    break;
  }

Second practical example found below.
Reply With Quote
  #2  
Old 10-07-2006, 01:35 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
And now : the conclusion

PHP Code:
/* Practical Lesson 2 */

function turnon()
{
  
this.on true;
  
GUIContainer.addControlDebugger_Window );
  
Debugger_Window.show();
  
getNodes();
}

function 
onPlayerEnters()
{
  if ( !
this.on )
    return;
  
Debugger_Tree.clearnodes();
  
getNodes();
}

function 
turnoff()
{
  
this.on false;
  
Debugger_Tree.clearnodes();
  
Debugger_Window.hide();
}

function 
addGuiControls()
{
  new 
GuiWindowCtrl("Debugger_Window" )
  {
    
profile "GuiBlueWindowProfile";
    
position "440 0";
    
width 600;
    
height GUIContainer.height;
    
canMove canClose canMinimize true;
    
canResize canMaximize false;
    
text "Object Browser";
    
visible false;

    new 
GuiScrollCtrl("Debugger_Scroll") {
      
profile "GuiBlueScrollProfile";
      
horizSizing "width";
      
vertSizing "height";
      
position "5 23";
      
extent "590" SPC Debugger_Window.height 28;
      
willFirstRespond true;
      
hScrollBar "dynamic";
      
vScrollBar "alwaysOn";
      
tile true;

      new 
GuiTreeViewCtrl("Debugger_Tree") {
        
profile "GuiBlueTreeViewProfile";
        
0;
        
fitparentwidth true;
        
clearnodes();
      }
    }
  }
}

function 
getNodes()
{
  
CaddNodeDebugger_Treeallplayers"allplayers" );
  
CaddNodeDebugger_Treeplayers"players" );
  
CaddNodeDebugger_Treeplayer"player" );

  
CaddNodeDebugger_Treenpcs"npcs" );
  
CaddNodeDebugger_Treeplayer.weapons"weapons" );
  
CaddNodeDebugger_Treeplayer.level"level" );


  
CaddNodeDebugger_Treecompus"compus" );
  
CaddNodeDebugger_Treebombs"bombs" );
  
CaddNodeDebugger_Treearrows"arrows" );
  
CaddNodeDebugger_Treeitems"items" );
  
CaddNodeDebugger_Treehorses"horses" );
  
CaddNodeDebugger_Treesigns"signs" );

  
CaddNodeDebugger_TreeGUIContainer"GUIContainer" );
  
CaddNodeDebugger_TreeGraalControl"GraalControl" );
}

function 
Debugger_Tree.onSelectnode )
{
  
with node )
  {
    
clearnodes();
    switch ( 
this.nodereturn.type() )
    {
      case 
"0": case "1":
        
CaddNodenodenode.nodereturnnode.nodeparent @"."node.nodename );

        
temp.getObjKeysnode.nodeparent @"."node.nodename @"." );
        for ( 
temp.vtemp.)
          
CaddNodenodenode.nodereturn.(@ temp.), node.nodename @"."temp.);
      break;
      case 
"2":
        
temp.node.nodereturn.getFunctions();
        
CaddNodenodetemp.f"functions" );
        
temp.node.nodereturn.getVarNames();
        for ( 
temp.vtemp.)
          {
          if ( (
temp.v in temp.check) )
            continue;
          
temp.check.addtemp.);

          
temp.getObjKeysnode.nodereturntemp.@".");//.getVarNames();
          
for ( temp.ktemp.)
            
CaddNodenodemakevar("node.nodereturn."temp.@"."@temp.k) , temp.@"."temp.);
          
CaddNodenodemakevar("node.nodereturn."temp.v) , temp.);
          }
      break;
      case 
"3":
        for ( 
temp.0temp.node.nodereturn.size(); temp.++ )
          
CaddNodenodenode.nodereturntemp.], "["temp.@"]");
      break;
    }
  }
}

function 
CaddNodenodeobjvarname )
{
  
with node )
  {
    switch ( 
obj.type() )
    {
      case 
"0": case "1":
        
with addNodevarname SPC "=" SPC ParseValue(obj) @";" ) )
        {
          if ( 
node.returntype.type() == )
            
this.parentnode node.returntype;
          else 
this.parentnode node.parentnode;
          return 
this;
        }
      break;
      case 
"2":
        
with addNodevarname SPC "=" SPC ParseValueobj ) @";" ) )
        {
          if ( 
node.returntype.type() == )
            
this.parentnode node.returntype;
          else 
this.parentnode node.parentnode;
          
this.nodereturn obj;
          return 
this;
        }
      break;
      case 
"3":
        
with addNodevarname SPC "= new["obj.size() @"];" ) )
        {
          if ( 
node.returntype.type() == )
            
this.parentnode node.returntype;
          else 
this.parentnode node.parentnode;

          
this.nodereturn obj;

          return 
this;
        }
      break;
    }
  }
}
public function 
getObjKeysobjstrNeedle 

  if ( 
obj.type() != )
    return 
getstringkeysobj );

  
temp.vars obj.savevarstoarrayfalse ); 
  for ( 
temp.var: temp.vars 
    if ( 
temp.var.startsstrNeedle ) ) 
      
temp.keys.addtemp.var.substringstrNeedle.length(), temp.var.pos("=") - strNeedle.length()) );

  
this.toreturn temp.keys;
  return 
this.toreturn;

Both the scripts go in the same weapon. This weapon should be seperate from the weapon used to make Lesson 1.

[EDIT]: Fixed the problem. fitparentwidth = true; Good old Wiki =)

Last edited by Twinny; 07-14-2007 at 11:26 AM..
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 03:59 PM.


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