ID:168718
 
i need a pice of code that moves the user from his current position to 5 spaces in his direction and if he bumps any thing it acitvates the attack verb then stops
world/New()
mob=/mob/
name="Junk World"


mob
icon='junk.dmi'

mob/var/HP=10
mob/verb/Attack()
var/steps=5
while(steps)
step(usr,usr.dir)
sleep(5)
steps--


mob/Bump(mob/M) //don't quite remember how bump works so you'll have to check it
if(ismob(M))
M.HP-=5
M.DeathCheck()
..()

mob/proc/DeathCheck()
if(M.HP<=0)
src<<"You killed [M]!"
//do leveling up stuff here
del M


Anything more than that and I suggest you try learning how to code first. Check out Demos/Tutorials/etc.
In response to Rockinawsome
That would work but if the object you bumped is deleted then the player would continue to move in that direction.
/*B-O-F*/
///////////////////////////////////////////////////
//Authour:Itanium -creator of the ItaninumCore-
///////////////////////////////////////////////////
mob/verb/Attack()
{
var steps=6;
while(--steps>0)
{
var turf/T=get_step(src,src.dir)
if(T.density)
{
for(var/mob/trg in T)//attack every mob in this turf
{
src<<"You attacked [trg]!";
};
break; // kill the loop
};
src.Move(locate(T.x,T.y,T.z),get_dir(src,T));
sleep(3); // movement delay
};
};
/*E-O-F*/

This is untested,but I don't see anything critically wrong with it.
In response to Itanium
Please get rid of the brackets ({}). All it does is make the code harder to read. DM doesn't require brackets like C and C++ do. And please use more than 1 space as a tab, as this will make the code also hard to read.
In response to Mega fart cannon
I would but then I wouldn't feel at ease programming.
(I will use double spaces though)
In response to Itanium
He asked to move five spaces though, and if a mob was there, to attack it. But, your code is probably more what he's looking for (though he wont understand it). He's probably looking for an attack Final Fantasy style.
In response to Mega fart cannon
Mega fart cannon wrote:
Please get rid of the brackets ({}). All it does is make the code harder to read.

Who cares? Its the programmers preference.
In response to XzDoG
god help me these ppl are arguing on my post
In response to XzDoG
Yes, but when displaying code on the forums, you want it as legible as possible, and not chock full of usr abuse and stuff.
In response to Ol' Yeller
I never understood the bracket thing myself, so if I was a person that was recieving that code I wouldn't be at ease with it.
In response to Justin Knight
Sadly thats not my concern.
Using brackets is a prefrence,I dont do it because I code then go back and add them in; I do it because if I dont then its Hard for me to get a quick grasp of it.


Itanium
In response to Itanium
Using brackets is a prefrence,I dont do it because I code then go back and add them in; I do it because if I dont then its Hard for me to get a quick grasp of it.

Yeah took me awhile to get used to not using them. Though it didn't help that initially the language did require them also :). Just got to remember that when I go and use other languages not to leave hanging ifs :P.
In response to Theodis
BYOND with mandatory brackets ?
(heaven)



Itanium
In response to Itanium
Yeah DUNG version 2 was the first version that processed scope by indentation rather than braces. The source code to most my games were left with thousands of errors due to inconsistant indentation :P.
In response to Theodis
have mercy on my post