ID:178955
 
When making any rpg, is it possible to make a character heal over time? Maybe by using verbs this can be accomplished?

mob
verb
Heal(mob/M in view(1))
var/heal = rand(2,hp)
usr << "[usr] heals!"
M.hp += hp
M.Deathcheck()

Would that work or would more have to be added and ho would I show a picture change in the heal after a heal command is entered?
Flare0080 wrote:
When making any rpg, is it possible to make a character heal over time? Maybe by using verbs this can be accomplished?

mob
verb
Heal(mob/M in view(1))
var/heal = rand(2,hp)
usr << "[usr] heals!"
M.hp += hp
M.Deathcheck()

Would that work or would more have to be added and ho would I show a picture change in the heal after a heal command is entered?

this is almost right. try this instead...

mob
proc
Heal()
usr << "[usr] heals!"
M.hp += rand(2,hp)
\\you don't really need the deathcheck since this is a heal verb

this is also assuming that the hp is greater than zero or even two and that it is of course already defined. now you just need something to call that proc. If i understand correctly you want it to happen every so often so a loop would be useful.
I would do it something like this:
mob
var/health = 100
New()
..()
anchor
sleep(20)
if(src.health > 100) goto NEXT
heal(src,rand(1,20))
NEXT
goto anchor
verb/Heal(var/mob/M in oview(1))
var/healed = heal(M,src.health/10)
src.health = src.health/10
src << "You heal [M] for [healed] health!"
M << "[src] heals you for [healed] health!"
proc/heal(var/mob/M in world,var/amount = 0 as num)
var/orig = M.hp
M.hp += amount
var/newhp = M.hp
return hewhp - orig


-Lord of Water
In response to Lord of Water
You use goto WAY too much, LoW.

mob
proc
healy()
while(src.health != src.maxhealth)
sleep(40)
src.health += 5
verb
heal()
usr.healy()


Simple, no?
In response to Lord of Water
oh thats good, thats real good, I didn't test it but looking at it makes my code look infinitesimal.
In response to Nadrew
Wanna see some real 'goto' action?
NPC
Clerk
Arena
SignUp
var/list/greeted = list() // <-- this is a list
Click()
for(var/obj/O in greeted)
if(O.name == src.key) goto VISITED
var/obj/O = new /obj (null)
O.name = src.key
greeted.Add(O)
var/chooser = alert(usr,"Welcome to the Croenia Arena! I see that you are a first timer, so I'll answer any questions you have. Is there anything you'd like to know?","Clerk","Yes","No")
if(chooser == "Yes") goto QUESTION
else goto NEXT
VISITED
var/choice = alert(usr,"Hello again, friend. Do you require any knowlage of this arena?","Clerk","Yes","No")
if(choice == "Yes") goto QUESTION
else goto NEXT
QUESTION
var/question = input(usr,"What would you like to know?","Clerk") in list(
"1. What can I do in this arena?",
"2. Why is this arena here?",
"3. Why should I compete here?",
"4. Does it cost anything to compete?",
"5. What equipment do I need to compete?",
"Done")
if(question == "Done") goto NEXT
else switch(text2num(copytext(question,1,2)))
if(1)
alert(usr,"Here at the arena you can compete in three sports: Archery (tests your reflexes and sharp eye), Fencing (which uses your quick legs and good technique), and Sword Fighting (which relies on your ability to deal and take damage).","Clerk")
if(2)
alert(usr,"This arena was built by King Faltus decades ago because of his love of martial sports and other festivities. He has since perished, but his masterpiece center of fun and sport lives on.","Clerk")
if(3)
alert(usr,"You should compete here for many reasons. One crucial one is that, to obtain the Royal Seal needed to leave this city, you must place in at least one tournament in one sport. Sports are also fun and challenging, and help to pass the time.","Clerk")
if(4)
alert(usr,"Depending on the tourney, it may cost from 5 Brass Bars to 5 Silver Pieces to compete in a tournament. Respectively, the more money it costs the larger the prizes and payouts are for winning the tourney. That is the only charge, aside from equipment costs.","Clerk")
if(5)
alert(usr,"Talk to the merchants outside the Arena and to the east. They are very knowlageable in what is needed to compete and will be more then willing to sell it to you!","Clerk")
goto QUESTION
NEXT
alert(usr,"Thank you for talking, and come back many times!","Clerk")


-Lord of Water
In response to Nadrew
geez that seems so easy and yet so good. I need to work on my coding skills.
In response to Lord of Water
Goto is good for long statments like that but when you can make it work better using while() that's usally the way you should go.
In response to Canar
It's untested, but it should work. If it is not, a tiny bit of tweaking should do the trick. Glad I could help!

-Lord of Water
In response to Nadrew
I agree. while just works alot better for simple loops, like what he needed.
In response to Canar
Thanks for all the coding help, I am going to test them now. I don't exaclty understand the 'goto' command though, but thanks.
In response to Lord of Water
That's one ugly loop, man. You should be using do-while() instead, which offers the same functionality for less confusion, and I'd set up the whole switch() thing differently anyway.

Lummox JR
In response to Lummox JR
Amen to that!
In response to Lummox JR
Nah... I write a lot of things like that, so they are easy enough for me to read. And, I like having the numbers in the switch. What do you suggest changing it to? Thirdly, what makes it 'ugly'? To me, it loops like a purposeful procedure that stays almost all on one line. I could certianly re-arrange the proc so that it does not use 'goto', but to me that would make it even more ugly.

-Lord of Water
In response to Lord of Water
Lord of Water wrote:
Nah... I write a lot of things like that, so they are easy enough for me to read. And, I like having the numbers in the switch. What do you suggest changing it to? Thirdly, what makes it 'ugly'? To me, it loops like a purposeful procedure that stays almost all on one line. I could certianly re-arrange the proc so that it does not use 'goto', but to me that would make it even more ugly.

For suggestions on changing it, I'd say to simply compare the first part of each item--or to find its index in the list with Find()--and use that. You take the first part and convert it to a number, which means you can't use "Done" in the switch() and have to check for it separately.

What makes it ugly is that you're using goto in a place where it's not only not needed, but worse than the alternative. A simple do-while loop would serve you perfectly well and actually save you a line (that line being taken up by one of your labels):
do
ask question
if(answer=="Done") break
switch(first part)
if("1")
...
if("2")
...
...
while(answer!="Done")

Lummox JR
In response to Flare0080
Flare0080 wrote:
Thanks for all the coding help, I am going to test them now. I don't exaclty understand the 'goto' command though, but thanks.


goto has been around forever... it basically means "I want to jump to a different place in the code (marked by the label), and I don't care about being able to return to where I jumped from"
In response to Lummox JR
I agree... the code example was more than just ugly. Of course I admit to being completely biased against using goto. It is never needed, and I challenge anyone to find a situation that uses goto that I can't rewrite in a clearer fashion without.

But LOW's example is further complicated by putting a goto inside of a for loop that points outside the loop. LOW, do you know whether or not the loop is still executing after the jump? It's all very hard to fathom what process are still hanging at each point in the code.

You may think it's easy enough for you to understand since you wrote it, but I bet if you look at it again after three months away, you're going to scratch your head a bit before recalling what it's supposed to do.
In response to Skysaw
Skysaw wrote:
I agree... the code example was more than just ugly. Of course I admit to being completely biased against using goto. It is never needed, and I challenge anyone to find a situation that uses goto that I can't rewrite in a clearer fashion without.

I disagree on that point: It is needed and should still be used, because C's loop constructs (which have migrated to other languages since) are incomplete; they're particularly bad for nested loops. These situations are hard to think up off the top of your head, but they do exist. I regard the anti-goto sentiment of the programming elite as a kind of snobbish disdain for all things BASIC and for outdated programming methods--but that doesn't mean goto should be eliminated.

But, the loop constructs that exist do cover about 98% of situations where goto was needed in the past, and in each and every one of those cases it makes infinitely more sense to use the construct rather than goto.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Skysaw wrote:
I agree... the code example was more than just ugly. Of course I admit to being completely biased against using goto. It is never needed, and I challenge anyone to find a situation that uses goto that I can't rewrite in a clearer fashion without.

I disagree on that point: It is needed and should still be used, because C's loop constructs (which have migrated to other languages since) are incomplete; they're particularly bad for nested loops. These situations are hard to think up off the top of your head, but they do exist. I regard the anti-goto sentiment of the programming elite as a kind of snobbish disdain for all things BASIC and for outdated programming methods--but that doesn't mean goto should be eliminated.

But, the loop constructs that exist do cover about 98% of situations where goto was needed in the past, and in each and every one of those cases it makes infinitely more sense to use the construct rather than goto.

Lummox JR

Lummox, I respect you as a top-notch programmer here, so I know if anyone could find an example, it likely would be you.

However, the challenge stands :-)
In response to Skysaw
If you have a move proc thing add the health check proc to that or something
Page: 1 2