-- LUA Script - precede every function and global member with lowercase name of script local state = {} local player = {} local tgtPos = {} local timer = {} local currentSquare = {} local currentPlayer = nil local playerList = {} function slplayer_init_name(e, name) state[e] = 'start' player[e] = name playerList[#playerList + 1] = name ModulateSpeed(e,0.85) SetAnimationSpeed(e,0.85) timer[e] = g_Time + 5000 end local function WalkToSquare(name, square) for k, v in pairs(player) do if v == name and ( state[k] == 'idle' or state[k] == 'dice thrown' or state[k] == 'arrived' ) then local x,y,z,xa,ya,za = SLCalcPos(square) state[k] = 'walk' tgtPos[k] = {x = x, y = y, z = z} timer[k] = g_Time + 2000 CharacterControlArmed(k) ModulateSpeed(e, 0.85) SetCharacterToWalk(k) AIEntityGoToPosition(g_Entity[k].obj, x, z) end end end local diceThrow = 0 function SLDiceThrown( e, dice ) diceThrow = dice state[e] = 'dice thrown' end function slplayer_main(e) PromptLocal(e, player[e] .. ", " .. state[e] .. ", " .. (currentSquare[e] or 'none') ) if state[e] == 'start' then timer[e] = g_Time + 5000 state[e] = 'idle' elseif state[e] == 'idle' and g_Time > timer[e] then if currentPlayer == nil then currentPlayer = math.random(1, #playerList) end if playerList[currentPlayer] == player[e] then currentSquare[e] = 1 WalkToSquare( player[e], currentSquare[e] ) else timer[e] = g_Time + 1000 end elseif state[e] == 'walk' then local Ent = g_Entity[e] local pos = tgtPos[e] local tDistX, tDistZ = Ent.x - pos.x, Ent.z - pos.z if tDistX*tDistX + tDistZ*tDistZ < 25*25 then state[e] = 'arrived' if currentSquare[e] == 100 then state[e] = 'winner' timer[e] = math.huge else timer[e] = g_Time + 1000 end else if g_Time > timer[e] then timer[e] = g_Time + 2000 AIEntityGoToPosition(g_Entity[e].obj, pos.x, pos.z) end end elseif state[e] == 'arrived' then if currentSquare[e] > 1 then local ladder = SLLadder( currentSquare[e] ) if ladder ~= nil then currentSquare[e] = ladder WalkToSquare( player[e], currentSquare[e] ) return end local snake = SLSnake( currentSquare[e] ) if snake ~= nil then currentSquare[e] = snake WalkToSquare( player[e], currentSquare[e] ) return end if playerList[currentPlayer] == player[e] then if currentPlayer == #playerList then currentPlayer = 1 else currentPlayer = currentPlayer + 1 end state[e] = 'wait turn' end else if playerList[currentPlayer] == player[e] then SLThrowDice( e ) state[e] = 'wait for dice' timer[e] = math.huge end end elseif state[e] == 'wait turn' and playerList[currentPlayer] == player[e] then SLThrowDice( e ) state[e] = 'wait for dice' timer[e] = math.huge elseif state[e] == 'dice thrown' then currentSquare[e] = currentSquare[e] + diceThrow if currentSquare[e] > 100 then currentSquare[e] = 100 end WalkToSquare( player[e], currentSquare[e] ) end Prompt(currentPlayer or 'none') end