ID:2035784
 
(See the best response by Ter13.)
Code:


im after a system to jail people, i need it so if i jail someone for 10 mins it gets world time and adds 5 mins to world time, then a proc or something so when world time hits jail time it frees them, anyone got any ideas on how to do this?

What have you tried so far?

The important part to learning how to program is honing your logic skills and your familiarity with the tools you use (in this case the DM Language).

Unless you try to think it through yourself, you will always be asking for code snippets for something simple like this.

Let's run this through a bit. Let's get you thinking about the problem and see what you can do, and we'll push you in the right direction.
In response to Ter13
usr.jailtimer = time2text(world.timeofday,"hh-mm") +

i got that, it adds world time to jail timer but i dont know how to add the minutes they been jailed for
maybe i should not use the time2text
Best response
Okay, we don't need time2text. Let's detail the process of exactly what a jail does so we can build an outline of the things we need to know to complete it.

1) An admin uses a command to jail a player.

2) The player is teleported to a jail location.

3) A timer ticks down, counting away their sentence.

4) The user is unjailed when the timer expires and teleported back to where they were before they were jailed.


For the first part, we need a verb that will allow an admin to select a player and input a number of minutes the person will be jailed for.

For the second and fourth parts, we need to know how to teleport the player.

For the third part, we need to know how to keep track of a jailed player's jail timer.


I'd look up verbs:

http://www.byond.com/docs/ref/info.html#/verb

I'd also look up world.time:

http://www.byond.com/docs/ref/info.html#/world/var/time

I'd also look up atom.loc and locate:

http://www.byond.com/docs/ref/info.html#/atom/var/loc

http://www.byond.com/docs/ref/info.html#/proc/locate


You should not convert the time to text for starters, and you definitely should not use world.timeofday. You will run into problems with timeofday from midnight rollovers.
In response to Ter13
Ter's no longer shoving code down people's throat and pretty much coding what they asked for? well done.
In response to Ter13
i just come up with this...

usr.jailtimer = world.timeofday + T
In response to Ter13
T is what jailer put as in 10 mins jail time
One of my big pet peeves are people who don't read. Fair warning, you didn't read my last post. Please read it.
Lol man said fair warning. might want to dumb it down/simplify it ter, you have a habbit of writing essays. it intimidates beginners.
you have a habbit of writing essays.

188 words. He ignored the first sentence completely. He didn't even try to read it.

I'm sorry, but if 188 words are intimidating, you are never going to get anywhere with programming.

And yeah, ignoring help that you asked for because it's "too long" or intimidating without pointing out to the person that you aren't following their help is just ignorant. It doesn't get you anywhere and all it does is make you look ungrateful/dedicated to not wanting to even try.
var
list/players = list()
list/admins = list()

list/admin_keys = list("Ter13"=1)

list/admin_verbs = list(/verb/jail)

mob
Login()
if(jail_timer)
Jailed(src)
if(admin_keys[key])
verbs += admin_verbs
admins += src
players += src
..()

Logout()
if(jail_timer)
Unjailed(src)
players -= src
admins -= src

verb
jail()
var/mob/m = input("Jail which player?","Jail \[player]") as mob|null in players-admins
if(!m) return
var/duration = max(0,round(input("Jail [m] for how long? (in minutes)","Jail [m] \[duration]") as num|null))
if(!duration) return
m.Jail(duration)

unjail()
var/mob/m = input("Unjail which player?","Unjail \[player]") as mob|null in jailed_mobs
if(!m) return
if(m.jail_timer>world.time&&alert("[m] still has [-round(-((m.jail_timer-world.time)/600))] minutes left on their sentence. Do you really wish to unjail them?","Unjail [m]","Yes","No")=="Yes")
m.jail_timer = world.time
m.Unjail()

var
list/jailed_mobs = list()
proc
Jailed(mob/m)
. = jailed_mobs.len
jailed_mobs |= m
. = jailed_mobs.len-.
if(.&&jailed_mobs.len==1)
for(var/mob/m in admins)
m.verbs += /verb/unjail

Unjailed(mob/m)
. = jailed_mobs.len
jailed_mobs -= m
. -= jailed_mobs.len
if(.&&jailed_mobs.len==0)
for(var/mob/m in admins)
m.verbs -= /verb/unjail

mob
var
tmp/jail_timer
restore_x
restore_y
restore_z
restore_step_x
restore_step_y
proc
Jail(duration)
set waitfor = 0
if(jail_timer)
jail_timer += duration*600
else
jail_timer = world.time + duration*600
restore_x = x
restore_y = y
restore_z = z
restore_step_x = step_x
restore_step_y = step_y
var/atom/movable/o = locate("@loc:jailcell")
loc = locate(o.x,o.y,o.z)
if(istype(o))
step_x = o.step_x
step_y = o.step_y
else
step_x = 0
step_y = 0
Jailed(src)
sleep(duration*600)
Unjail()

Unjail()
if(jail_timer&&jail_timer>=world.time)
loc = locate(restore_x,restore_y,restore_z)
step_x = restore_step_x
step_y = restore_step_y
jail_timer = null
Unjailed(src)
Write(savefile/F)
..()
F["jail_timer"] << (jail_timer ? jail_timer-world.time : null)

Read(savefile/F)
..()
F["jail_timer"] >> jail_timer
if(jail_timer) jail_timer += world.time


Here's your fish. FFS.
In response to Ter13
Ter13 wrote:
Okay, we don't need time2text. Let's detail the process of exactly what a jail does so we can build an outline of the things we need to know to complete it.

1) An admin uses a command to jail a player.

2) The player is teleported to a jail location.

3) A timer ticks down, counting away their sentence.

4) The user is unjailed when the timer expires and teleported back to where they were before they were jailed.


For the first part, we need a verb that will allow an admin to select a player and input a number of minutes the person will be jailed for.

For the second and fourth parts, we need to know how to teleport the player.

For the third part, we need to know how to keep track of a jailed player's jail timer.


I'd look up verbs:

http://www.byond.com/docs/ref/info.html#/verb

I'd also look up world.time:

http://www.byond.com/docs/ref/info.html#/world/var/time

I'd also look up atom.loc and locate:

http://www.byond.com/docs/ref/info.html#/atom/var/loc

http://www.byond.com/docs/ref/info.html#/proc/locate


You should not convert the time to text for starters, and you definitely should not use world.timeofday. You will run into problems with timeofday from midnight rollovers.

Looking at the code versus what Ter wrote (188 words)... I'd choose the words over code... I'm lost looking at the code, but what he said made sense as I was slightly stalking this thread and looking up the reference... I might just start posting in code help, if replies are like this.
I'd choose the words over code

The best part is that the code I just posted probably won't be compatible with whatever project he's already got.

He has to understand the theory to tie in the code to his existing project.

So even if I just did hand him the code, it wouldn't have done him a damn bit of good without understanding it.

EDIT: OP: I know you probably have no idea how this got so heated so fast. You happened to step into a community where this is a repeated issue that has been going on for years. People ask for help, don't want to learn how to do something, and then basically ignore whatever advice is thrown at them. You didn't do anything too horribly wrong. You just happened to make a common mistake that a large number of us here are at our breaking point with. Sorry to kick this up a notch, but this kind of approach is something you absolutely have to break and fast, or it will hold you back for years.
j/s from a nobbs perspective since i was one, sometimes a wall of text intimidates vs doing it step by step between 6 posts. dont have to hurt my feelings :/
dont have to hurt my feelings

I'm not attempting to hurt your feelings. I'm pointing out that the phrase "wall of text" is a severe misrepresentation of 188 words.

But, if 188 words is too much to post to a new developer, I don't think I can help anyone here. I care too much about thorough explanations and actually helping people better themselves to just blindly roll my face on the keyboard and then post an emoticon at the end in an attempt to convey meaning.

lkasjdklajfldsfkl; sdjkl;fjskl;dfjsdl; =(
jeez was just being sarcastic with the hurt my feelings part. personally i liked how you did it, js people are diff.
In response to Ter13
wouldnt it be easier to do this
var
list/players = list()
list/admins = list()

list/admin_keys = list("Ter13")


mob
Login()
if(jail_timer)
Jailed(src)
if(admin_keys[key])
verbs.Add(typesof(/admin/verb))
admins += src
players += src
..()

Logout()
if(jail_timer)
Unjailed(src)
players -= src
admins -= src

admin/verb
jail()
var/mob/m = input("Jail which player?","Jail \[player]") as mob|null in players-admins
if(!m) return
var/duration = max(0,round(input("Jail [m] for how long? (in minutes)","Jail [m] \[duration]") as num|null))
if(!duration) return
m.Jail(duration)

unjail()
var/mob/m = input("Unjail which player?","Unjail \[player]") as mob|null in jailed_mobs
if(!m) return
if(m.jail_timer>world.time&&alert("[m] still has [-round(-((m.jail_timer-world.time)/600))] minutes left on their sentence. Do you really wish to unjail them?","Unjail [m]","Yes","No")=="Yes")
m.jail_timer = world.time
m.Unjail()

var
list/jailed_mobs = list()
proc
Jailed(mob/m)
. = jailed_mobs.len
jailed_mobs |= m
. = jailed_mobs.len-.
if(.&&jailed_mobs.len==1)
for(var/mob/m in admins)
m.verbs += /verb/unjail

Unjailed(mob/m)
. = jailed_mobs.len
jailed_mobs -= m
. -= jailed_mobs.len
if(.&&jailed_mobs.len==0)
for(var/mob/m in admins)
m.verbs -= /verb/unjail

mob
var
tmp/jail_timer
restore_x
restore_y
restore_z
restore_step_x
restore_step_y
proc
Jail(duration)
set waitfor = 0
if(jail_timer)
jail_timer += duration*600
else
jail_timer = world.time + duration*600
restore_x = x
restore_y = y
restore_z = z
restore_step_x = step_x
restore_step_y = step_y
var/atom/movable/o = locate("@loc:jailcell")
loc = locate(o.x,o.y,o.z)
if(istype(o))
step_x = o.step_x
step_y = o.step_y
else
step_x = 0
step_y = 0
Jailed(src)
sleep(duration*600)
Unjail()

Unjail()
if(jail_timer&&jail_timer>=world.time)
loc = locate(restore_x,restore_y,restore_z)
step_x = restore_step_x
step_y = restore_step_y
jail_timer = null
Unjailed(src)
Write(savefile/F)
..()
F["jail_timer"] << (jail_timer ? jail_timer-world.time : null)

Read(savefile/F)
..()
F["jail_timer"] >> jail_timer
if(jail_timer) jail_timer += world.time

That way he could list more of his admin verbs under the admin category and recieve them all at one time?
That way he could list more of his admin verbs under the admin category and recieve them all at one time?

Sure, if you want the unjail command to show up when nobody is jailed, you could do that.