ID:273095
 
whats the best way to go about forcing a certain player mimic the movements of another (be it a client or an NPC)?
So that whenever player A stepped in a given direction, player B would step in the same direction...
Note that I don't want north to mean north per se. Rather forwards = fowards.
(so if A is facing South and B is facing East, if A steps south, B will step East)

Im not asking for someone to just write the code for me, just a nudge in the right direction. PUN.
Saucepan Man wrote:
whats the best way to go about forcing a certain player mimic the movements of another (be it a client or an NPC)?
So that whenever player A stepped in a given direction, player B would step in the same direction...
Note that I don't want north to mean north per se. Rather forwards = fowards.
(so if A is facing South and B is facing East, if A steps south, B will step East)

Im not asking for someone to just write the code for me, just a nudge in the right direction. PUN.

You could have something like this.
mob
verb
Walk(mob/M in world)
switch(input("Which way do you want [M] to walk?","Walk")in list("North","South","East","West"))
if("North")
step(M,NORTH)
if("South")
step(M,SOUTH)
if("East")
step(M,EAST)
if("West")
step(M,WEST)

Thats just an example though.
In response to Cyberlord34
I want the user's movement to directly affect movement.
I guess I could have a before and after type check in the Move() proc. And then adjust the target mob accordingly. But I don't know if thats a very efficient way, beit CPU efficiency or code complexity efficiency...
In response to Saucepan Man
var/list/playermobs=list()
client
New()
..()
playermobs+=src.mob
Del()
..()
playermobs-=src.mob

mob
var/mob/mob_controlled
Move(dir)
if(mob_controlled) //if a mob is assigned to it
step(mob_controlled, dir)
return //don't let the original person move
//obviously you can take that out
else ..()
verb/control_mob()
var/mob/m=input("Who do you want to control?") in playermobs|null
if(m) src.mob_controlled=m

Something like that should work nicely.
In response to Vic Rattlehead
It would work, for a good rollbacking issue as you didn't make the mob_controlled a tmp var.

Aside from that, even if you remove that return it won't move the mob.

var/list/playermobs=list()
client
New()
..()
playermobs+=src.mob
Del()
..()
playermobs-=src.mob

mob
var/tmp/mob/mob_controlled
Move(loc,dir)
if(mob_controlled) //if a mob is assigned to it
step(mob_controlled, dir)
return //don't let the original person move
//obviously you can take that out
..()
verb/control_mob()
var/mob/m=input("Who do you want to control?")as null|anything in playermobs
if(m) src.mob_controlled=m
In response to Vic Rattlehead
Thanks very much, that's what I was leaning towards I think.
I do, however, leave the question open in case someone has any better suggestions?
In response to Andre-g1
I forgot to make it a temp var, my bad.
In response to Andre-g1
Ah - but what about when you want to prevent the target from moving itself and only you can move it, whether the target be human or computer controlled...
It could just be that I don't know enough about the Move()proc...?
In response to Saucepan Man
mob
var
iscontrolled
Move()
if(iscontrolled) return 0
else return 1


Something like that.
In response to Saucepan Man
You'd have to freeze the mob.

mob
var/tmp
mob/mob_controlled
being_controlled
Move(loc,dir)
if(mob_controlled) //if a mob is assigned to it
step(mob_controlled, dir)
return //don't let the original person move
//obviously you can take that out
..()
verb/control_mob()
var/mob/m=input("Who do you want to control?")as null|anything in playermobs
if(m)
src.mob_controlled=m
m.being_controlled = 1
client/Move()
if(mob.being_controlled) return // I'm using client move because step() which is being used to move the mob, \
calls Move() and if you put this check on Move() it won't work. Because it'll return before ..() is called

..()


[Edit] Made a slight mistake. Fixed.

As far as moving and stopping npcs, you'll have to show how you handle their movement. :P
In response to Vic Rattlehead
Hm, no.

Move() doesn't work if you return 0, it works if you call ..().

Besides, if he tried something like that, the snippet I posted before wouldn't work, because it would stop the mob's movement completely.

Check [link].
In response to Andre-g1
Um yeah. NPC movement.
I don't. I don't think.

I have a Move() proc that applies to any and all mobs.
Mobs' wander / attack/chase is controlled with step, step_to, step_towards, and step_away, where Bump() calls a punch/attack procedure...
In response to Saucepan Man
Show the wander proc, you'll have to add a check there to see if they're being controlled. If they are, simply don't call step :)
In response to Andre-g1
Darn. I was hoping there was a nicer way - I intend to add in various confused movements too. up = down||left right=up||down etc etc. QQ
In response to Saucepan Man
Show the wander() proc, really. Adding the check I mentioned wouldn't stop you from adding confused movement at all.
In response to Andre-g1
    Wander_Sentry()
set background=1
if(src.dead) return
var
w=0; t=0
for(var/mob/h in oview(12,src))
if(!istype(h,/mob/AI)) src.VillageHitListCheck(h)
if(istype(h,/mob/player)) w++
if(h in (src.HitList|src.VillageHitList)) t++
if(t)
src.AI()
else if(w)
if(get_dist(src,src.respawn)<5) src.steprand()
else step(src,get_dir(src,src.respawn))
spawn(40) src.Wander_Sentry()
else
if(get_dist(src,src.respawn)>5) step(src,get_dir(src,src.respawn))
spawn(66) src.Wander_Sentry()



Probably could be slightly more efficient.
Would making it a while() type loop be worthwhile? ._.

'respawn' is the mobs mapped location, thus assigned via the New() proc.
In response to Saucepan Man
Can you show AI() also ?

[EDIT]

Wander_Sentry()
for()
if(src.dead||being_controlled) return // this proc would then be called again when being_controlled turns to 0\
as I said before, I can't think how this would injure confused movement. :P Confused movement would be handled in mob/Move()\
with turn() affecting both the npcs and players.

var
w=0; t=0
for(var/mob/h in oview(12,src))
if(!istype(h,/mob/AI)) src.VillageHitListCheck(h)
if(istype(h,/mob/player)) w++
if(h in (src.HitList|src.VillageHitList)) t++
if(t)
src.AI()
else if(w)
if(get_dist(src,src.respawn)<5) src.steprand()
else step(src,get_dir(src,src.respawn))
sleep(40)
else
if(get_dist(src,src.respawn)>5) step(src,get_dir(src,src.respawn))
sleep(66)


This is considering AI() sleeps, since I don't know what AI() does :P
In response to Andre-g1
mob/AI/VillageNinjas
AI()
if(src.dead) return
var/c=0
var/mob
M; m; t
src.HuntList=new/list
for(M in range(9,src))

if(!(M in src.YieldList)) src.VillageYieldCheck(M)
if(M in src.YieldList) {src.HitList-=M; src.VillageHitList-=M; src.YieldList-=M}
else if((M in src.HitList)||(M in src.VillageHitList)) src.LocateTarget(M)
for(m in src.HuntList) c++
if(c)
t=pick(HuntList)
if(src.Wounds<30)
if(!isnull(t)) src.Attack1(t)
else AI()
else
switch(pick(1,2))
if(1)
if(!isnull(t)) src.Attack1(t)
else AI()
if(2)
if(!isnull(t)) src.Attack2(t)
else AI()
else spawn(25) src.Wander_Sentry()

urgh. length(HuntList) for the win.

Forgive some of my stupid questions. i.e. confused movement.
In my mind i've got old methods that didn't work, but that was when i didn't know what i was doing. In short I end up missing now-obvious solutions :\
In response to Saucepan Man
No problem, I'm here to help, or at least try ;)

Change the spawn in that proc to a sleep() and remove the Wander_Sentry() call and it should work fine.