Secret Santa 2024
urgh...
Ok if i have more then one input box, only the first works...
dofile("Buttons.lua")
IInputs = { }
InputID = 0
KeyDown = 0
shiftstate = 0
function new_input(text,x,y,w,h,formid)
    InputID = InputID + 1
    IInputs[InputID] = {text = "", x = 0, y = 0, w = 0, h = 0, formid = 0, active = 0}
    IInputs[InputID].text = text
    IInputs[InputID].x = x
    IInputs[InputID].y = y
    IInputs[InputID].w = w
    IInputs[InputID].h = h
    IInputs[InputID].formid = formid
    echo("New Input, ID = " .. InputID)
end

function checkactive(ID)
    if(IInputs[ID].active == 1) then return 1 end
    echo("Inputbox: " .. i .. ".active = " .. IInputs[i].active)
end

local function ___mouse_down(button,x,y)
for i=1,#IInputs do
    IInputs[i].active = hit_test(IInputs[i].x+FForms[IInputs[i].formid].x,IInputs[i].y+FForms[IInputs[i].formid].y+30,IInputs[i].w,IInputs[i].h)
end
end

local function DrawInputs()
for i=1,#IInputs do
    if(FForms[IInputs[i].formid].show == 1) then
        set_color(FForms[IInputs[i].formid].r,FForms[IInputs[i].formid].g,FForms[IInputs[i].formid].b,0.3)
        draw_quad(FForms[IInputs[i].formid].x + IInputs[i].x, FForms[IInputs[i].formid].y + IInputs[i].y+30, IInputs[i].w, IInputs[i].h)
        set_color(1,1,1,0.3)
        draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x+IInputs[i].w-2,FForms[IInputs[i].formid].y+IInputs[i].y+30, 2, IInputs[i].h)
        draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x,FForms[IInputs[i].formid].y+IInputs[i].y+28+IInputs[i].h, IInputs[i].w-2, 2)
        set_color(0,0,0,0.3)
        draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x,FForms[IInputs[i].formid].y+IInputs[i].y+30, 2, IInputs[i].h)
        draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x+2,FForms[IInputs[i].formid].y+IInputs[i].y+30, IInputs[i].w-2, 2)
        set_color(0,0,0,IInputs[i].active+0.3)
        draw_boxed_text(IInputs[i].text, IInputs[i].x+FForms[IInputs[i].formid].x+3, FForms[IInputs[i].formid].y + IInputs[i].y+30, IInputs[i].w, IInputs[i].h, 15, 1)
    end
end
end
function inputboxinput(key,i)
    echo(i)
    if key == 8 then
        if #IInputs[i].text <= 1 then IInputs[i].text = "" end
        if #IInputs[i].text > 1 then IInputs[i].text = string.sub(IInputs[i].text,1,#IInputs[i].text - 1) end
    else
        if shiftstate == 0 then IInputs[i].text = IInputs[i].text .. string.char(key)
        else IInputs[i].text = IInputs[i].text .. string.upper(string.char(key))
        end
    end
    --echo(IInputs[i].text)
end

local function _KeyDown(key)
if key == 303 or key == 304 then shiftstate = 1; return 1 end
for i=1,#IInputs do
echo(IInputs[i].active)
    if(checkactive(i) and key ~= 13 and key ~= 27) then
    --echo("Inputting: " .. string.char(key))
    inputboxinput(key,i)
    --echo("Input: " .. string.char(key))
    return 1
    end
end
end

local function _KeyUp(key)
if key == 303 or key == 304 then shiftstate = 0; return 1 end
    return 1
end

add_hook("draw2d","InputBoxes",DrawInputs)
add_hook("key_down","InputBoxes",_KeyDown)
add_hook("key_up","InputBoxes",_KeyUp)
add_hook("mouse_button_down","InputBoxes",___mouse_down)
Any reason why?
Last edited by Blam; Mar 29, 2008 at 11:26 AM.
:D
The variable i wasn't defined in checkactive().
Radioactive torso's description should be, "You have cancer like wow."
Can you draw a straight line in 3D starting at one point, go through another, and have it keep on going forever? Like a ray line? I want to make an aimer for rpg script.
You can draw a crapload of small quads. I used to draw text and just use a ton of periods, but text moves around when you change zoom for some reason.

I wouldn't recommend extending forever, since so far as I know when you want to do these sorts of operations, you can't get the 2D position during draw3d. But you can make it arbitrarily long without a lot of difficulty.
Radioactive torso's description should be, "You have cancer like wow."
But you can make it arbitrarily long without a lot of difficulty

Can you give me an example of how to do this? I'm still learning.
You can use this code:

function drawLine(p1, p2, step, thickness)
  if(step == nil) then step = .01 end
  if(thickness == nil) then thickness = 3 end
  local dx, dy, dz = p2.x - p1.x, p2.y - p1.y, p2.z - p1.z
  local mag = math.sqrt(dx*dx + dy*dy + dz*dz)
  dx, dy, dz = dx/mag, dy/mag, dz/mag
  for i=0, mag/step do
    local x, y = get_screen_pos(p1.x + dx*step*i, p1.y + dy*step*i, p1.z + dz*step*i)
    local setName = "drawLine"..x..","..y
    add_hook("draw2d", setName, 
      function()
        draw_quad(x, y, thickness, thickness)
        remove_hook("draw2d", setName)
      end)
  end
end

function drawSomeLines()
  drawLine({x=0, y=0, z=1}, {x=1, y=1, z=2})
  drawLine({x=0, y=0, z=1}, {x=1, y=1, z=1})
  drawLine({x=1, y=1, z=1}, {x=1, y=1, z=2})
end

add_hook("draw3d", "asdf", drawSomeLines)
Feel free to change the defaults for the step and thickness. You can also set them per function call like:
drawLine({x=0, y=0, z=1}, {x=1, y=1, z=2}, .1, 10)

step is specified in meters, and thickness is in pixels, sort of.
The function just draws a ton of squares. The thickness argument is just the length of the sides of the squares.
Radioactive torso's description should be, "You have cancer like wow."
Thank you, I got it half way, I'm gonna work on it later on. Also, I have an idea for stick figure toribash. I love you Dafe! <3
Here's my progress (in attachement)

It's not done yet, I'm gonna use this post so I can work on it next class.
Attached Files
rpgaim.lua (4.3 KB, 11 views)
Originally Posted by Nuyashaki View Post
I have an Idea for stick figure toribash.

Hah.
You mean like:
:D
You son of a bitch. I want to do this to help me learn T.T. Just don't post it please. I want to use this as a moment of learning for me.

EDIT: Anyone know the 3D distance formula, worked backwards with distance known, and in lua? :P
Last edited by Nuyashaki; Mar 4, 2008 at 07:38 PM.
Anyway LUA can extend the space between joints. For example, normally left elbow is like 1mm from left shoulder. Anyway to make that 1 metre or something?
I'm the Juggernaut, Bitch!

http://toritori9.on.toribash.com