For any bits of scripting that don't belong anywhere else. Feel free to share them here.
Newbie scripts are also accepted.

To get things started:

Having been learning how to work with math.cos and math.sin, I have achieved some wonderful results: lua code:

len = 0
ang = 0
w,h = get_window_size()
angtbl = {}

while len <= w do
table.insert(angtbl,{x=(w/2)+(len*math.cos(ang)), y=(h/2)+(len*math.sin(ang))})
len = len + 0.1
ang = ang+0.01
end

add_hook("draw2d","y_test",function()
set_color(0,0,0,1)
draw_quad(0,0,w,h)
for i = 1,#angtbl do
set_color(math.random(),math.random(),math.random(),1)
draw_quad(angtbl[i].x-2, angtbl[i].y-2,4,4)
end
end)

I was bored, so I decided to code 2 circle algorithms: lua code:

function draw_circle_b(xc,yc,r)
local x = 0
local y = r
local p = 3 - 2 * r
if not r then return end
while y >= x do
draw_quad(xc-x, yc-y, 1, 1)
draw_quad(xc-y, yc-x, 1, 1)
draw_quad(xc+y, yc-x, 1, 1)
draw_quad(xc+x, yc-y, 1, 1)
draw_quad(xc-x, yc+y, 1, 1)
draw_quad(xc-y, yc+x, 1, 1)
draw_quad(xc+y, yc+x, 1, 1)
draw_quad(xc+x, yc+y, 1, 1)
if p < 0 then
x=x+1
p=p+(4*x+6)
else
x=x+1
y=y-1
p=p+(4*(x-y)+10)
end
end
end

function draw_circle_n(xc,yc,r)
draw_disk(xc,yc,r-1,r,r*2.5,1,0,360,0)
end

First one is a lua translation of Bresenham's circle algorithm, second one is a simplified version of draw_disk adapted for circles.
The hook provided is an example.

Parameters are x position, y position and radius of the circle on both functions.

A hacked startup.lua requested by john (aka box), it removes several restrictions while keeping backwards compatibility.
It removes all OS and cpath restrictions, and allows you to use the original file functions.
ex: _old_io_open("etc","w")
You can check for the hacked startup by checking the boolean _hackedstartup.
_startup.lua is the default startup.

Please don't mess around with this if you don't know what you're doing.

Great work, Yoyo. Your talent does not go un-noticed.

[23:23:53] <AndChat|700625> Blue eyes ultimate dragon best card
[23:24:29] <AndChat|700625> You know the one with 3 heads
[23:24:39] <~Lightningkid> just like my dick

[11:35:40] <box> Hampa suck
[11:36:21] <hampa> not the first to tell me that today

Working on a maze generator that john asked for, using prim's algorithm.
This is as far as I've gotten, but the maze still doesn't generate quite properly.
If anyone wants to help, feel free to.

source (big)

lua code:

local grid = {}
local n = {}
local path = {}
local nn = {}
local r
local len = 0

local is_stepping = false

for x = 1, 50 do
grid[x] = {}
path[x] = {}
for y = 1, 50 do
grid[x][y] = false
path[x][y] = false
end
end

n={{x=1,y=1}}

local function maze_gen() --actual prims alg, generates 1 cell everytime the func is ran
if #n>0 then
r = math.random(1,#n)
if not grid[n[r].x][n[r].y] then
grid[n[r].x][n[r].y] = true path[n[r].x][n[r].y] = true
if n[r].y>1 then if not grid[n[r].x][n[r].y-1] then table.insert(nn,{x=n[r].x,y=n[r].y-1}) end end
if n[r].y<50 then if not grid[n[r].x][n[r].y+1] then table.insert(nn,{x=n[r].x,y=n[r].y+1}) end end
if n[r].x>1 then if not grid[n[r].x-1][n[r].y] then table.insert(nn,{x=n[r].x-1,y=n[r].y}) end end
if n[r].x<50 then if not grid[n[r].x+1][n[r].y] then table.insert(nn,{x=n[r].x+1,y=n[r].y}) end end
if #nn>0 then
for i=1,#nn do
if nn[i].y>1 then if n[r].x~=nn[i].x and n[r].y~=nn[i].y-1 and path[nn[i].x][nn[i].y-1] then len=len+1 grid[nn[i].x][nn[i].y-1]=true end end
if nn[i].y<50 then if n[r].x~=nn[i].x and n[r].y~=nn[i].y+1 and path[nn[i].x][nn[i].y+1] then len=len+1 grid[nn[i].x][nn[i].y+1]=true end end
if nn[i].x>1 then if n[r].x~=nn[i].x-1 and n[r].y~=nn[i].y and path[nn[i].x-1][nn[i].y] then len=len+1 grid[nn[i].x-1][nn[i].y]=true end end
if nn[i].x<50 then if n[r].x~=nn[i].x+1 and n[r].y~=nn[i].y and path[nn[i].x+1][nn[i].y] then len=len+1 grid[nn[i].x+1][nn[i].y]=true end end
if nn[i].y>1 and nn[i].x>1 then if n[r].x~=nn[i].x-1 and n[r].y~=nn[i].y-1 and path[nn[i].x-1][nn[i].y-1] then len=len+1 grid[nn[i].x-1][nn[i].y-1]=true end end
if nn[i].y<50 and nn[i].x>1 then if n[r].x~=nn[i].x-1 and n[r].y~=nn[i].y+1 and path[nn[i].x-1][nn[i].y+1] then len=len+1 grid[nn[i].x-1][nn[i].y+1]=true end end
if nn[i].x<50 and nn[i].y>1 then if n[r].x~=nn[i].x+1 and n[r].y~=nn[i].y-1 and path[nn[i].x+1][nn[i].y-1] then len=len+1 grid[nn[i].x+1][nn[i].y-1]=true end end
if nn[i].x<50 and nn[i].y<50 then if n[r].x~=nn[i].x+1 and n[r].y~=nn[i].y+1 and path[nn[i].x+1][nn[i].y+1] then len=len+1 grid[nn[i].x+1][nn[i].y+1]=true end end
if len ~= 0 then
grid[nn[i].x][nn[i].y]=true
end
table.insert(n,nn[i])
len = 0
end
end
nn = {}
end
table.remove(n,r)
end
end

while #n>0 do
maze_gen()
end

add_hook("draw2d","box's homework",
function()
set_color(0,0,0,1)
draw_quad(0,0,520,520)
draw_text("boxprims.lua by yoyo - press h to regenerate maze, press n to generate step by step",550,100,1)
for j=1,50 do
for i=1,50 do
set_color(1,1,1,1)
if path[j][i] then
draw_quad(j*10,i*10,10,10)
end
if is_stepping then
set_color(0,0,1,0.3)
if grid[j][i] then
draw_quad(j*10,i*10,10,10)
end
end
end
end
if is_stepping then
set_color(1,0,0,0.3)
for i=1,#n do
draw_quad(n[i].x*10,n[i].y*10,10,10)
end
maze_gen() maze_gen() maze_gen() --step the algorithm forward 3 times
if #n==0 then is_stepping = false end
end
end
)

add_hook("key_down","box's homework",function(k)
if k==104 then
run_cmd("ls boxprims.lua")
elseif k==110 then
if not is_stepping then
is_stepping = true
if #n==0 then
for x = 1, 50 do
grid[x] = {}
path[x] = {}
for y = 1, 50 do
grid[x][y] = false
path[x][y] = false
end
end
n = {{x=1,y=1}}
end
else
is_stepping = false
end
end
end)