Toribash
Original Post
[REL] DeScript V1.3
A new version of my Framework

Download link: MegaUpload

included are:
DeScript - the core pice

DevelHelper - shows events when the happen, keypresses, mouse state, world state

BoutInfo - shows belts and wins/loss for each enemy if you hover over the little triangle next to the bout name

RulesInfo - shows non obvious game rules if you hover over the config button

ModEditor - allows you to create and edit toribash mods

Install instructions:
1. download the file
2. unpack it into the data/script folder
3. load DeScript.lua from the main menu
now DeScript is installed and doesn't need to be reloaded from the menu
you should have now a little red button in the lower right corner

4. middle click (or press 'c') on that button to open the config menu
5. click on the lowest input control, enter 'DevelHelper.lua' and hit the little '+' button
do the same for other scripts
6. click the red config button again to apply changes (and load those addon scripts)

you won't have to repeat those steps the next time you startup toribash since DeSript will be loaded automaticly
to uninstall it edit startup.lua and remove the line saying: dofile('DeScript.lua')
DevelHelper,BoutInfo and RulesInfo need the script to be installed they won't run alone

7. left click on the red button and there should open a menu with your installed scripts click on one of them to execute it
(RulesInfo and BoutInfo won't show up since they are autorun)


Detail Description:
DeScript

Stuff added to the LUA environment:
Special Tables:
  to get the content of these, use the DevelHelper

DeScript
  contains the configuration data

DeWorld
  contains data about the current world state.

DeGUI
  contains GUI classes and is root parent for all GUI objects

Functions:

class([super],[constructor])
  create a new class, optional derived from a super class and constructor function
  classes and objects are tables for lua, but classes are callable and objects share the methods(object functions) with its class
  the new class will have all methods of the super class
  the constructor will become a attribute named 'init'
  to create an object of a class call it with the corresponding parameters for the constructor

key2char(key)
  scancode to char conversion with shift-key detection
  the key-map can be edited within the file "keymap.cfg"

spairs(tbl)
  an iterator like pairs, but iterates alphabeticaly sorted

table_methods(tbl)
  makes the functions in the "table"-table callable the method way for the given tbl
  e.g: tbl:insert('tt')

ttype(var)
  like the type function, but returns the type of special tables, those are:
  "class", "object", "tupel", "vector", "matrix"

math.round(num,[digits])
  rounds the number to the given number of digits

math.sgn(num)
  returns the sign of a number (-1,0,1)

table.copy([trg],src,[deep])
  make a copy of a table
  if deep is true then all subtables will be copied too
  if there is no trg a new table will be created and returned

table.diff(tbl,cmp)
  returns a table which contains only those fields from tbl that differ from cmp

table.equals(tbl1,tbl2)
  returns true if the tables keys and values are equal

table.find(table,value)
  find the key for a given value in a table

table.size(table)
  get the total size of a table, not just that of numeric indecies, as returned by #table

catch_cmd(cmd,onResult)
  like the built in run_cmd, but allows you to catch the return normally displayed at the screen with a function
  onResult(cmd,message)

Data Objects:
  these are for vector and matrix calculations
  to create an object call one of the constructor functions
  the objects can be used in formulas like numbers

Tupel(...)
  Tupel(num) creates a tupel of size num
  Tupel(num,num,...) creates a tupel
  Tupel(tbl) creates a tupel wich contains all nummeric keys that have number values
  Tupel(matrix,n) returns a copy of the n-th row of the matrix

Vector(...)
  Vector(num) creates a vector of size num
  Vector(num,num,...) creates a tupel
  Vector(tbl) creates a tupel wich contains all nummeric keys that have number values
  Vector(matrix,n) returns a copy of the n-th column of the matrix

Matrix(...)
  Matrix(num) creates a square matrix of size num with the main diagonal set to 1
  Matrix(num,num) creates a 0-matrix of that size
  Matrix(...) tries to make a matrix out of it somehow

the operations:
  tup + tup = tup  adds for each index the components
  vec + vec = vec   -"-
  mat + mat = mat   -"-
  tup - tup = tup  substracts for each index the components
  vec - vec = vec   -"-
  mat - mat = mat   -"-
  tup * num = tup  multiplies for each index the components
  vec * num = vec   -"-
  mat * num = mat   -"-
  num * tup = tup  multiplies for each index the components
  num * vec = vec   -"-
  num * mat = mat   -"-
  tup * vec = num  builds the scalar product
  tup * tup = num   -"-
  vec * vec = num   -"-
  vec * tup = num   -"-
  tup * mat = tup  builds the scalar product for each column of the matrix and the tupel
  mat * vec = vec  builds the scalar product for each row of the matrix and the vector
  mat * mat = mat  does a matrix multiplication
  tup / num = tup  divides for each index the components
  vec / num = vec   -"-
  mat / num = mat   -"-
  vec / vec = num  returns the distance of the vectors
  mat / vec = tup  tries to solve the set of linear equations that mat|vec represents
  vec % vec = vec  builds the cross product of the vectors
  vec ^ num = num  returns num * length of the vector
  num ^ vec = vec  returns a vector with the same direction but length num
  tup.T     = vec  returns a vector with same values
  vec.T     = tup  returns a vector with same values
  mat.T     = mat  returns the transposed matrix
  mat.I     = mat  returns the inverse matrix
  mat.det   = num  returns the determinant
  tup()            unpacks the tupel

Classes:
create classes with the 'class'-function
create objects of classes by calling them with the corresponding parameters for the constructor
objects share the methods of their class
classes may have an attribute .super which points to the class they are derived from
classes have a method :is([someclass]) which returns the class of an object if called without parameter
  or returns the specified class ONLY if it's a super class of that object/class (else nil)
here are the predefined ones

TBTimer([owner],hook,[interval=1000],[start])
  create objects of this class to get a timer
  the hook function will get called every time the interval has elapsed until you set the hook field to nil
  .owner = 'some object'
  .hook = function(owner,timer)
  .interval = number
  .start = frame_tick
  .next = start + interval

TBScript()
  subclass this class to hook events
  to actually hook an event you have to create a method wich corresponds to the event name wich are:
    player_select		a player gets selected
    joint_select		a joint gets selected
    draw3d			called every frame to execute world draws
    console			console text arrived
    game_enter			you enter a new gametype(intro,single or multi)
    game_leave			you leave a gametype
    game_pause			the game is paused (match is halted not frozen!!)
    game_continue
    match_enter			you enter match mode
    match_start			the match is started (match frame=0)
    match_frozen		the match is frozen
    match_unfrozen		the match WAS unfrozen
    match_over			the match is over (game_over)
    match_leave			you leave match mode
    replay_enter		you enter replay mode
    replay_start
    replay_frozen
    replay_unfrozen
    replay_over
    replay_leave
    replay_load			a replay was loaded
    enter_frame			the next match frame occours *
    exit_freeze			called before the match unfreezes **
    player_changed		a player changed
    score_changed		a players score changed
    rules_changed		the game rules where changed
    qi_changed			the qi of a bout changed
    user_entered		a bout or spectator entered the room
    user_exited			a bout or spectator left the room
    boutlist_changed		the bout or spec list changed
    key_up
    key_down
    mouse_button_up
    mouse_button_down
    mouse_move
    update			called every frame, use this as less as possible
	
    * for some reason enter_frame is not generated by the engine for multiplayer replays
    ** exit_freeze is not generated in multi gametype
    the hooks remain as long as the object exists, it is save to 'nil' the object at any time

  .disabled			set this to true to temporary disable events for this object

DeGUI.Element(x,y,w,h)
  super class of all GUI classes, subclass of TBScript
  :child([name],[element])
    child()			returns the list of children names
    child(name)			returns the child with given name
    child(element)		returns the name of the given child element
    child(name,element)		makes the element a child with given name
    child(name,false)		removes the named element from the children list
  :parent([element],[name])
    parent()			returns the parent
    parent(false)		removes the object from the parent
    parent(element)		makes the object a child of the given element, the name will be those it had before or a number if it had none
    parent(element,name)	makes the object a child of the given element with given name
  :name(name)
    name()			returns the name
    name(false)			removes the object from its parent
    name(name)			sets the name
  :pos([x],[y])			get/set the relative position
  :abspos()			get the screen position
  :size([w],[h])		get/set the size
  :x([x])			get/set the horizontal position
  :y([y])			get/set the vertical position
  :w([w])			get/set the width
  :h([h])			get/set the height
  :show(vis)
    show()			get the visability of the element
    show(true)			set the element to be visable (it gets only drawn, when all of its (grand-)parents are visible too
    show(false)			hide the element
  .hud				if set to anything but nil or false this element will not block mouse and keyboard events
  .z				if set this defines the draw order for childs of the same parent
  :tex(filename)		the tex function is used to automaticly load and unload textures when they are needed
    use it within the draw2D function like that: draw_quad(...,self:tex('myFunkyTexture.tga'))
    textures won't be loaded double, one texture stays in memory only as long as one object that called the tex function for that texture exists

DeGUI.Element and its subclasses can receive some more events:
focus			occurs if it is set and you click on that element; the element gets focus and receives keyboard input exclusivly
key_pressed		occurs if the mouse is over that element or it has focus
mouse_over		occurs when the mouse enters or leaves an element
mouse_down		...
mouse_up
mouse_click		occurs when mouse_down and mouse_up was on the same element

DeGUI.Quad(x,y,w,h,color)
  :color([{r,g,b,[a]}])		get/set the color

DeGUI.Image(x,y,w,h,filename,[color])
  :color([{r,g,b,[a]}])		get/set the color
  :texture([filename])		get/set the texture file to draw

DeGUI.Disk(x,y,r,color[,r0,start,sweep,slices,loops,blend])
  :color([{r,g,b,[a]}])		get/set the color
  :posC([nx],[ny])		get/set the center of the disk
  :absposC()			get the screen position of the center
  :radius([r],[r0])		get/set the outer and the inner radius

DeGUI.Text(x,y,text[,font,color,align])
  :color([{r,g,b,[a]}])		get/set the color
  :text([text])			get/set the text - can contain \n or can be a list
  :font([font])			get/set the font
  :align(align)			get/set alignment - -1 left; 0 screen-centered; 1 right

DeGUI.BoxedText(x,y,w,h,text[,font,color,lineheight])
  :color([{r,g,b,[a]}])		get/set the color
  :text([text])			get/set the text - no \n or table here
  :font([font])			get/set the font
  :lineheight(lh)		get/set the lineheight

DeGUI.Frame(x,y,w,h[,color])
  a window frame
  :color([{r,g,b,[a]}])		get/set the color

DeGUI.Panel(x,y,w,h[,color])
  a sub window for a frame
  :color([{r,g,b,[a]}])		get/set the color

DeGUI.Button(x,y[,onClick,label,w,h,color])
  :color([{r,g,b,[a]}])		get/set the color
  .onClick			set this to a function(self,button) to process clicks on this button
  .label			the label text
  .label_offset			fineadjust the hor. positioning of the label

DeGUI.CircleButton(x,y, [onclick, d,icon,label,color,d1])
  a round button, d is the diameter(default is 24), icon is a imagefile, d1 is a 2. diameter to create ellipses
  :color([{r,g,b,[a]}])		get/set the color
  .onClick			set this to a function(self,button) to process clicks on this button
  .label			the label text
  .label_offset			fineadjust the hor. positioning of the label
  .icon				the icon

DeGUI.ButtonBar(x,y,bwidth,bheight,orientation)
  a bar of buttons
  orientation can be one of 'h','h-','v','v-'
  :add(label,onClick,color)	create a new button on the bar
  :add(button)			add an existing button to the bar
  :remove(n)			remove the nth button
  :max(m)			get/set the maximum buttons displayed
  :set(n,label,onclick,color)	modify the nth button
  :count()			get the number of buttons

DeGUI.TextBox(x,y,w,h,[text,color])
  a text panel
  :color([{r,g,b,[a]}])		get/set the color
  .text				can contain \n or can be a list (table with numeric indecies)

DeGUI.TextInput(x,y,w,h,[pattern,color])
  a text input frame
  :pattern(pattern)		set an allowed input, onChange will only trigger if the text matches the pattern (see LUA string patterns)
  :color([{r,g,b,[a]}])		get/set the color
  .text				no \n and no table
  .onChange			set this to a function(self,text) to process input when it occurs

DeGUI.CheckBox(x,y,onCheck)
  .onCheck			set this to a function(self,checked) to process a click when it occurs
  .checked			true or false

DeGUI.Slider(x,y,length,direction,[onChange,color])
  direction can be 'h' or 'v'
  :sliderpos(spos)		get/set the position of the slider;0 <= spos <= 1
  .onChange			set this to a function(self,spos) to process a change of the slider position
  .delta_click			set this to change the delta value when a click on the slider bar occurs
  .delta_wheel			set this to change the delta value when the mouse wheel is used

DeGUI.ColorChooser(x,y,color,posx,posy,[onChange])
  .color			= {r,g,b,a}
  .overcolor			set to true to allow values outside [0,1]
  .onChange			set this to a function(self,color) to process a change of color

DeGUI.ListBox(x,y,w,[table,max_h])
  to modify tables with numeric indecies
  if no table is given an empty will be used
  if max_h is given it only resizes itself to this maximum, if the table doesn't fit a scrollbar is added
  will always work with a internal copy of the specified table so use the onAdd and onDel functions
  :color([{r,g,b,[a]}])		get/set the color
  :table(tbl)			get/set the table for the ListBox
  .onAdd			set this to a function(self,element,pos) to process inserts to the ListBox, can return a modified element or false if the element should not be inserted
  .onDel			set this to a function(self,element,pos) to process removements from the table

DeGUI.ListChooser(x,y,w,table)
  to select one element from a list
  :color([{r,g,b,[a]}])		get/set the color
  :table(tbl)			get/set the table for the ListBox
  .onClick			set this to a function(self,mbutton,pos) to process clicks on an element
DeScript special features:
- better event handling, see desc. of TBScript
- timers, see desc. of TBTimer
- GUI system, see desc. DeGUI, DeGUI.Element and the other DeGUI classes
to create a new GUI class subclass one of those and overwrite the methods to your needs, especially :draw2D to change the drawing
- classes under DeGUI load and unload dynamicly now
- save stuff between sessions:
. make it part of the DeWorld.save table, for general things
. make it part of DeWorld.users[username].save, for user specific things
. per User saving must be enabled for this
. make it part of DeWorld.rules.save, for mod specific things
. per Mod saving must be enabled for this


ModEditor

with this you can edit all options of a tbm file
for an explaination of all those flags in the menus look at MrPoptart's Mod Tutorial

you can select objects in the 3D world by clicking on them
if you selected one you can hold:
[ctrl] for move mode
[alt] for size mode
[shift] for rotation mode
in one mode click and drag the mouse around to change the object
use the mouse wheel to change the z-value, click on it to change the wheel speed

press '2' to change to freecam mode, otherwise the camera will reset alot

addons:
i have developed a system to embed data into the comments of the mod, this data will get processed by DeScript, which then tries to execute a corresponding script
the first feature is a per mod shader, setup the shader - whenever the mod is loaded the shader will be changed to this one
Last edited by DeFransen; Dec 8, 2010 at 07:13 PM. Reason: Update
"Wenn Sensei Tanaka sein Shodushi ist, dann soll er hingehen und uns den Dimak zeigen!"
it sead's "Error loading scripts.zip.lua "
i trust in god :D
yeah [Latin]:)/WAAAAAAAZZZZZZZZZAAAAAAA!!!!!!!!!!
DeFransen, sorry, but your scripts actually doesnot work:

Error loading script: DevelHelper.lua
Error loading script: rulesinfo.lua
Error loading script: DeScript.lua

only mytest.lua works, but does nothing.

can you add more details how to start it for noobs as me?
Well...
Here are step by step install instructions:

1. download the file
3. unpack it into the data/scripts folder
4. load DeScript.lua from the main menu
now DeScript is installed and doesn't need to be reloaded from the menu
you should have now a little red button in the lower right corner

5. middle click that button to open the config menu
6. click on the lowest input control, enter 'DevelHelper.lua' and hit the little '+' button
do the same for RulesInfo.lua and BoutInfo.lua and other scripts
7. click the red config button again to apply changes (and load those addon scripts)

you won't have to repeat those steps the next time you startup toribash since DeSript will be loaded automaticly
to uninstall it edit startup.lua and remove the line saying: dofile('DeScript.lua')
DevelHelper,BoutInfo and RulesInfo need the script to be installed they won't run alone

8. left click on the red button and there should open a menu with your installed scripts click on one of them to execute it
(RulesInfo and BoutInfo won't show up since they are autorun)

Hope this brings light into the darkness
Last edited by DeFransen; Mar 25, 2010 at 02:18 PM.
"Wenn Sensei Tanaka sein Shodushi ist, dann soll er hingehen und uns den Dimak zeigen!"
This is sweet, very nice, simple interface.

Develhelper is abit over my head, but i will be using the rest for sure.
I swear you shouldn't be able to open up startup.lua

Anyway great work, will be very useful, thanks. Looks like a tonne of work went in to this, i'd never be able to commit myself to that, so congrats

Hope to see that mod editor soon :3
Last edited by Blam; Mar 14, 2010 at 09:17 PM.
:D
If this makes you nervous already, check out the "Violence evolved" script by squeakus
Maybe you're not the right address, but a good solution for my hack could look like this:
io.open = function (filename, mode)
  -- Simple check for valid access
  if string.find(filename, "../", 1, true) or string.find(filename, "..\\", 1, true) or string.find(string.lower(filename), "startup.lua", 1, true) then
    return nil, "invalid access"
  end
  return old_io_open("./data/script/" .. filename, mode);
end

local res,f = pcall(io.open,"autorun.lua")
if res and f then
  f:close()
  dofile("autorun.lua")
end
Then you could include the startup.lua file in the list of autoupdated files to prevent manual modification, but it would still be possible to add custom scripts
Last edited by DeFransen; Mar 15, 2010 at 01:56 PM.
"Wenn Sensei Tanaka sein Shodushi ist, dann soll er hingehen und uns den Dimak zeigen!"
I got descript.lua script running,
added develhelper.lua,
added rulesinfo.lua,
added boutinfo.lua,
added movememory.lua,
closed Toribash for startup test,
attempted to reopen Toribash,
Toribash wont open.
Shop (Óc¸Ó ) PM me if you want to buy TC
Damn yes, got the same problem today...
and solved it.

The error occurs if one tries to execute "echo" during startup.
so open DeScript.lua and those other files in a text editor and delete the lines where "echo" is called.

Got no clue what i mean? Don't worry, I will release a update very soon.

Thats what happens if you do last minute changes

======================================
Updated:
-Now all bugs should be removed
-It came to my mind that lots of scripts are not ment to run on startup, but at a certain time, therefor i changed it a little:
To open the config menu you have to click with the middle mouse button now.
If you want a script to be executed once at startup enter "--autorun" as the very first line in the script file,
all other files will appear in a menu if you left click on the main button from where you can run them

added new event "rules_changed"

optional force download of players customs (enable in config menu)

added per Mod saving
Last edited by DeFransen; Mar 17, 2010 at 11:35 AM.
"Wenn Sensei Tanaka sein Shodushi ist, dann soll er hingehen und uns den Dimak zeigen!"
As blam said, it sounds like a shitload of work.
I will be looking further into the tools for developpers

Also I spotted a little mistake in the gui class I think.
You have two function DeGUI:h(). (l. 1589, 1593)
I guess the second should be named function DeGUI:w() ;)

Good work
[FROG] - [Toribash-FR] - [OLDA] - \m/
Français, english: Click