ID:261386
 
Could someone please get me started on and open door with key verb. Im very new to DM and Im trying to read all the guides and stuff :)

(Just wondering if this is even close)

verb
Open()
if (hkey in usr.loc)




Thanks
If you are really new at coding, you should check out my, "My First Game" tutorial, under the tutorials section. After you read over that, I'd be glad to answer any questions you have..

-Rcet
In response to Rcet
Ok I read over the whole thing :) It was very helpfull and I wanted to say good job. But I still need some help with the door. And I walos used the attack verb that you made and I wanted to make the damage you and the npc did random.




Thank you
In response to Little Sally
Random Damage

If you want it random, and not depend on your strength and defense, then instead of defining var/damage as that, define it as var/damage = rand(1,10). That would make damage a random number between 1 and 10.


Doors

First you need two icons. Opened and Closed. Then, make the object.
obj
door
icon = 'door.dmi'
icon_state = "closed"
density = 1 // set default as you cant walk through it
opacity = 1 // set default as you cant see through it.
verb
Open()
set src in view(1)
src.density = 0 // make it where you can walk through it
src.opacity = 0 // make it where you can see through it
src.icon_state = "open" //change the icon state
Close()
set src in view(1)
src.density = 1 // make it where you cant walk through it
src.opacity = 1 // make it where you cant see through it
src.icon_state = "closed" // change the icon state


There ya go.

Hope i helped.

-Rcet
In response to Rcet
You did it! Thank you so much both things worked. Adn its working great! Just one little thing...Can you see anything weong. I bet its just one little thing :( Thanks


mob
NPC
Worm
icon = 'Worm.dmi'
name = "Worm"
HP = 10
Max_HP = 10
strength = 5
exp_give = 5
gold = 1
var/mob/PC/P
New()
.=..()
spawn(1)
Wander()
proc/Wander()
while(src)
if (P in oview(5))
step_towards(src,P)
else
step_rand(src)
for(P in view(src))
break
sleep(13)
spawn(40)
Wander()
Bump(mob/M)
if (istype(M,/mob/PC))
Attack(M)
proc/Attackk(mob/M)
flick("Worm_Attack",src)
sleep(2)
var/damage = rand(1,3)
M.HP -= damage
view(src) << "[src] attacks [M]!"
view(src) << "[damage] damage!"
deathcheck()

-----------------------------------------------------------
Lyodia.dm:239:error:rand:bad proc
Lyodia.dm:239:error:= :expected a constant expression
Lyodia.dm:240:error:M.HP:duplicate definition
Lyodia.dm:240:error:damage:duplicate definition
Lyodia.dm:240:error:-= :instruction not allowed here
Lyodia.dm:241:error:src:value not allowed here
Lyodia.dm:241:error::duplicate definition
Lyodia.dm:241:error:src:value not allowed here
Lyodia.dm:241:error::duplicate definition
Lyodia.dm:241:error:M:value not allowed here
Lyodia.dm:241:error::duplicate definition
Lyodia.dm:241:error:text "[] attacks []!":value not allowed here
Lyodia.dm:241:error::duplicate definition
Lyodia.dm:241:error:<< :duplicate definition
Lyodia.dm:242:error:src:value not allowed here
Lyodia.dm:242:error::duplicate definition
Lyodia.dm:242:error:damage:value not allowed here
Lyodia.dm:242:error:text "[] damage!":value not allowed here
Lyodia.dm:242:error::duplicate definition
Lyodia.dm:242:error:<< :duplicate definition
Lyodia.dm:38:'Cdoor.dmi':warning: file found only in .rsc
In response to Little Sally

var/damage = rand(1,3) isnt indented enough.. And theres an extra K on your "attackk" proc.
-Rcet
In response to Rcet
Thank you ;)
In response to Little Sally
Ok everything is working great thanks to you ;) I just nedd one more thing to finish the doors. I need to kinda get an idea of how to set a door to lock and be able to unlock and lock with a certain item. Thank you
In response to Little Sally
Put this under the door

New()
door = "locked"

or
locked = 1

Use the boolen 0 - unlocked, 1 - locked

LJR
In response to Little Sally
Just a suggestion as a gamer. I really prefer it when people use the Bump() proc to open doors instead of clicking.

That's just my preference, your the one making the game so you can do it anyway you want :)

Since your new you might not know about Bump() yet so don't sweat it if you don't.
In response to English
Bump was one of my 1st major problems in Kemet as its a major factor in the gameplay. But for a lock and unlock I'd much rather have a click than a bump.

LJR
In response to Little Sally
Locking, and Unlocking Doors.

What you have to do, is first make a key.
obj
key
icon = 'key.dmi'// give the obj an icon

Then make some unlock and lock verbs under the door.
obj
door
icon = 'door.dmi' //assign an icon
var
locked = 1 // by default, make the door locked
verb
Unlock()
set src in view(1)
var/has_key = locate(/obj/key/) in usr.contents //set a var.
if(has_key) //if the usr has the obj /obj/key...
if(src.locked == 1) // and the door is locked..
usr << "You unlock the door." // tell the user that they unlocked it.
src.locked = 0 //unlock the door
else //if the door isnt locked..
usr << "The door isnt locked." //tell them.
else //no key?
usr << "You do not of the key." //too bad.
Lock()
set src in view(1)
var/has_key = locate(/obj/key/) in usr.contents //set a var.
if(has_key) //if the usr has the obj /obj/key...
if(src.locked == 0) // and the door isn't locked..
usr << "You lock the door." // tell the user that they locked it.
src.locked = 1 //lock the door
else //if the door is locked..
usr << "The door is already locked." //tell them.
else //no key?
usr << "You do not of the key." //too bad.
Open()
set src in view(1)
if(src.locked == 0)
//put normal opening code here
else
usr << "The door is locked."


Its commented so you dont get lost.

Hope i helped.

-Rcet