ID:1846290
 
(See the best response by Kaiochao.)
Code:
obj/Creatables
var/neededtech=1
New(mob/creator)
suffix="[FullNum(round((cost/creator.techmod)))]z"
if(cost <= 0) del(src)

for(var/obj/Creatables/Punching_Bag/A in !usr.contents)
if(!pbagdisabled)
usr.contents+=A
for(var/obj/Creatables/Books/A in !usr.contents)
if(!booksdisabled)
usr.contents+=A
for(var/obj/Creatables/Ammo/A in !usr.contents)
if(ammodisabled)
usr.contents+=A
for(var/obj/Creatables/Handgun/A in !usr.contents)
if(!gundisabled)
usr.contents+=A
for(var/obj/Creatables/Armor/A in !usr.contents)
if(!armordisabled)
usr.contents+=A
for(var/obj/Creatables/Blaster/A in !usr.contents)
if(!blasterdisabled)
usr.contents+=A
for(var/obj/Creatables/PDA/A in !usr.contents)
if(!pdadisabled)
usr.contents+=A
for(var/obj/Creatables/Hand_Drill/A in !usr.contents)
if(!handdrilldisabled)
usr.contents+=A
for(var/obj/Creatables/Artificial_Moon/A in !usr.contents)
if(!moondisabled)
usr.contents+=A
for(var/obj/Creatables/Scouter/A in !usr.contents)
if(!scouterdisabled)
usr.contents+=A
for(var/obj/Creatables/Sword/A in !usr.contents)
if(!sworddisabled)
usr.contents+=A
for(var/obj/Creatables/Regenerator/A in !usr.contents)
if(!regeneratordisabled)
usr.contents+=A
for(var/obj/Creatables/Simulator/A in !usr.contents)
if(!simulatordisabled)
usr.contents+=A
for(var/obj/Creatables/Gravity/A in !usr.contents)
if(!gravitydisabled)
usr.contents+=A
for(var/obj/Creatables/Power_Drill/A in !usr.contents)
if(!drilldisabled)
usr.contents+=A
for(var/obj/Creatables/Nav_System/A in !usr.contents)
if(!navdisabled)
usr.contents+=A
for(var/obj/Creatables/Spacepod/A in !usr.contents)
if(!spacepoddisabled)
usr.contents+=A

for(var/obj/Creatables/Punching_Bag/A in usr.contents)
if(pbagdisabled)
del(A)
for(var/obj/Creatables/Books/A in usr.contents)
if(booksdisabled)
del(A)
for(var/obj/Creatables/Ammo/A in usr.contents)
if(ammodisabled)
del(A)
for(var/obj/Creatables/Handgun/A in usr.contents)
if(gundisabled)
del(A)
for(var/obj/Creatables/Armor/A in usr.contents)
if(armordisabled)
del(A)
for(var/obj/Creatables/Blaster/A in usr.contents)
if(blasterdisabled)
del(A)
for(var/obj/Creatables/PDA/A in usr.contents)
if(pdadisabled)
del(A)
for(var/obj/Creatables/Hand_Drill/A in usr.contents)
if(handdrilldisabled)
del(A)
for(var/obj/Creatables/Artificial_Moon/A in usr.contents)
if(moondisabled)
del(A)
for(var/obj/Creatables/Scouter/A in usr.contents)
if(scouterdisabled)
del(A)
for(var/obj/Creatables/Sword/A in usr.contents)
if(sworddisabled)
del(A)
for(var/obj/Creatables/Regenerator/A in usr.contents)
if(regeneratordisabled)
del(A)
for(var/obj/Creatables/Simulator/A in usr.contents)
if(simulatordisabled)
del(A)
for(var/obj/Creatables/Gravity/A in usr.contents)
if(gravitydisabled)
del(A)
for(var/obj/Creatables/Power_Drill/A in usr.contents)
if(drilldisabled)
del(A)
for(var/obj/Creatables/Nav_System/A in usr.contents)
if(navdisabled)
del(A)
for(var/obj/Creatables/Spacepod/A in usr.contents)
if(spacepoddisabled)
del(A)
..()


Problem description:
Basically, I am trying to make a system, where if a Variable ( Example: spacepoddisabled) equals to 1, it will remove the item from the users contents, but, if it equals to 0 it'll all it. I need a conveniant way for that to happen, without it causing major lag. Could anyone help me reform this code please ?

1. Flip your if()s and for()s. You don't need to loop through every Spacepod if spacepoddisabled is false, because in that case, nothing happens. Same goes for all your other loops.

2. Repeated usr abuse. You have "creator", so use that instead.

3. !usr.contents will never actually be a list of things to loop through.
In response to Kaiochao
So something like this
if (var/obj/Creatables/Spacepod/A != creator.contents)
if(spacepoddisabled)
Del(A)
else
if (!spacepoddisabled)
usr.contents += A
Best response
Actually, I was thinking more like this.
In response to Kaiochao
Out of all the links the only thing that could help me is probably the DM guide I still don't know how I would be able to set up a good nd simple system. Which removes the object or adds the object based on a variable.
Woah... that's.. incapable of being helped???
Kozuma-Chan ! Anyway, Yeah thank's alot, now all I have to do is convert the code <.<
Kozuma3 wrote:
Kinda like this.

if(!pbagdisabled)
> for(var/obj/Creatables/Punching_Bag/A in creator.contents)
> creator.contents += A


Please don't take advice from this code..it makes no sense. At all.
You could simplify this much more by using a global list of what IS allowed, add the objects that are allowed in run-time when the world is loading, then just check if the source type (the object being created) is in that list, if it is, create it, if it's not, don't create it. Far more simplistic than create lines of code that are pretty much copy+paste until you fill a single .dm file with 1000000000000000000000 lines of code. Also, you'll remove every single variable like the pbagdisabled, scouterdisabled, etc.


var/list/allowed_creations = list()
var/list/created_creations = list()

obj
creations
New()
// blah blah spawning new /obj
created_creations += src

cake
desc = "The cake is a lie."
pie
desc = "Pies are spies."
zombie
desc = "Zombies eat keyboards."

proc
addCreation()
var/creation = input("Add", "Add", ) in typesof(/obj/creations)
allowed_creations += creation

removeCreation()
var/creation = input("Remove", "Remove", ) in allowed_creations
allowed_creations -= creation
checkWorld()

checkContents(client/player)
for(var/obj/creations/creation in player.mob.contents)
if(!istype(creation) in allowed_creations)
player.mob.contents -= creation

checkWorld()
for(var/obj/creations/creation in created_creations)
if(!istype(creation) in allowed_creations)
del creation

mob
verb
addAllowedCreation()
addCreation()

removeAllowedCreation()
removeCreation()

client
proc
loadCharacter()
// blah blah loading character whatnots
checkContents(src)


Now obviously this will not copypasta into your game as work as you expect it right off the bat. You'll need to follow these steps on handling your system and work on it to follow. Because you're trying to remove objects if the world has disabled certain /obj, you'll want to call a check anytime an /obj is added from this list. That means, when addCreation() is called, have it check every client's /mob if they have any of these /obj and remove them. You'll also want to remove them from the world itself if these /obj are drop/placeable. To simplify this even further, have a list that holds references to all /obj created that fall under /obj/creations, and loop through that list (instead of looping through every /atom, /turf in the world and remove the desired /obj from it's owner's contents or wherever it may lie in the world. This will also require a check every time a client logs in, so as if a player spawned a /obj/creations/cake and then they logged out, their contents were saved, and then /obj/creations/cake was removed from the acceptable creations, you'll need to remove it from the client's /mob contents when they login.
In response to Maximus_Alex2003
Thanks, I'll read this and incoperate the system, thanks.