-- LUA Script - precede every function and global member with lowercase name of script + '_main' local U = require "scriptbank\\utillib" local Q = require "scriptbank\\quatlib" local rad = math.rad local deg = math.deg local rnd = math.random math.randomseed(os.time()) rnd(); rnd(); rnd() local dice_list = {} local controlDice = nil local EkeyPressed = false function dice_throw_init( e ) Include( "utillib.lua" ) end local function ThrowDice() for k, _ in pairs(dice_list) do CollisionOff(k) local Ent = g_Entity[k] local yo = rnd(100) SetPosition(k, Ent.x, Ent.y + 100 + yo, Ent.z) nxa, nya, nza = rnd(-179, 179), rnd(-89, 89), rnd(-179,179) SetRotation(k, nxa, nya, nza) ResetPosition(k, Ent.x, Ent.y + 100 + yo, Ent.z) ResetRotation(k, nxa, nya, nza) CollisionOn(k) end end function dice_throw_main( e ) local dice = dice_list[e] if dice == nil then dice_list[e] = { state = 'idle' } if controlDice == nil then controlDice = e end return end if dice.state == 'idle' and controlDice == e then Prompt("Press E to throw dice") if g_KeyPressE == 1 then if not EkeyPressed then EkeyPressed = true ThrowDice() end else EkeyPressed = false end end -- get new Euler angles local xa, ya, za = rad( GetEntityAngleX( e ) ), rad( GetEntityAngleY( e ) ), rad( GetEntityAngleZ( e ) ) local vx,vy,vz = U.Rotate3D(0,0,1, xa, ya, za) if vy > 0.5 then PromptLocal(e, "4") return elseif vy < -0.5 then PromptLocal(e, "3") return end vx,vy,vz = U.Rotate3D(0,1,0, xa, ya, za) if vy > 0.5 then PromptLocal(e, "6") return elseif vy < -0.5 then PromptLocal(e, "1") return end vx,vy,vz = U.Rotate3D(1,0,0, xa, ya, za) if vy > 0.5 then PromptLocal(e, "2") return elseif vy < -0.5 then PromptLocal(e, "5") return end end