ID:1410989
 
(See the best response by Nadrew.)
I was wondering if it is possible to reboot without having to actually restarting the server. By that I mean, like all the turfs,npc, etc would go back to its original place just like a reboot. So if someone summon a npc out of place, then world restore would put it back to where it was without having to restart the server.

world.repop() restores objects to their initial state if they have been destroyed.

If they have not been destroyed, then you can loop though their vars list and set the values to their initial value by using initial().


You would need to use both to properly restore the world, unless you never deleted an item. Note, if someone picks something up, it'll move that back too.

MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/m in world)
m.loc = locate(initial(m.x),initial(m.y),initial(m.z))
hmm so if someone picks up a sword for example and this proc takes effect it would go back yes (world restore code that i have restores items) but would it delete them from that person's inventory? Also..wouldn't this move players?
Correct, you would need to add logic to stop that.
You would need to do checking on if someone is a player to r prevent that too. (i.e. if(!m.client))
mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/M in world)
if(M.player||M.GM)
return
else
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))

ok this would work then
OR do i need to indent that a bit more

mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/M in world)
if(M.player||M.GM)
return
else
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))
Second one would be the correct indentation. Now the return statement is not the correct one to use here. Return refers to the procedure. We just want to move to the next alliteration of the loop.

loopstatement
next
dosomething
exit


Looking at the example, our loop statement here is the for. In order to exit the loop statement, you use break somewhere in the do something area. Now if you want to go to the next, you use continue in the do something area.
hmm, ya i was thinking that i might need to use break ok replace break with return and else with else continue?

could you show me like an example or something? I think that maybe i would understand more, i have some procs like
    break
else
continue
No, just replace return with continue.

This will say, when I reach a player, I don't want to do anything with them, go to the next loop.
You can then just remove the else as it would be redundant.

mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/M in world)
if(M.player||M.GM)
continue
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))
so return or break isnt needed? what im was trying to do with player and gm is so they they DONT get moved and everything else npc,obj etc do
I just wanted to make sure, can u plz tell me if it is needed?
Return isn't needed.
it says


test.dm:7:error: M.x: cannot change constant value
test.dm:7:error: M.y: cannot change constant value
test.dm:7:error: M.z: cannot change constant value
test.dm:7:error: M.loc: cannot change constant value


mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/M in world)
if(M.player==1||M.GM==1)
continue
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))
Sorry, change the for line to the following:

for(var/atom/movable/M in world)


So like...
mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/movable/M in world)
if(M.player==1||M.GM==1)
continue
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))

test.dm:5:error: M.player: undefined var
test.dm:5:error: M.GM: undefined var


why am i getting this error? I have it set look..
mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/atom/movable/M in world)
if(M.player==1||M.GM==1)
continue
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))

mob/var
player=0
GM=0

Best response
You're looking up /atom/movable in the loop, but the variables are defined for /mob, the compiler doesn't know what you're trying to do.

Since you want the loop catching everything, you can either change the way the variables are defined, or do some type-casting to check the variables after an istype() check.

if(istype(M,/mob))
var/mob/whatever = M // Type-casting
if(whatever.player || whatever.GM) continue
// ... Rest of stuff here.
well since this code is bascially for npc and not players then this should work...

mob/Owner
verb
MoveBackToInital() //this moves the object back to it's start location.
for(var/mob/M in world)
if(M.NPC)
M.loc = locate(initial(M.x),initial(M.y),initial(M.z))
Thank you guys so much! I got it to work ^.^