ID:146048
 
Code:
world/loop_checks = 0
mob/proc
Money_Proc()
sleep(2.5*MINUTE)
var/cash = rand(300,550) as num
var/bills = 0 as num
usr.money += cash
usr << "<font color = green>Income Tax: You gained $[cash]."
for(var/obj/O in world)
if(O.owner)
if(O.owner == usr.key)
bills += rand(1,4)
if(istype(O,/obj/objects/Phone))
if(O:owner)
if(O:owner == "[usr.key]")
bills += O:bill
O:bill = 50
if(bills)
if(bills > cash) bills -= 50
usr.money -= bills
usr << "<font color = red>Bills: You paid $[bills]."
sleep(25)
usr.Money_Proc()


Problem description:After a while the server crashes with out any runtime errors.

Maybe it would help if you didn't have so much usr abuse?
I honestly don't see how you're using this, but I attempted to revise your code.
mob/proc/Money_Proc()
sleep(2.5*MINUTE)
mob/var/cash=rand(300,550)
mob/var/bills
src.money+=cash
src<<"<font color=green>Income Tax: You gained $[cash].</font>"
for(var/obj/O in world)
if(O.owner=="[src.key]") src.bills += rand(1,4)
if(istype(O,/obj/objects/Phone))
if(O.owner=="[src.key]") {src.bills+=O.bill;O.bill=50}
if(src.bills>src.cash) {src.bills-=50;src.money-=src.bills;src<<"<font color=red>Bills: You paid $[bills].</font>";sleep(25);src.Money_Proc()}
In response to Sinoflife
Hmm...
Thanks I will try it out.

do i still need this?
world/loop_checks = 0
In response to Y2kEric
Y2kEric wrote:
Hmm...
Thanks I will try it out.

do i still need this?
world/loop_checks = 0

No. Bad bad thing to do. Basically what that does is make it to where it AVOIDS the checks, even though the problem still will remain. This will explain why the server randomly crashes; you can't see the runtime errors and you most likely have an infinite loop.
In response to Sinoflife
So, do you have a better way of giving people money every 2 minutes and 30 seconds?
In response to Sinoflife
You shouldn't define a mob variable in that proc, because it really has no purpose. Just use a proc defined variable.
In response to CaptFalcon33035
yeah, i figured that out.
mob/proc/Money_Proc()
sleep(20)
var/cash = rand(300,500)
var/bills
src.money += cash
src << "<font color=green>Income Tax: You gained $[cash].</font>"
for(var/obj/O in world)
if(O.owner)
if(O.owner=="[src.key]")
bills += rand(1,2)
bills += O.Layer
if(istype(O,/obj/objects/Phone))
bills += O:bill
O:bill = 50
if(bills)
src.money -= bills
src<<"<font color=red>Bills: You paid $[bills].</font>"
sleep(10)
src.Money_Proc()


Are there any other problems
In response to CaptFalcon33035
Yeah. I had it that way but I wasn't really sure if it was going to be used elsewhere or just in the proc itself.
In response to Sinoflife
oops i messed up

i forgot to make the proc run again.

mob/proc/Money_Proc()
sleep(20)
var/cash = rand(300,500)
var/bills
src.money += cash
src << "<font color=green>Income Tax: You gained $[cash].</font>"
for(var/obj/O in world)
if(O.owner)
if(O.owner=="[src.key]")
bills += rand(1,2)
bills += O.Layer
if(istype(O,/obj/objects/Phone))
bills += O:bill
O:bill = 50
if(bills)
src.money -= bills
src<<"<font color=red>Bills: You paid $[bills].</font>"
sleep(10)
src.Money_Proc()

Is there a better way to do this so the server won't crash?
In response to Y2kEric
This won't solve your problem, but it's a step closer, there's 2 stray ':' colon operators in your code. Also, you might want to use spawn() in place of that last sleep().
In response to Mega fart cannon
Mega fart cannon wrote:
This won't solve your problem, but it's a step closer, there's 2 stray ':' colon operators in your code. Also, you might want to should use spawn() in place of that last sleep().

The reason for the game crashing is the entire proc is an infinite loop. The first proc runs, and then calls a new proc. The first proc waits for the new proc to return, but it doesn't because it too starts another proc up and waits for it to return. The process continues infinitely until the game simply can't handle it anymore and just crashes.

To fix it rather than sleep(10) src.whatever(), you want to use spawn() src.whatever().