I've been working on a small mod that needs external lua libraries (websocket and copas, to be exact), and unfortunately Prison Architect doesn't recognize the "require" term. This is a built-in lua function to grab external libraries, to clarify, but unfortunately Prison Architect doesn't like it for some reason.
Thanks,
//Ron
EDIT: Here's the code...
object_MultiplayerBlockServer:
Code: Select all
function Create()
otherPrisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y + 1 )
myprisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y - 1 )
end
nextTimeout = 0.1
timer = 0
function Updateprisoner(xx,yy)
otherPrisoner.Pos.x = xx
otherPrisoner.Pos.y = yy
end
function OpenServer()
local copas = require("copas")
local ws = require("websocket").server.copas.listen
{
port = 12343,
protocols = {
echo = function(ws)
while true do
local x,y = ws:receive()
ws:send(myprisoner.Pos.x,myprisoner.Pos.y)
Updateprisoner(x,y)
end
end
}
}
end
function CheckTrigger()
local triggerTime = this.TriggerTime
if triggerTime == nil or tonumber(triggerTime) == 0 then
return 5
end
if triggerTime ~= this.LastTriggered then
OpenServer()
end
end
function Update(TimePassed)
timer = timer + TimePassed
if timer > nextTimeOut then
nextTimeout = CheckTrigger()
timer = 0
end
endobject_MultiplayerBlockClient:
Code: Select all
function Create()
otherPrisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y - 1)
myprisoner=Object.Spawn( "Prisoner", this.Pos.x, this.Pos.y + 1 )
end
function Updateprisoner(xx,yy)
otherPrisoner.Pos.x = xx
otherPrisoner.Pos.y = yy
end
function CheckTrigger()
local triggerTime = this.TriggerTime
if triggerTime == nil or tonumber(triggerTime) == 0 then
return 5
end
if triggerTime ~= this.LastTriggered then
StartClient()
end
end
function StartClient()
local websocket = require("websocket")
local client = websocket.client.copas({timeout=2})
local ok,err = client:connect('localhost:12343',myprisoner.Pos.x, myprisoner.Pos.y)
while true do
local x,y = client:receive()
Updateprisoner(x,y)
local ok = client:send(myprisoner.Pos.x, myprisoner.Pos.y)
end
end
function Update(TimePassed)
timer = timer + TimePassed
if timer > nextTimeOut then
nextTimeout = CheckTrigger()
timer = 0
end
end
EDIT: The idea of this mod is to make a multiplayer server (for 2 people, the person hosting the server and the person using the client) that will tell the client where said 'myprisoner' is, and the client will move 'otherprisoner' to the coordinates. Likewise, the client will tell the server where the client myprisoner is, and the server will move the server-side otherprisoner to the coordinates given by the client.



