Hello.
I've been working on a quick script, that as shown on the video above, adds semi-swim-able water.
Every body part that is inside a water object is subject to an upwards force.
It's still a beta, I'm probably gonna work more on it. I intend to make it so that you can add water objects inside your mod, and get the script to recognize it.
Right now, if you can work with lua, you can go inside the source and mess with the add_water function. It's parameters are equal to the draw_box function without the rotation.
The script now lets you add water objects through a mod.
To add a water object to your mod, create a line anywhere in the script that starts with "#water".
Then, add the object information separated by commas: x position, y position, z position, x size, y size, z size
To add more objects, simply put a space between them.
Example mod
# water.lua demo mod, made by yoyo, shoutout to dinis and box
#water 1,-5,2.55,10,5,5 5,5,5,10,4,4
gamerule
matchframes 1500
engageheight 500
engagedistance 900
env_obj 1
pos 5 5 2.5
sides 10 4 1
color 0 1 0 1
flag 8
The script doesn't add any water flow physics though, and I don't really expect to do anything like that.
That's pretty much all at the moment, hope you like it.
Changelog:
19-12-2012: Initial release.
20-12-2012: Script now adapts automatically to the gravity.
20-12-2012: Script is now customizable through mods.
Source
lua code:
local water = {}
local bodyparts = {{},{}}
local gravity = {}
for g in string.gmatch(get_game_rules().gravity, "[^%s]+") do
table.insert(gravity, g)
end
local function add_water(s)
local tbl = {}
for v in string.gmatch(s,"[^,]+") do
table.insert(tbl, tonumber(v))
end
table.insert(water,tbl)
tbl = nil
end
local modf
local line = ""
if get_game_rules().mod ~= "classic" then
modf = io.open("data/mod/"..get_game_rules().mod,"r",1)
while true do
line = modf:read("*l")
if line == nil then break end
if line:sub(1,6) == "#water" then
for w in string.gmatch(line:sub(8), "[^%s]+") do
add_water(w)
end
end
end
modf:close()
end
local function pos_between(x,y,z,xx,yy,zz,xxx,yyy,zzz)
if x>(xx-(xxx/2)) and x<(xx+(xxx/2)) and y>(yy-(yyy/2)) and y<(yy+(yyy/2)) and z>(zz-(zzz/2)) and z<(zz+(zzz/2)) then
return true
else
return false
end
end
add_hook("new_game","y_water",
function()
gravity = {}
for g in string.gmatch(get_game_rules().gravity, "[^%s]+") do
table.insert(gravity, g)
end
water = {}
if get_game_rules().mod ~= "classic" then
modf = io.open("data/mod/"..get_game_rules().mod,"r",1)
while true do
line = modf:read("*l")
if line == nil then break end
if line:sub(1,6) == "#water" then
for w in string.gmatch(line:sub(8), "[^%s]+") do
add_water(w)
end
end
end
modf:close()
end
end
)
add_hook("enter_frame","y_water",
function()
for j = 1,2 do
for i = 0,20 do
bodyparts[j][i] = get_body_info(j-1,i).pos
for u, n in pairs(water) do
if #n==6 then
if pos_between(bodyparts[j][i].x,bodyparts[j][i].y,bodyparts[j][i].z,n[1],n[2],n[3],n[4],n[5],n[6]) then
set_body_force(j-1,i,0,0,gravity[3]*-0.00305)
end
end
end
end
end
end
)
add_hook("draw3d","y_water",
function()
set_color(0,1,1,0.5)
for u, m in pairs(water) do
if #m==6 then
draw_box(m[1],m[2],m[3],m[4],m[5],m[6],0,0,0)
end
end
end
)
So you're trying to simulate water by creating a kind of buoyancy effect inside objects by adding a upwards force inside them?
If I understood that correctly, you'll have to "calibrate" the effect for -30 gravity with another version of the script or so, won't you?
You're pretty much correct, I set an upwards going force on every bodypart (not joints though) that is inside the water objects.
It is possible to make a self-adapting script, and it is something I'll add in the future, but right now it's only calibrated for -9.82.
I'll try to make an updated version asap.
This is an excellent script. I enjoy it very much. It warms my heart that this script is so good.
[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
I figured out a proportionality constant that gives me the correct upwards force when multiplied by the gravity, so the script now adapts automatically to the gravity.
If anyone is interested, it's value is of -0.00305.