ID:160480
 
ok, so I've been trying to do this for couple of days now, so how do I do attacking system where you first target ur opponent and when ur next to him, u attack him? I've tried this but my game crashes when I target opponent :/
Would depend how you plan on targetting. If your game is crashing, you could post what code you may have so we can see why it might be doing so.
How do you go about doing the "targetting" part of the process? Do you click to target? Do you use a verb to target? What?

As for the attacking part, I'm sure it would have to go into the an Attack proc. Something along the lines like: "for mob in oview..." (if not view or get_step) "...Attack()". Where 'Attack()' is calling the attack proc. That's what it would be if you did a DM to English translation. I'm not totally sure how you'd code it.
In response to Mizukouken Ketsu
My targeting is by clicking. I put my current code here now (doesn't crash anymore)


There isn't no attacking as it only says hi everyone when ur next to target, or atleast it should do that :D



mob
var
mob/target//variable of type mob, named "target"
targetoverlay//the overlay for the target you have selected
targeted=0//if you already somthing targeted
tmp/Mob1
tmp/Mob2
attackon = 1
attackable=1
attacking = 0
proc//calls for a proc
getTarget(var/mob/M)//name of the proc
if(M != src) //attacking yourself is bad form
if(target==null)//if if you have no target
target = M //get the target
if(client)//if it is a client(real person)
targetoverlay = image('target.dmi',M)//calls icon from life.dmi, attaches icon to mob, icon state = flash
usr << targetoverlay //only allow the usr to see it
else//otherwise
del(targetoverlay)//remove the target's overlay
target = null//no more target
attack()
set background = 1
src.attacking=1
var/mob/M
start
for(M in oview(1,src))
if(src.target == M)
world << "Hi everybody!"
sleep(40)
goto start
else goto start


Click()//click the mob
usr.getTarget(src)//activate the gettarget proc
if(src.attacking==0)
attack()
In response to Syntty
Why are you creating a loop there with the goto start. Its set to the background so the error doesnt come up and shouldnt crash but your creating an invinte loop there is that what you want. The only thing i can think of that would be useful to do that (and only barely) is if you wanted it to say hi everytime you get close but theres better ways to do that.
In response to Syntty
Syntty wrote:
My targeting is by clicking. I put my current code here now (doesn't crash anymore)


There isn't no attacking as it only says hi everyone when ur next to target, or atleast it should do that :D



mob
> var
> mob/target//variable of type mob, named "target"
> targetoverlay//the overlay for the target you have selected
> targeted=0//if you already somthing targeted
> tmp/Mob1
> tmp/Mob2
> attackon = 1
> attackable=1
> attacking = 0
> proc//calls for a proc
> getTarget(var/mob/M)//name of the proc
> if(M != src) //attacking yourself is bad form
> if(target==null)//if if you have no target
> target = M //get the target
> if(client)//if it is a client(real person)
> targetoverlay = image('target.dmi',M)//calls icon from life.dmi, attaches icon to mob, icon state = flash
> usr << targetoverlay //only allow the usr to see it
> else//otherwise
> del(targetoverlay)//remove the target's overlay
> target = null//no more target
> attack()
> set background = 1
> src.attacking=1
> var/mob/M
> start
> for(M in oview(1,src))
> if(src.target == M)
> world << "Hi everybody!"
> sleep(40)
> goto start
> else goto start
>
>
> Click()//click the mob
> usr.getTarget(src)//activate the gettarget proc
> if(src.attacking==0)
> attack()
>
>






        getTarget(var/mob/M)//name of the proc
if(M != src) //attacking yourself is bad form
if(target==null)//if if you have no target
target = M //get the target
if(client)//if it is a client(real person)
targetoverlay = image('target.dmi',M)//calls icon from life.dmi, attaches icon to mob, icon state = flash
usr << targetoverlay //only allow the usr to see it
Okay, so basically you're doing this: if you're attacking yourself AND attacking nobody AND if it's a real player then it targets them? That must be hard to do :s

I don't think the loop inside a loop helps either. I'll update this (maybe) with a small example.
In response to Speedro
Here's some crap with some useless code in it. :)


mob
var
target
targetted=0
mob
targetting
list
targetters=new

proc
target(mob/targetter,mob/targetee) //Just to make it confusing.. XD
if(targetee==targetter)
targetee<<"lawl yew newb."
return
targetee<<"Kay, yer targetted by [targetter]"
targetter<<"lyk, wannah attak [targetee] lole?"
///////////////////////////
del targetter.target
targetter.target=image('target.dmi',targetee)
targetter<<targetter.target
targetter.targetting=targetee
targetee.targetters+=targetter
mob
verb
say(msg as text)
if(src.targetting)
src.targetting<<"You're targetter says: [msg]"
src<<"You say to your target: [msg]"
else
world<<"[src] says: [msg]"




client
Click(mob/m)
if(istype(m))
usr.target(usr,m)
.=..() //not to mention this is in the wrong spot.
Enjoy. O_o I made a lot of useless things, like that list has absolutely no purpose.