Ranking
Originally Posted by Nuyashaki View Post
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.

I wont.
:3
:D
Originally Posted by toritori9 View Post
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?

Yes; but acording to the wiki, it's experimental.
Originally Posted by wiki
set_joint_position(integer player_index, integer joint_index, number x, number y, number z) -- Experimental
  • Args: player_index (0 for RED, 1 for BLUE), joint_index (from JOINTS.<blah>)

EDIT: Need help on making the line extend beyond eX,eY,eZ on my script. T.T
If it helps heres what I need: A line, from (fX, fY, fZ) through (eX,eY,eZ) to point with a distance of 20. A little help? I can't find a formula anywhere. If you do the normal 3D distance formula, you get answers, but I don't know how to limit it to a line going through eX,eY,eZ.

Here's the result from my calculator:
X:
wtfX = fX - (((400 + (2*fY*wtfY) + (2*fZ*wtfZ) - (fY^2) - (wtfY^2) - (fZ^2) - (wtfZ^2))^.5)*sign1)
Y:
wtfY = (((400 + (2*fX*wtfX) + (2*fZ*wtfZ) - (fX^2) - (wtfX^2) - (fZ^2) - (wtfZ^2))^.5)*sign1) + fY
Z:
wtfZ = (((400 + (2*fY*wtfY) + (2*fX*wtfX) - (fY^2) - (wtfY^2) - (fX^2) - (wtfX^2))^.5)*sign1) + fZ
sign1 is plus or minus 1
I just need that limited to go through eX, eY, eZ
Last edited by Nuyashaki; Mar 4, 2008 at 09:05 PM.
Let me think about it.
Shouldn't it be something more along the lines of
  fX,fY,fZ = get_joint_pos(0,6)
  eX,eY,eZ = get_joint_pos(0,10)
  aimX = fX-eX
  aimY = fY-eY
  aimZ = eZ-eZ
  aimX = aimX * -30
  aimY = aimY * -30
  aimZ = aimZ * -30
  drawLine({x=fX, y=fY, z=fZ}, {x=aimX, y=aimY, z=aimZ})
?
Last edited by Blam; Mar 4, 2008 at 09:57 PM.
:D
Study vectors a little bit. You want to normalize to a unit vector, then all of the math is really simple.
Radioactive torso's description should be, "You have cancer like wow."
aimZ = aimZ * -30?
Doesn't sound right but i'll try.

EDIT: Very close, but the x and y axis are slightly off, and the z axis is way off. Also, what is the command to make this dissapear and reappear when i press a key? I tried and failed.
Last edited by Nuyashaki; Mar 5, 2008 at 02:03 PM.
local function keydown(key)
if(key == blah) then
if(drawline == 1) then drawline = 0 else drawline = 1 end
end
Then just do
if(drawline ==1) then drawLine({x=fX, y=fY, z=fZ}, {x=aimX, y=aimY, z=aimZ}) end
:D
I DID IT!!! Thank you Ms. Fortenberry (my math teacher)!!

I just can't get that stupid key press to work...

Can't upload it thanks to this stupid school computer...ill just post the code.

--Original Credits
--Cobbled together by TrueBoVinE
--Thank you to Suomynona, SSJokker, and Newbluck for making the original scripts
--
-- NewbLuck's useful function...
--New Credits
--Thanks to all the above and my math teacher for finding a formula
--Edited by Nuyashaki
function get_distance(x1,y1,z1,x2,y2,z2)
 local dist = math.abs( math.sqrt( (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2 ) )
 return dist
end
function explode(player, body, force, radius)
 chestpos = get_body_info(player,body).pos
 player1 = player
 xvec = 0
 yvec = 0
 zvec = 0
 if(player1 == 1) then
  player2 = 0
 else
  player2 = 1
 end
 for b=0,20 do
  if (b ~= body) then
   pos = get_body_info(player1,b).pos
   dist = get_distance(chestpos.x,chestpos.y,chestpos.z,pos.x,pos.y,pos.z)
   if(dist < radius) then
    xforce = ((pos.x - chestpos.x) * (1 / dist)) * force
    yforce = ((pos.y - chestpos.y) * (1 / dist)) * force
    zforce = ((pos.z - chestpos.z) * (1 / dist)) * force
    set_body_force(player1,b,xforce,yforce,zforce)
    xvec = xvec - xforce
    yvec = yvec - yforce
    zvec = zvec - zforce
   end
  end
 end
 for b=0,20 do
  pos = get_body_info(player2,b).pos
  dist = get_distance(chestpos.x,chestpos.y,chestpos.z,pos.x,pos.y,pos.z)
  if(dist < radius) then
   xforce = ((pos.x - chestpos.x) * (1 / dist)) * force
   yforce = ((pos.y - chestpos.y) * (1 / dist)) * force
   zforce = ((pos.z - chestpos.z) * (1 / dist)) * force
   set_body_force(player2,b,xforce,yforce,zforce)
   xvec = xvec - xforce
   yvec = yvec - yforce
   zvec = zvec - zforce
  end
 end
 for p=0,1 do
  for j=0,19 do
   x,y,z = get_joint_pos(p,j)
   dist = get_distance(chestpos.x,chestpos.y,chestpos.z,x,y,z)
   if(dist < (radius / 3)) then
    rnd = math.random(0,3)
    if(rnd > 0) and (rnd < 3) then
     fracture_joint(p,j)
    elseif(rnd == 3) then
     dismember_joint(p,j)
    end
   end
   if(dist < (radius / 9)) then
    dismember_joint(p,j)
   end
  end
 end
 set_body_force(player,body,xvec / force,yvec / force,zvec / force)
end
function onkey(key)
 if(key == string.byte("y")) then
  exploded = 1
  explode(0,11,6,10)
 end
end
hackfoo = 10 --hacky way to fix
hackbar = {} -- having to wait one frame
shot3 = {11}
shot = {10}   -- table containing joints connected to the bodyparts to be shot for easy  modding 
shot2 = {6}   -- table containing joints that precede the shot parts for aim calculation
keys = {"q"} -- table containing keys to bind to the bodyparts that are shot
shot['number'] = 3
function init()
 add_hook("key_down","shotgun",keydown)
end
function keydown(key)
 --run_cmd("echo key pressed: "..key)
 --run_cmd("echo key should be pressed: "..keys[1])
 for i = 1, shot['number'] do 
  if ((key == string.byte(keys[i]))) then
   --run_cmd("echo should be fired")
   bodypart_shoot(shot[i],shot2[i], shot3[i]);
  end
 end
end
function bodypart_shoot(body,body2, body3)
 --run_cmd("echo starting firing")
 posX,posY,posZ = get_joint_pos(0,body)
 posX2,posY2,posZ2 = get_joint_pos(0,body2)
 aimX = posX-posX2
 aimY = posY-posY2
 aimZ = posZ-posZ2
 aimX = aimX * 100
 aimY = aimY * 100
 aimZ = aimZ * 100
 dismember_joint(0,body)
 hackfoo = body3
 hackbar.x = aimX
 hackbar.y = aimY
 hackbar.z = aimZ
 frame = 0
 add_hook("enter_frame","shotgun",shoot)
end
function shoot()
 if frame == 1 then
  set_body_force(0,hackfoo,hackbar.x,hackbar.y,hackbar.z)
  --run_cmd("echo fired")
  remove_hook("enter_frame","shotgun")
 end
 if frame == 2 then
  frame = 1
 end
 if frame == 0 then
  frame = 2
 end
end
function drawLine(p1, p2, step, thickness)
  if(step == nil) then step = .2 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()
  fX,fY,fZ = get_joint_pos(0,6)
  eX,eY,eZ = get_joint_pos(0,10)
  aAa = fX * 8 - eX * 8
  bBb = fY * 8 - eY * 8
  cCc = fZ * 8 - eZ * 8
  aimA = eX - aAa
  aimB = eY - bBb
  aimC = eZ - cCc
  drawLine({x=fX, y=fY, z=fZ}, {x=aimA, y=aimB, z=aimC})
end
add_hook("draw3d", "asdf", drawSomeLines)
init()
add_hook("key_down","grenade",onkey)
add_hook("new_game","grenade",init)
I made the line dotted so that it woulden't obstruct the view as much. It is pretty accurate before you fire, after that, it may lag.
Now to work on a "better than yours" stick figure script.
Last edited by Nuyashaki; Mar 5, 2008 at 08:01 PM.
I decided to make some improvements :3
•Press O to show or hide aimer.
•The aimer automatically goes now when you shoot to prevent lag.
•Aimer is coloured red.
•I also changed the length to 30, because i was testing it from 2500 distance.
--Original Credits
--Cobbled together by TrueBoVinE
--Thank you to Suomynona, SSJokker, and Newbluck for making the original scripts
--
-- NewbLuck's useful function...
--New Credits
--Thanks to all the above and my math teacher for finding a formula
--Edited by Nuyashaki
adrawline = 0
function get_distance(x1,y1,z1,x2,y2,z2)
 local dist = math.abs( math.sqrt( (x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2 ) )
 return dist
end
function explode(player, body, force, radius)
 chestpos = get_body_info(player,body).pos
 player1 = player
 xvec = 0
 yvec = 0
 zvec = 0
 if(player1 == 1) then
  player2 = 0
 else
  player2 = 1
 end
 for b=0,20 do
  if (b ~= body) then
   pos = get_body_info(player1,b).pos
   dist = get_distance(chestpos.x,chestpos.y,chestpos.z,pos.x,pos.y,pos.z)
   if(dist < radius) then
    xforce = ((pos.x - chestpos.x) * (1 / dist)) * force
    yforce = ((pos.y - chestpos.y) * (1 / dist)) * force
    zforce = ((pos.z - chestpos.z) * (1 / dist)) * force
    set_body_force(player1,b,xforce,yforce,zforce)
    xvec = xvec - xforce
    yvec = yvec - yforce
    zvec = zvec - zforce
   end
  end
 end
 for b=0,20 do
  pos = get_body_info(player2,b).pos
  dist = get_distance(chestpos.x,chestpos.y,chestpos.z,pos.x,pos.y,pos.z)
  if(dist < radius) then
   xforce = ((pos.x - chestpos.x) * (1 / dist)) * force
   yforce = ((pos.y - chestpos.y) * (1 / dist)) * force
   zforce = ((pos.z - chestpos.z) * (1 / dist)) * force
   set_body_force(player2,b,xforce,yforce,zforce)
   xvec = xvec - xforce
   yvec = yvec - yforce
   zvec = zvec - zforce
  end
 end
 for p=0,1 do
  for j=0,19 do
   x,y,z = get_joint_pos(p,j)
   dist = get_distance(chestpos.x,chestpos.y,chestpos.z,x,y,z)
   if(dist < (radius / 3)) then
    rnd = math.random(0,3)
    if(rnd > 0) and (rnd < 3) then
     fracture_joint(p,j)
    elseif(rnd == 3) then
     dismember_joint(p,j)
    end
   end
   if(dist < (radius / 9)) then
    dismember_joint(p,j)
   end
  end
 end
 set_body_force(player,body,xvec / force,yvec / force,zvec / force)
end
function onkey(key)
 if(key == string.byte("y")) then
  exploded = 1
  explode(0,11,6,10)
 end
 if(key == string.byte("o")) then
  if(adrawline == 1) then adrawline = 0 else adrawline = 1 end
 end
end
hackfoo = 10 --hacky way to fix
hackbar = {} -- having to wait one frame
shot3 = {11}
shot = {10}   -- table containing joints connected to the bodyparts to be shot for easy  modding 
shot2 = {6}   -- table containing joints that precede the shot parts for aim calculation
keys = {"q"} -- table containing keys to bind to the bodyparts that are shot
shot['number'] = 3
function init()
 add_hook("key_down","shotgun",keydown)
end
function keydown(key)
 --run_cmd("echo key pressed: "..key)
 --run_cmd("echo key should be pressed: "..keys[1])
 for i = 1, shot['number'] do 
  if ((key == string.byte(keys[i]))) then
   --run_cmd("echo should be fired")
   bodypart_shoot(shot[i],shot2[i], shot3[i]);
  end
 end
end
function bodypart_shoot(body,body2, body3)
 --run_cmd("echo starting firing")
 posX,posY,posZ = get_joint_pos(0,body)
 posX2,posY2,posZ2 = get_joint_pos(0,body2)
 adrawline = 0
 aimX = posX-posX2
 aimY = posY-posY2
 aimZ = posZ-posZ2
 aimX = aimX * 100
 aimY = aimY * 100
 aimZ = aimZ * 100
 dismember_joint(0,body)
 hackfoo = body3
 hackbar.x = aimX
 hackbar.y = aimY
 hackbar.z = aimZ
 frame = 0
 add_hook("enter_frame","shotgun",shoot)
end
function shoot()
 if frame == 1 then
  set_body_force(0,hackfoo,hackbar.x,hackbar.y,hackbar.z)
  --run_cmd("echo fired")
  remove_hook("enter_frame","shotgun")
 end
 if frame == 2 then
  frame = 1
 end
 if frame == 0 then
  frame = 2
 end
end
function drawLine(p1, p2, step, thickness)
  if(step == nil) then step = .2 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()
        set_color(1,0,0,1)
        draw_quad(x, y, thickness, thickness)
        remove_hook("draw2d", setName)
      end)
  end
end
function drawSomeLines()
  fX,fY,fZ = get_joint_pos(0,6)
  eX,eY,eZ = get_joint_pos(0,10)
  aAa = fX * 30 - eX * 30
  bBb = fY * 30 - eY * 30
  cCc = fZ * 30 - eZ * 30
  aimA = eX - aAa
  aimB = eY - bBb
  aimC = eZ - cCc
  if(adrawline == 1) then drawLine({x=fX, y=fY, z=fZ}, {x=aimA, y=aimB, z=aimC}) end
end
add_hook("draw3d", "asdf", drawSomeLines)
init()
add_hook("key_down","grenade",onkey)
add_hook("new_game","grenade",init)
:D
Thank you blam!
As for now, my finished stick figures:
NOW uploading works...stupid computer...

Thank you everyone else who helped me do this ^^

Tried to make the script work with both at once, but im too lazy to go back and change the name of every variable :P
Attached Files
stickfigureuke.lua (2.5 KB, 9 views)
stickfiguretori.lua (2.5 KB, 11 views)
Last edited by Nuyashaki; Mar 5, 2008 at 08:35 PM.
you should improve it by using get_joint_dismember(player_index,joint_index) :3

Ok, ok
Now for my error.
=[
It's supposed to draw bezier curves.
It shows no line, nor any error in stderr.txt...
function draw_bezier(A,v1,v2,D,thickness,quality,r,g,b,a)
    local B = { }
    local C = { }
    B.x = A.x + v1.x
    B.y = A.y + v1.y
    C.x = D.x + v2.x
    C.y = D.y + v2.y
    local dx, dy = D.x - A.x, D.y - A.y
    local mag = math.sqrt(dx*dx + dy*dy)
    for i=0, mag/0.01 do
        a = i
        b = 1 - i
        x = A.x + dx*0.01*i
        y = ((A.y*b)^2) + (3*B.y*b^2*a) + ((3*C.y)*b*a^2) + (D.y*a^3)
        set_color(r,g,b,a)
        draw_disk(x, y, 0, thickness/2, quality, 2, 0, 360, 0)
    end
end

local function draw2d()
    draw_bezier({x = 150, y = 170},{x = 100, y = 200},{x = 200, y = 400},{x = 180, y = 250},3,80,1,0,0,1)
end

add_hook("draw2d","moo",draw2d)
This code may be completely wrong as i suck at maths :3
What am i doing wrong here?
Last edited by Blam; Mar 5, 2008 at 09:05 PM.
:D