ID:1697397
 
(See the best response by Reformist.)
Code:
obj/var
open=0
password = null
mob
var
build[] = list(new/obj/buildobjs/PasswordFence,
new/obj/buildobjs/Grass,
new/obj/buildobjs/Wall,
new/obj/buildobjs/Wall2,
new/obj/buildobjs/Wall3,
new/obj/buildobjs/Wall4,
new/obj/buildobjs/Floor,
new/obj/buildobjs/Floor1,
new/obj/buildobjs/Floor2,
new/obj/buildobjs/Floor3,
new/obj/buildobjs/Floor4,
new/obj/buildobjs/Floor5,
new/obj/buildobjs/Flower,
new/obj/buildobjs/Flower1,
new/obj/buildobjs/Flower2,
new/obj/buildobjs/DirtPatch,
new/obj/buildobjs/Mud,
new/obj/buildobjs/Piano,
new/obj/buildobjs/Bucket,
new/obj/buildobjs/Hay,
new/obj/buildobjs/Dresser,
new/obj/buildobjs/Dresser1,
new/obj/buildobjs/Dresser2,
new/obj/buildobjs/Pole,
new/obj/buildobjs/Bookshelf,
new/obj/buildobjs/Bookshelf2,
new/obj/buildobjs/Bookshelf3,
new/obj/buildobjs/Matt,
new/obj/buildobjs/Stove,
new/obj/buildobjs/Stove1,
new/obj/buildobjs/Stove2,
new/obj/buildobjs/Candles,
new/obj/buildobjs/Light,
new/obj/buildobjs/Table,
new/obj/buildobjs/Table1,
new/obj/buildobjs/Chair1,
new/obj/buildobjs/Chair2,
new/obj/buildobjs/Chair3,
new/obj/buildobjs/Chair4,
new/obj/buildobjs/Stairs,
new/obj/buildobjs/BedTop,
new/obj/buildobjs/BedBottom)


Stat()
statpanel("Build")
for(var/s in src.build)
stat(s)


obj
buildobjs
icon='BuildingTurfs1.dmi'

PasswordFence
icon_state="fencinggate"
naturalsuffix = "Purchase to Build/Make Fence Gates to protect your plot of land with a password!"
buyprice = 2500
Click()
if(usr.NoBuild==1)
usr<<output("You cannot build this here","chatoutput")
return
if(usr.NoBuild==0)
if(usr.zenni>=buyprice)
usr<<output("You have made [src]","chatoutput")
usr.zenni-=buyprice
var/o=new/obj/Build/PasswordFence1(usr.loc)
o:ownerof = "[usr.ckey]"
switch(alert(usr,"Would you like to set a password for your door?","Building","Yes","No"))
if("Yes")
o:password = input("What should it's password be?","Building")as text
if("No")
usr<<output("Just a warning, if you do this and someone clicks on your door, they will be able to get on your land!","chatoutput")
return
if(usr.zenni<=buyprice)
usr<<output("You do not have enough zenni for this. You may be able to build more grass when you have [buyprice] zenni.","chatoutput")
return
proc
tryit()
for(var/mob/m)
set background = 1
if(src.open == 1)
return 0
if(usr.owner == "[usr.ckey]")
if(!src.password)
src.open()
return 0
else
m <<output( {"<font color=#C0FFC0>Remember, the password for your door is "[src.password]"."},"chatoutput")
src.open()
return 0
if(!src.password)
src.open()
return 0
else
var/choice = input("What is the password?","Fencing Gate")as null|text
if(choice == src.password)
src.open()
return 0
else
m <<output( "<font color=#C0FFC0><I><B>Access Denied","chatoutput")
return 0
proc/open()
set background = 1
src.density = 0
src.opacity = 0
src.open = 1
flick("fencinggateopen",src)
src.icon_state = "fencinggate"
sleep(40)
src.density = 1
src.open = 0
flick("fencinggateopen",src)
src.icon_state = "fencinggate"






Second Part of Coding:

PasswordFence1
Click()
switch(alert("Enter Password","Password","Yes","No"))
if("Yes")
src.tryit()
if("No")
usr<<output("Ok","chatoutput")
return
icon_state="fencinggate"
density=1

Problem description:
Ok, so i gave you all two snippets of the fencing gate that im having trouble finishing. I am currently using a statpanel to give a description, and image of the item before you build it. I have it so that if you click it, you set it on your usr loc, etc. Well, I get that perfectly fine for the fence. But with map saving, i am trying to make it so that each plot of land, a person can set a password for their gate, and when they click on the gate on the map, it sends them to an alert to enter their password. if the password is correct, then it turns the density to 0 and allows you to walk through (also enabling a icon state of the gate opening and closing) well i keep getting an undefined proc error and im a little confused as to why. If anyone could help me out or needs more of the code, let me know. NOTE: I tried to do a bump proc and for some reason, i received no response in game. If someone could explain to me or contact me over skype on the bump proc let me know. Thanks so much in advance for your help!
First of all you could greatly simplify that starting list with typesof and newlist.
Because it seems as if tryit() is attached to BuildObjs, not PasswordFence1. Where exactly is PasswordFence1 in the code? It seems from your example, unless you shortened it, it is its own datatype.
I can't really help you with the limited amount of code here. Perhaps you could make PassWordFencing a subtype of buildobjs, with both PasswordFence 1 and 2 there, so they have the same procs and vars, instead of letting tryit() be inherited by all the buildobjs.
Vivalas, do you have skype by anychance? the entire code is too long for me to post it up on here.
obj
Build
Earth_Icons
icon='BuildingTurfs1.dmi'
Flowers
Click()
switch(alert("Are you sure you want to delete this turf?","Delete Mistakes","Yes","No"))
if("Yes")
usr<<output("You deleted [src]","chatoutput")
del src
if("No")
usr<<output("Ok","chatoutput")
return
density=1
destroyable=1
flower/icon_state="flower"
flower1/icon_state="flower1"
flowers
icon_state="flowers"
density=0

PasswordFence1
Click()
switch(alert("Enter Password","Password","Yes","No"))
if("Yes")
src.tryit()
if("No")
usr<<output("Ok","chatoutput")
return
icon_state="fencinggate"
density=1


Is there a way to simple this up? Im not exactly the best, or most organized coder lol. Let me know if a bump atom type concept would work?
Best response
mob
proc
PassAttempt(var/Attempt, var/Password)
if(Attempt == Password)
src << output("Access granted!", "chatoutput")
// do access logic here
// for example, check if it's a build item and call Open() if it's a gate or door, etc.
else
if(Attempt && Attempt != Password)
src << output("Access denied! (incorrect password)", "chatoutput")
else
src << output("Access denied!", "chatoutput")


obj
Build
Passworded // this type can cover all Build objects that need passwording in the future
var
Password
Click()
..()
var/mob/M = usr
switch(alert("Attempt Password?", "Password", "Yes", "No"))
if("Yes")
var/Attempt = input("Enter a password", "Password")
M.PassAttempt(Attempt, src.Password) // send the player's attempt and the objects actual password for equivalency testing
if("No")
M.PassAttempt(null, src.Password) // same here, but send null as they did not give an attempt
Fence1
Password = "Pickle" // you can reset this on creation, this is just for testing


This code generalizes the password logic, and also creates a Build type child to cover all objects that should have a password. I left the method setting the password and what happens on accepted passwords up to you, but the basics are all there.
Resolved. Thank you so much for your help reformist!