ID:169063
 
How would I go about making an NPC that blocks your path until you get a certain item?
well you could have a variable that once you have a certain item in in view(-1) it sets the variable to 1 if the variable is 0 the gate is dense if the varaible is 1 then it has the gate not dense
My way (and me being an ineffecient coder that atleast gets the work done) would be to make a turf that's where the NPC is at and the path you want to block (x - turfs, O - NPC with the turf there, | = wall) eg:
|xxoxx|

If the client (let's assume you only want players to be blocked) tries to enter where the X is, it won't let them pass without that certain item... the coding would be something like this:
turf
BlockPathGuard
mouse_opacity = 0 //If the client puts the mouse over the turf, it will not "see" the turf
Enter(mob/M)
if(ismob(M) && M.client)//if M is a player and a mob (safety check ;/)
var/Items/Clothes/Acadamy/Shirt/O//The object needed to pass through
for(O in M.contents)
if(O)
return..()//if M has O, lets them continue
for(var/mob/NPC/N in view(5))//Assuming mob/NPC is the default path of your NPCs and the path is 5 tiles long from N (therefore about |xxxxoxxxx|)
if(N.guard)//if N is the mob that's guarding the place (and it's guard var is set to 1 (true))
var/obj/Q = new(locate(N.x,N.y,N.z))
Q.density = 0 //Q is the ref point for N's original location
var/obj/E = new(locate(src.x,src.y,src.z))//E is the ref point for src
walk_to(N,E,0,3)//Search up in help in DM to see what walk_to does
sleep(3*get_dist(N,E))//Time delayed until N reaches X
N.dir = get_dir(N,M)//Makes N face M
view(1,N) << "You can not pass without an Acadmy Shirt!"//replace name here of O's item ([O] doesnt show the name for some reason) even with O = new
sleep(10)//waits one second
walk_to(N,Q,0,3)//Returns to original spot
sleep(3*get_dist(N,Q))
N.dir = initial(N.dir)//original facing way
del(E)
del(Q)
//The above two are used to delete the two extra objs made as ref points
return 0//Stops them from entering)
else
return..() //If M is not a mob or a player, makes them continue on


Even if N.guard was not set to 1 or N was not near, M could not pass without the item... remember to replace things and not just copy/paste/run

PS: I tested this and it worked, just remember to make sure everything is correct (like NPC's path, the object's name and path, etc) and to place the turfs along the path you want to block. Also add the guard var as a tmp since only certain NPCs will be using it and you can enter it in it's coding like so:
mob/var/tmp/guard=0 //Default is 0

mob/NPC/Guard
name = "Guard"
guard = 1


If you want anything explained, ofc (ofcourse) ask here or if you want to ask me directly, check up my email in my profile ;)
In response to Flame500
Flame500 wrote:
well you could have a variable that once you have a certain item in in view(-1) it sets the variable to 1 if the variable is 0 the gate is dense if the varaible is 1 then it has the gate not dense

Not, everything should be done that way. Sometimes, other people wish to have it different. GhostAnime's way seems resourceful enough.
In response to MasterLink2003
Uhhh, mine's a text rpg, so I also want that when you go to that area, the NPC automatically talks to you and says that you can't go through.
In response to Seraphrevan
mob
Bump(Guard)
usr << "You cannot pass!"


Thats extremely rough code, not sure if it works :P If it doesn't, look up Bump() in the DM reference
In response to Nukes4U
I have no idea what I'm coding, but would something like this work:

if(ismob(M) && M.client)
var/pass/0
for(O in M.contents)
if(O)
return ..()
else
set usr.loc="Whatever the area is before it..."
turf
Gate()
icon = 'adfsdf'
icon_state = "asdasd"
Enter(mob/m)
if(m.gatenter == 0)
return
else
continue


Not tested it should work...
In response to Seraphrevan
Not sure if you still live (;/) but you just have to tweak my turf code a bit
turf
PassCheck
mouse_opacity = 0
text = " "
invisibility = 100
Enter(mob/M)
if(ismob(M) && M.client)
var/obj/pass/0
for(O in M.contents)
if(O)
return..() //if O is in M content's, the person can move into the turf.
break //Just felt like adding this
M << "\redYou can not pass without a pass!"
return 0 //Note that this Enter proc is called before the user comes into the turf. the set old loc thing would be needed if this was a Entered() proc