Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- masters={Zer0Galaxy=true,AlexCC=true}
- jail_x=-1469 jail_y=5 jail_z=90 R=5
- spawn_x=-1459 spawn_y=5 spawn_z=90
- p=peripheral.wrap('bottom')
- WorldID = p.getPeripheralWorldID()
- function save()
- local file=fs.open('jailed','w')
- for name,dat in pairs(jailed) do
- file.writeLine(name..' '..jailed[name].time..' '..jailed[name].by)
- end
- file.close()
- end
- function check(username)
- local online= p.getPlayerUsernames()
- for i=1,#online do
- if username==online[i] then
- local user=p.getPlayerByName(username)
- jailed[username].ent=user.asEntity()
- jailed[username].wid=jailed[username].ent.getWorldID()
- return
- end
- end
- jailed[username].ent=nil
- jailed[username].wid=nil
- end
- function load()
- jailed={}
- -- local online= p.getPlayerUsernames()
- local file=fs.open('jailed','r')
- if not file then return end
- local line=file.readLine()
- while line do
- local username,jail_time,jailed_by=line:match('([_%w]+)%s+(%d+)%s+([_%w]+)')
- if username then
- jailed[username]={time=tonumber(jail_time),by=jailed_by}
- check(username)
- end
- line=file.readLine()
- end
- file.close()
- end
- function events()
- while true do
- local event,username,mess=os.pullEvent()
- if event=="chat_message" and masters[username] then
- local user,time=mess:match("$$jail%s*([_%w]*)%s*(%d*)")
- if user then
- if user=="" then
- user=p.getPlayerByName(username)
- for n,u in pairs(jailed) do
- user.sendChat(n..' '..(u.time/60)..' by '..u.by..' status-'..(u.wid or 'ofline'))
- end
- else
- jailed[user]={time=(tonumber(time) or 0)*60,by=username}
- check(user)
- end
- end
- elseif event=="player_login" or event=="player_change_world" or event=="player_respawn" then
- if jailed[username] then check(username) end
- elseif event=="player_logout" then
- if jailed[username] then
- jailed[username].ent=nil
- jailed[username].wid=nil
- end
- elseif event=="char" and username=="q" then return
- end
- end
- end
- function guard()
- local change=false
- local x,y,z
- while true do
- for i=1,100 do
- for n,u in pairs(jailed) do
- if u.wid==WorldID and u.time>=0 then
- x,y,z=u.ent.getPosition()
- if math.abs(jail_x-x)>R or math.abs(jail_y-y)>R or math.abs(jail_z-z)>R then
- u.ent.setPosition(jail_x,jail_y,jail_z)
- else
- change=true
- u.time=u.time-3
- if u.time<=0 then
- u.ent.setPosition(spawn_x,spawn_y,spawn_z)
- jailed[n]=nil
- save()
- break
- end
- end
- end
- end
- sleep(3)
- end
- if change then
- save()
- change=false
- end
- end
- end
- load()
- parallel.waitForAny(events,guard)
- save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement