turf
Click()
for(var/mob/npc/N in view())
walk_to(N, src)
Problem description:
I want the npc to walk where I click. But he does not move.
ID:1269743
![]() May 21 2013, 11:53 am (Edited by moderator on May 21 2013, 11:56 am)
(See the best response by FIREking.)
|
|
Code:
turf Problem description: I want the npc to walk where I click. But he does not move. |
![]() May 21 2013, 12:31 pm
Best response
|
|
try range(10, src) instead of view()
|
How are you meant to be selecting the NPC for this to work? The code you've shown (with Fireking's correction) will walk all NPCs in a certain range of the place you clicked, to that place. Is that correct?
|
At moment... I'm just trying to learn how it works.
I want to move some selected npcs to chase another player. Like a army in RTS game. :] |
That's because you have it under turf at the moment, if you want it to move "towards anything" try using atom/movable instead of turf.
|
atom/movable I tried that way. But now they do not walk. |
The type of system you wish to implement, I'm afraid, isn't an easy one. Perhaps check out the developer resources http://www.byond.com/developer/ to see if anyone has accomplished this. Even if you're only interested in learning, its worth it to look at someone's implementation to see how they accomplished such a task.
Short answer is, you can't do it with only a few lines of code. Here's a limited one: world/mob = /mob/player There's a lot left to do in the above example, but it should get you started. To make a selection box, you're gonna wanna record the turf clicked on with mouse_down and the turf resulting on mouse_up. From there, you'll create a block of turfs to search for units in, and add those units to a selection list. But when you do this, then you'll have to handle your selection dynamically (meaning, it could contain more than just a single unit)... The more you want this to accomplish, the more complex the cases and conditions will become. |
Any particular reason you didn't just cast the usr to mob/player, Fireking? Seems fair to show how you'd do it "properly".
|
Stephen001 wrote:
Any particular reason you didn't just cast the usr to mob/player, Fireking? Seems fair to show how you'd do it "properly". Laziness haha, I'll correct. |
http://www.byond.com/developer/Metamorphman/mSelect
I found this. But it is totally without comments. I'll try to do something simple, without using DragSelect yet. is possible to make them attack another player without much trouble? something like ... summon them and send them to kill things. |
I was working on something like this, If I find the file I'll post the code, but I would probably make a AI while statement that has your units attack any enemy units within view.
Once you have the movement system down then having them attack is relatively easy. In my system I made it to where the player could build grunts select them and then deselect them or move them to a location and attack other mobs. I will try to find it and make some documentation for it and post it, perhaps it will help others start making RTS like games. TL;DR Just make a while proc to handle attacking mobs in oview and use the turf movement for now and they will just attack whatever enemies they see. PS The only issue will be you will need to make some kind of var like Enemy = 1 and use a IF statement to check for it so you don't have friendly fire. Good luck and I hope you learn what you wanted to learn, Bloodocean7. |
mob It worked. Now i want them to search and destroy! |
This is how I would do it, I just wrote this it could be wrong or buggy but you get the general idea :)
Also be sure to add Enemy = 0 to the players mob vars and make the enemy have Enemy = 1 as a var so that your units will only attack enemy units and not you are your own units. mob/proc/attackAI() |
Thanks! It will be helpiful!!
I will use your code... but i tried to chase the mob using a list... can you tell me where I am wrong? Chase() |
Well out of context it looks like undefined vars or something, I recommend using walk_to() or something smiler its simple and easy and it will get the job done, if your goal is to learn going about it in the easiest way will help you to reduce frustration and get results :)
|
I thought so too, it seemed as though he didn't define any variables in the list. Thanks for confirming :)
|
mob It work... but my name appears at list... how i can remove my name from the list? i want to put time limit at summon spawn... and a max number of summons too... can someone help me?? :]] |