ID:139222
 
Code:
mob/proc/Knocked_out(mob/M as mob in get_step(src,usr.dir))
if(M.hp == 0)
view(6) << "[M] has been knocked out!"


mob
verb
Attack(mob/M as mob in get_step(src,usr.dir)) //the verb name, look no var/mob/M in oview(1)
if(M.hp <= 0 ) //if the mobs hp is less than or equal to 0
usr.attacking = 1
M.attacking = 1
M.move = 0
M.ko = 1 //sends M to death proc
else if(prob(70))//You got a 70% chance of it continueing and not going to the else
usr.attacking = 0
M.attacking = 0
M.move = 1
M.ko = 0 //sends M to death proc
var/damage = usr.strength - M.defense //assigns a random number between 1 and 5 to damage
src<<"You attack [M] for [damage] damage!" //says you attack
M<<"[src] attacks you for [damage] damage!" //tells the mob (in case that mob is another player) you attacked them
M.hp -= damage //the mobs hp is subtracted by the number in damage
M.Knocked_out(M)
else //if you didn't hit
src<<"You attempt to attack [M] but miss!" //says player miss
M<<"[src] attempts to attack you but misses!" //tells the M player missed
sleep(7) //code sleeps for 7/10 of a second.
usr.attacking = 0 //attacking goes to 0, now the usr can attack again


Problem description: Ok, Basically my problem is that I am trying to either A.) Create a proc that is able to be used in a verb(In this case Attack would be that verb) and allow it to run so that when the hp of a mob reaches 0 it will tell the user that the mob has been knocked out, but not repeat.. I am really assuming this is an easy fix, but its just slipping my mind... Or B.) Simply just add something to my attack code that allows the text not to repeat...

And now my next problem, umm ok, I am not sure exactly what this issue is or where its occuring as the last time I ran my project everything worked fine, now for some reason when I updated Byond I got a warning saying that cKey has been phased out, replace with cKeyEx, and before and after that it would not allow me to click on my login screen.... And it kinda bugs my map up where my login screen is and when I put these codes in here
turf
New
Click()
icon = 'New.dmi'
icon_state = ""
usr.CreateCharacter()
Continue
Click()
icon = 'Continue.dmi'
icon_state = ""
usr.ChooseCharacter()
Delete
Click()
icon = 'Delete.dmi'
icon_state = ""
usr.DeleteCharacter()
on my map over where they are suppose to be on the login screen they seem to just erase that tile of the login screen, regardless if I snip out icon and icon_state from the codes, when before updating these worked and I could easily log in my game... Like I said I cannot figure this out... but I can use text mode when I start up the game to click these and they work then.. I am at a lost and I hope I do not seem dumb for either of these questions, and I appreciate the help, if any at all, very much.

Well, I don't see any way in your code for the text to repeat, but I do see a few problems:

mob/proc/Knocked_out(mob/M as mob in get_step(src,usr.dir))


The "as" and "in" keywords don't actually do anything in process arguments, that's only for verb arguments.

if(M.hp == 0)


Because you're using the '==' operator, this check will fail if M's health falls below 0 (ie is negative). You should use '<=' like you did in the Attack() verb.

view(6) << "[M] has been knocked out!"


The center of view() defaults to the usr, which in this case is usually the one who knocked-out the mob. That should be view(6, src) (I'll get to why it should be src and not M in a bit)


For your Attack() verb, don't mix and match usr and src. src holds what you want, so you might as well stick to that.

You also need to check that damage isn't negative, or weak players will actually heal stronger enemies. You can use var/damage = max(usr.strength - M.defense,0) to keep the damage at or above 0.

M.Knocked_out(M)


Okay, this is silly, and here's why: you're passing 'M' to a process that it owns, which means 'src' already holds the value you want. Most people would pass 'src' to a Kocked_out/Death process in this situation, so it knows who caused it. Here's how I would suggest writing it:

M.Knocked_out(src)

mob/proc/Knocked_out(mob/killer)
if(src.hp <= 0)
view(6,src) << "[src] has been knocked out by [killer]!"




As for your second question, the map editor changed a bit in recent version. Now to overlay two turfs on top of one another, you have to CTRL+Click when placing the second turf. To change this behavior so you "insert" above instead of "replace" the existing turf, go to your map, and go into Option->Click Behavior.

If you're login screen looks all messed up (like the image is repeated a bunch), that's a result of the change from the old TILED_ICON_MAP to the new TOPDOWN_MAP map_format. There are two ways to fix this.

I recommend simply deleting and replacing your login screen (and any other multi-tiled turfs/objects placed in the old versions, however be aware that only one tile will actually have the density, so you may need filler objects if your multi-tiled object is dense).

However, you can also revert to the old map_format (which disables big icons and some other new features):
world/map_format = TILED_ICON_MAP


Also, for your buttons, you may want to do mouse_opacity = 2.
In response to DarkCampainger
Argh, I am editing this because I poked around my code and I did use some of the stuff you suggested or most of the changes anyways and it definitely helped, I wasn't getting any errors when I would run or compile, but I still wasn't getting the results I needed when I would test out my procs or verbs. I do appreciate your help a lot, I have also learned a few new things and learned some mistakes not to make again. Thank you.
In response to Zekk98
Zekk98 wrote:
Also, by Defining M.Knocked_out(src) like that, does it allow you to define the mob as whatever you wish in the Knocked out proc? I mean I do have multiple mobs and I need it to work for each mob... I seriously hope I am not sounding stupid, but I am able to grasp what you have said thus far and it makes sense.

"M.Knocked_out(src)" is calling M's Knocked_out() process, and passing src as the first argument.


mob/proc/Knocked_out(mob/killer)


Now inside the process definition for Knocked_out() we see that it is defined under /mob, and that the first argument is type-cast* as a /mob and named "killer".

So, putting the definition together with the way we call it, inside the Knocked_out() process src will be equal to the M from the Attack() verb (M.Knocked_out), and killer will be equal to the src from the Attack() verb (Knocked_out(src))


*(It's important to keep in mind that just because an argument is type-cast as a certain type, doesn't mean that the value passed will be that type (for example, you could accidentally pass an object, or even a number!))
In response to DarkCampainger
More knowledge and you definitely explained out in great detail the answer to my question, thank you, lol. I figured it out as I was playing with the code and your explanation did wonders for me, both of them. :) I just hope I am somewhat decent at coding...