ID:147440
 
I have a npc that sends you to a adventure map.When you get sent there you get 50 Energy.Everytime you move when you are in the adventure map i want it to minus 1 Energy and once his Energy is 0 he gets sent back to the start.The problem im having is when the user moves it doesnt minus any of his Energy.This is what i have right now.

This is the NPC Code that sends you to the map
mob
NPC
Person
icon = 'NPC.dmi'
icon_state = "Adventure"
Click()
if(src in oview(1))
if(usr.action)
return
else
usr.action = 1
if(usr.move == 0)
usr.action=0
return
else
if(usr.Pet)
usr.move=0
var/R = input("Where do you want to go","[src]")in list("Forest","Cancel")
switch(R)
if("Forest")
if(usr.Cash >= 15000) //if usr's gold is greater than or equal to 15000
var/H = input("Are you sure?It will cost $15000","[src]")in list("Yes","No")
switch(H)
if("Yes")
usr.move=1
usr.action=0
usr.Cash -= 15000 //takes 15000 away from usr's gold
usr.loc = locate(1,1,3)
usr.Energy = 50
if("No")
usr.move=1
usr.action=0
return
else
usr << "<Font size=1><font color=red>You dont have enough cash."
usr.move=1
usr.action=0
if("Cancel")
usr.move=1
usr.action=0
return
else
usr << "<font size=1><Font color=red>You dont have a pet to go adventuring with"


This is the code i have to check if the user is in The adventure area.

area
Adventure
Entered(mob/M)
if(M.client)
M.Energy -= 1
if(M.Energy <= 0)
usr.loc = locate(1,1,2)
usr << "You run out of energy and finish the adventure"
Just check mob.loc.loc to find out what area its in.

mob = the mob.
mob.loc = the turf the mob is in.
mob.loc.loc = the area the turf the mob is in is in.

You can chech mob.loc.loc.type to find out what kind of area the mob is in, and if the type equals this "adventure map" they're on, then it subtracts one energy. However you want to work that.
In response to Foomer
I dont really get it. Would i use it like this?By the way Adventure is the name of the area.
mob
Move()
if(usr.loc.loc == "Adventure")
usr.Energy -= 1
In response to Turles9000
Turles9000 wrote:
I dont really get it. Would i use it like this?By the way Adventure is the name of the area.
mob
Move()
if(usr.loc.loc == "Adventure")
usr.Energy -= 1

I think this should work:

<code>mob/Move() if(istype(src.loc.loc, /area/Adventure)) src.Energy -= 1</code>

Incidentally, this is not an appropriate place for <code>usr</code>. You should be using <code>src</code> to refer to the mob.

There's probably a better way to write this, but I can't think of it at the moment.
In response to Foomer
What if the mob is in a boat/car/bus/vehicle or riding a horse/cow/pig/sheep/bike?
I ALWAYS have a 'Random_Procs.dm' file, into which goes anything that I use in more than one other file - for example, Get_Area(atom/a):
proc/Get_Area(atom/a)
if(istype(a,/area))
return a
else Get_Area(a.loc)

Now, you could then use this proc like this:
mob/Move()
var/area/a = Get_Area(src)
if(istype(a,/area/Adventure))
//Do your money, adventure and movement bits here.


By the way, is this game based on the PSOne game 'Monster Rancher'? It used a similar adventure system.
In response to Lord_Him
Yeah it is and this doesnt seem to be working.Nadrew's works but if the user has a pet the pet seems to dissapear then reapear constantly. The probably is probably in my pet follow code though =/.
mob
Move()
if(move)
..()
else
return
var/area/a = Get_Area(src)
if(istype(a,/area/Adventure))
src.Energy -= 1
if(src.Energy <= 0)
usr << "You run out of energy and finish your adventure"
usr.loc = locate(1,1,2)
proc/Get_Area(atom/a)
if(istype(a,/area))
return a
else Get_Area(a.loc)
In response to Turles9000
Then make sure it's only effecting clients.
In response to Goku72
Ahhh k I got it now. Thanks everyone.