ID:141110
 
Code:
//DOFTB Copyright neos300
var/list/attackers = list()
var/list/defenders = list()
var/playernum = 0
var/notstarted = 1

mob
var
hp = 50
hhp
gold = 10000
goldm = 10000
propsleft = 100
str = 5
kills = 0
ofpoints = 0
defpoints = 0
started = 0
team
victory = 0
proc
StartGame()
notstarted = 0
world << "The game has started!"
if (team == "Attackers")
usr.loc=locate(51, 18, 1)
if (team == "Defenders")
usr.loc = locate(50, 100, 1)
started = 1
var/savefile/t = new("settings.sav")
t["started"] << started
world << "You have 20 minutes to fight"
sleep(5000)
world << "15 minutes left"
if (VictoryCheck() == 1)
return
sleep(5000)
world << "10 minutes left to fight."
if (VictoryCheck() == 1)
return
sleep(5000)
world << "5 minutes left to fight."
if (VictoryCheck() == 1)
return
sleep(2000)
world << "3 minutes left to fight."
if (VictoryCheck() == 1)
return
sleep(1000)
world << "2 minutes left to fight."
if (VictoryCheck() == 1)
return
sleep(1000)
world << "1 minute left to fight."
if (VictoryCheck() == 1)
return
sleep(300)
world << "Half a minute left to fight!"
if (VictoryCheck() == 1)
return
sleep(300)
EndGameD()
EndGameA()
world << "The game has ended! The attackers have won!"
if (team == "Attackers")
str += 1
hp += 1
victory = 1
world << "You will all be logged out, then the world will reboot. Please come back for the next match."
sleep(100)
usr.Logout()
world.Reboot()
EndGameD()
world << "The game has ended! The defenders have won!"
if (team == "Defenders")
goldm += 10
hhp += 1
world << "You will all be logged out, then the world will reboot. Please come back for the next match."
sleep(100)
usr.Logout()
world.Reboot()
DeathCheck()
if (src.hp == 0 || src.hp <= 0)
del(src)
VictoryCheck()
if (victory == 1)
return 1
else
return 0
Login()
usr << "Welcome to base defence! Please read the help file if you don't know what to do."
world << "[usr] has logged in."
var/savefile/t = new("settings.sav")
t["started"] >> started
if (started == 1)
usr << "The game has already started."
..()
else
playernum += 1
var/tmp/tc = rand(0, 1)
if (tc == 1)
team = "Defenders"
defenders.Add(usr)
icon = 'Cow.dmi'
verbs += typesof(/mob/defend/verb)
verbs += typesof(/mob/build/verb)
else
team = "Attackers"
attackers.Add(usr)
icon = 'Chadguy2.dmi'
verbs += typesof(/mob/attack/verb)
if (fexists("saves/[copytext(ckey(src.key),1,2)]/[ckey(src.key)].sav") == 1)
var/savefile/s = new("saves/[copytext(ckey(src.key),1,2)]/[ckey(src.key)].sav")
s["hhp"] >> hp
s["hhp"] >> hhp
s["str"] >> str
s["gold"] >> goldm
gold = goldm
s["kills"] >> kills
else
usr << "It seems you are new to DOTB. Welcome! Please read the help file, it will help explain the game."
if (client.CheckPassport(".."))
propsleft = 99999999999999999999999999999999999999999999999999999999999999
..()
if (team == "Defenders")
usr.loc = locate(50, 100, 1)
Logout()
playernum -= 1
world << "[usr] logged out."
var/savefile/s = new("settings.sav")
if (victory == 1)
s["hhp"] << hhp
s["str"] << str
s["gold"] << goldm
s["kills"] << kills
Del()
if (src == usr)
if (team == "Defenders")
usr.loc = locate(50, 100, 1)
else
usr.loc = locate(51, 18, 1)
else
..()
usr.kills += 1
usr.ofpoints += 1
Move()
if (team == "Attackers")
if (view(10, /obj/props/tree_turret))
missile(/obj/props/arrow, /obj/props/tree_turret, src)
verb
say(msg as text)
world << "[usr]: [msg]"
attack(mob/M as mob in oview(1))
set category = "Combat"
src << "You attack [M]!"
M << "[usr] attacks you!"
//var/dmg = 1 //Testing Purposes
var/dmg=src.str * rand(1,4)//Reg one
s_damage(M, dmg, "blue")
M.hp -= dmg
M.DeathCheck()
votego()
var/savefile/t = new("settings.sav")
if (t["votes"] == playernum && notstarted == 1)
StartGame()
else
if (notstarted == 0)
usr << "The game has already started, dummy!"
if (t["votes"] == playernum)
StartGame()
else
t["votes"] += 1
world << "There are now [t["votes"]] votes. We need [playernum] to go."
if (t["votes"] == playernum)
StartGame()
attack
verb
attackdef(obj/O as obj in oview(1))
set category = "Combat"
src << "You attack [O]!"
O << "[O] attacks you!"
//var/dmg = 1 //Testing Purposes
var/dmg=src.str * rand(1,4)//Reg one
s_damage(O, dmg, "blue")
O.hp -= dmg
O.DeathCheck()
teamsay(msg as text)
attackers << "\[TEAM][usr]: [msg]"
defend
verb
teamsay(msg as text)
defenders << "\[TEAM][usr]: [msg]"
ready()
set desc = "Tells your team you are ready."
defenders << "[usr] is all set up and ready to go!"
build
verb
Wall()
set desc = "HP - 50 Cost - 20"
build(usr.loc, usr, /obj/props/wall)
Hard_Wall()
set desc = "HP - 200 Cost - 100"
build(usr.loc, usr, /obj/props/hard_wall)
Tree()
set desc = "HP - 500 Cost - 300"
build(usr.loc, usr, /obj/props/tree)
Tree_Turret()
set desc = "HP - 200 Cost - 100 Fires at enimes."
build(usr.loc, usr, /obj/props/tree_turret)
Super_Wall()
build(usr.loc, usr, /obj/props/super_wall)
Epic_Wall()
build(usr.loc, usr, /obj/props/epic_wall)



atom
var/owner
var/cost
Click()
if(!src.owner)
usr << "<B>This object has no owner.</b>"
else
usr << "<B>[src.owner] has build this object."
verb
Destroy()
if (owner == usr)
usr.propsleft += 1
usr.gold += cost
del(src)
else
usr << "You can't destroy other peoples things!"



proc
build(location, mob/owner, buildtype)
if (usr.propsleft == 0)
usr << "Sorry, you can't build anymore props!"
else
usr.defpoints += 1
usr.propsleft -= 1
var/atom/A = new buildtype (location)
A.owner = "[owner.name] key ([owner.key])"


Problem description:

Can someone please check my code for erros? It works alright in singleplayer, but i cant host and this is more of a multiplayer game.
(Yes, i left out a couple things.)
A few programming tricks:
if(VAR == 1) = if(VAR) 

if(VAR == 0 || VAR == null || VAR == "") = if(!VAR)

VAR += 1 = VAR++

VAR -= 1 = VAR--

if(VAR == 0 || VAR <= 0) //This is redundant. Use <=0 instead.

//This variable can be replaced with the prob() proc.
var/Chance = rand(0,1)
if(Chance == 1)
//...
else //...

if(prob(50)) //50% chance
//...
else //...

//Also, no usr in procs.
//When adding/removing a single item to lists, use the += or -= operators. It's a waste of processing power to use the list procs that way.
You can also short cut to reduce vars.

Instead of...
var/tmp/tc = rand(0, 1)
if (tc == 1)


try...
if (rand(0, 1))
In response to Tsfreaks
if(rand(0,1))
if(pick(0,1))
if(prob(50)) //as I've said already

They all pretty much work the same.
By the way, don't forget that one minute has 60 seconds, not 100.

So sleep(3600) instead of (5000) would make you wait 5 minutes. Also there should be sleep(600) instead of sleep(1000).
In response to Kisioj
Thanks.