ID:163527
 
How do I make like a pokemon game (just a example) when I can catch a mob (the mob dissapears) then use a release verb and the mob comes up behind you and follow you? Also how can I make the mob attack a selected target (also how do I select a target)?
http://developer.byond.com/hub/RurouniDragon/FollowMe

Theres a demo on making a mob follow you.
In response to CrazedHunter
There we got one thing :P
Not many will be willing to offer completed program snippets for you to copy and paste into a project; you should evaluate some demos, tutorials or libraries and take a crack at it, then bring any relevant code problems to the forum. You'll find more are willing to help when you're showing initiative to learn and try it yourself first.
In response to Mobius Evalon
I figured out some parts myself of ways to do it (maybe since it's not tested) but it would just give a whole [dirty word, sorry!] of code that I maybe could avoid :/

I mean I could give the mobs I'm trying to capture a variable like "catch" and when it turns on it will follow the one that catched it. Could someone give me a example code how I define a certain mob from all other? Like mob/M = mob/player, ok there we got that M is a player but that could be any player right? Can I use "usr" and "src" in this situation? Like if "catch" equals 1 then "follow usr"?

Well there we go for the catch system :P Will look if I find any libs that maybe can help me with the "select mob" part...

EDIT: Nope, didn't find what I looked for :(

I get confused with the select part that it should only attack the mob the player choose when "catch" equals 1...

And what's this about "when you're showing initiative to learn and try it yourself first." I've tried it myseld, in my mind and I get really confused about everything above...Why would I ask if I didn't want to learn? People ask questions because they don't know the answer......

Sorry if something above was bad wroten since I had a lot on my mind then so I just wrote everything I thought of without no special order.
In response to Syltmunk
Show us the code you're trying to make functional and we'll try and help you resolve it. I don't know how to fix your attack code if I can't see it.
In response to Evre
Even thought this should be in code problems....
mob/Monster/Hiroshi_Ghost
icon = 'ghosts.dmi'
icon_state = "g1d"
overlays = newlist(/obj/g1head)
density = 1
HP = 15 // its power
Str = 3
Def = 0
Exp = 5//ow much exp it gives
Money = 15
var/attacking = 0
var/mob/player/P // it is way easyer it type P then to type mob/player all the time :)
New()
. = ..()
spawn()//starts to do the next command
Wander()
proc/Wander()
while(src)//makes sure it is doing it
var/Found = FALSE// flase is the same as 0 and ture means 1, just did diferent for a while XD
for(P in oview(5,src))//if the player is within 5 steps.
step_towards(src,P)//steps towards the player
Found = TRUE
break // makes it so it wont just leave the person it is chasing and go after something else
if(Found != TRUE)
step_rand(src)//steps randomly for a while
sleep(10)
sleep(5)
Bump(mob/M)
if(istype(M,/mob/player))
Attack(M)
proc/Attack(mob/M)
if(catched == 0)
if(!attacking)
attacking = 1
spawn(15)
attacking = 0
flick("attack",src)//shows the mnster attacking. OPTION :)
sleep(15)
var/damage = rand(1,Str) - round(rand(M.Def*0.6,M.Def*1.25))
if(damage <= 0)
damage = 1
M.HP -= damage
view(src) << "[src] attacks [M]!"//tell people who and what got attacked
view(src) << "[damage] damage!"// says how much damage
else
if(catched == 1)
if(mob_chosen == usr)
usr << "You can not attack yourself"
else
wander()


That's a example but since I don't know things I have to know to make it working I made up some stuffs like "mob_chosen". So what I need there is how to select a mob and how to make the catched mob go and attack the selected mob.
In response to Syltmunk
anyone get what I mean?
In response to Syltmunk
Ooof, italian-style code :P

I'll give you a brief example of one way to handle a catch and release system. This is just for illustration, I wouldn't plunk this into your code:

mob
player
var/mob/monster/chosen //stores our chosen monster

proc/Catch(mob/monster/m) //called upon successfully catching a monster
m.owner = null //monster isn't out, so owner is undefined
walk(m,0) //cancel any movement
m.Move(src) //move the monster into the player's inventory; alternatively you could replace src with a reference to an object, such as a Pokeball
if(!chosen || isnull(chosen)) chosen = m //if the player hasn't selected a monster then it defaults to the next one caught.

proc/Release() //called to release the chosen monster
if(!chosen) return 0 //return FALSE if there is no chosen monster
chosen.Move(locate(src.x,src.y-1,src.z)) //move the monster one tile south of the player.
chosen.owner = src
chosen.Follow()

monster
var/mob/player/owner //store the monster's owner
var/following = 0

proc/Follow()
if(!owner)
return 0 //return false if no owner is defined
following = !following
switch(following)
if(1)
walk_to(src,owner,0,5) //follow the owner
if(0)
walk(src,0) //stop following

Follow?
In response to CriticalBotch
That's looks good :)

I will try it tomorrow, time for bed :P

In response to Syltmunk
tried copy paste but I get "Catch.dm:13:error::invalid expression"

on "chosen.Move(locate(usr.x,usr.y-1,usr.z))"
In response to Syltmunk
Well, as I mentioned, I wouldn't just plunk it into your code. The example was for you to see and consider, not for actual use.

Also, if you're trying to emulate the snippet I provided, I will have to borrow from Lummox: No put usr in proc, ungh.

I specifically had it set for src, which will always be the mob that the proc belongs to.

As for the actual error, I'll have to take another look in a minute.

Edit: Looks like the lines under the if statement above the error shouldn't be indented (no idea why I had them that way, my apologies).
In response to CriticalBotch
Not following you but that may be because I changed some stuffs in your code so this is how it look for me:

        proc/Release() //called to release the chosen Monster
if(!chosen) return 0 //return FALSE if there is no chosen Monster
chosen.Move(locate(src.x,src.y-1,src.z)) //Move the Monster one tile south of the player.
chosen.owner = src
chosen.Follow()
In response to Syltmunk
I don't think you're quite getting what I'm saying; you don't want to use the code I provided as an actual system. It was merely meant to illustrate a possible way to do it, and a poor way at that. In the above snippet, reduce the indent under the if(!chosen) return 0 section by one.

Seriously though, read through it and see what the snippet was supposed to do, learn from it, and make your own. Just plugging what I put up into your game will make your game less, not more.
In response to CriticalBotch
Yeah I think I will make my own since your example really helped me.

Well it's my own type of combinations so in a way it's still my game :P
mob
var/list/party // this is your party
var/mob/follower // this is who will follow you when you move
proc
AddPartyMember(mob/M)
if(!party.len) // party is empty
party = list(M) // set it to M
follower = M // he will follow you
else
var/mob/lastmember = party[party.len] // get the last member
lastmember.follower = M // make his follower M
party.Add(M) // add him to your party
Move(newloc,newdir)
. = ..() // set . to whatever the parent returns
var/oldloc = loc // this is your location before you move
var/olddir = dir // this is your direction before you move
if(. && follower) // if movement was successful and you have a follower
follower.Move(oldloc) // move him behind you
follower.dir = olddir // set his dir to yours like in the pokemon series
proc
CatchPokemon(mob/pokemon/P)
..() // you will probably override this so call ..()
AddPartyMember(P) // add P to your party
src << "You have caught \an [P]" // hey you caught him
ReleasePokemon(mob/pokemon/P) // this is how we safely remove a pokemon
if(!(P in party)) return // safety check
party.Remove(P) // move the pokemon
if(!party.len) return // don't loop through an empty party
for(var/i = 1 to party.len-1) // we need to loop through every member in the party but the last one
var/mob/current = party[i] // get the current member
var/mob/next = party[i+1] // he should follow the current member
current.follower = next // so do it

If you have any questions or would like me to explain more feel free to ask :)
In response to Khalamari
oh....my...god! O.O Will look trough it O.o
In response to Khalamari
I get this error in game >.<

"runtime error: Cannot read null.len
proc name: AddPartyMember (/mob/proc/AddPartyMember)
usr: the hoisetg (/mob/player/male)
src: the hoisetg (/mob/player/male)
call stack:
the hoisetg (/mob/player/male): AddPartyMember(null)
the hoisetg (/mob/player/male): CatchMonster(null)
the hoisetg (/mob/player/male): Catch(Hiroshi Ghost (/mob/Monster/Hiroshi_Ghost))"

Since I'm not familiar to "len" I don't really know what's wrong.
In response to Syltmunk
Look up lists in the reference or in dream maker. The problem is that party isn't initialized (the object is null) so it can't access the len variable (which is the length of the list; see also the length() proc).
In response to CriticalBotch
So how do I fix it?

I want to give party a value?
Page: 1 2