ID:271973
Feb 5 2008, 10:02 pm
|
|
I was wondering how to program in range attacks. As in, I push a button and then a beam is shot out in front of me untill it hits something to dense (and the dense thing, if a mob, taking damage).
|
In response to YMIHere
|
|
Well, I've had to modify it a little and it's not working. I can't see why, so can you help me out a bit more please?
obj/projectile // Using a projectile subtype so mob/Spell |
In response to Demon_F0rce
|
|
What isn't working, is it just not shooting or will it not compile? I used spaces as my indentation so if it's giving you indentation errors you might have snuck a tab in while editing (it's probably better to tab it all anyway).
obj/projectile // Using a projectile subtype so If that doesn't work for you double check the icon and icon state names. It still works for me. |
In response to YMIHere
|
|
It simply wont shoot. I've tried with everything retabbed and still there's nothing. Even when I fixed up the problem that Spells.dmi was in a folder so it should be Icons/Spells.dmi.
|
In response to Demon_F0rce
|
|
Does the player say Flippendo {edit: and if he does are you sure it's the one where he actually shoots?}? Have you overridden any higher level atom or objs New() proc and forgotten to call ..()?
|
In response to YMIHere
|
|
The player just says Flippendo and nothing happens after that, and there's only one verb. As far as I know, no. I've shown you the whole program with it and nothing seems to be wrong from my perspective. Maybe I've mucked it up when I put it into the verb, I dont know.
|
In response to Demon_F0rce
|
|
That's just one of the reasons you shouldn't just copy code found or given to you. Learn how his code works and make your own, better suited to your game and wants, etc.
|
In response to Demon_F0rce
|
|
There are two places in the verb where the player says flippendo though, and only one that fires the beam. Try adding some debug text.
mob/Spell Of course this should probably be cleaned up a bit. mob/Spell |
In response to YMIHere
|
|
Ah yes, it's working now. That teaches me for not looking at what I've done more closely >_<. Well, thanks for your help YMIHere!
|
In response to Kaioken
|
|
yes but you can get more use to the different versions of the code i like to mess around and stuff
|
In response to Kozuma3
|
|
Look at the damn date before you reply and dig up ancient topics for no reason. :\
|
I was wondering how to program in range attacks. As in, I push a button and then a beam is shot out in front of me until it hits something to dense (and the dense thing, if a mob, taking damage).
First you'll need a beam object.
Easy enough, now we can give players the ability to create the beam. Use get_step() to place it in front of the player.
Compile and run and you've got yourself a beam that shoots out of the player. Doesn't move yet, but it's a good start. =) Did I mention that I like that you were specific with your request? Very nice to see. Oh right, moving on to movement.
Since all this projectile is meant to do is move, we'll put that on the object itself. Since it's going to need to know which direction to move (and you'll probably want to know who shot it when it destroys someone, etc.) we'll add some more parameters to the projectiles New() proc while we're there.
This part is a little more in-depth so allow me to explain. First we're letting the projectile know who shot it. Then, instead of creating the object in front of the shooter, we create it outside of the map (creation is technically done in the verb with new) and move it to it's starting location. This is so Bump() will be called (which we will use in a bit to damage any mobs that were hit) if needed, and as needed, the projectile can be deleted. Then there's the loop.
step() will attempt to move a mob or obj one tile in a certain direction, if it moves the proc will return a TRUE value (1). If it doesn't it will return a FALSE value (0). So what the loop is saying is while the object can still move forward sleep for a bit then try again. Now whenever the projectile stops moving (whether it's bumped something or reached the end of the map) the loop will exit and the projectile will be deleted.
Of course, now we have to change our verb to reflect the new additions. If you'll notice I'm now using named arguments, this will prevent Dream Seeker from creating the object at the location of the first argument because it sees all of my arguments as used.
Now if you run it you should have a projectile that moves in a straight line and disappears when it hits something. One thing left, killing! >=D
I've done some type casting for you, but I have no idea what your variables for health are so I can't hurt the victim. It would be something like victim.hp-=10 (or victim.TakeDamage(10) if you're using a really robust system), and shooter should get some experience for hitting the mark don't you think? ;)
To wrap up I've condensed it and added some spiffy new attacks. =)
Happy killing!