ID:1628025
 
(See the best response by GhostAnime.)
Code:
mob/PC/Login()
spawn()MovmentLoop()


Problem description:i have the movment code but its to mob/player

i want to use it to mob/pc and mob/player how can i use it in mob/pc with out duplicate it?

Define MovementLoop() in /mob. Then mob/PC and mob/Player have it.
i will try thx

Edite : the movment code dsnt work if i do that
it works when i change mob/pc to player
but the icons and some code are messed
Without knowing what MovementLoop() does, I can't help.
its allowing you move diagonal

mob
// This is just so tile transitions animate smoothly.
animate_movement=SLIDE_STEPS
var
// How many ticks to wait between steps.
// Must be a positive number or 0.
move_delay=1

// If movement needs to be disabled for some reason.
move_disabled=0

// This will prevent multiple instances of MovementLoop() from running.
move_int=0

// These track which directions the player wants to move in.
tmp
key1=0
key2=0
key3=0
key4=0

proc
// MovementLoop() is the main process which handles movement.
// It does a few simple checks to see if the player wants to
// move, can move, and is able to move. Once the player moves
// it will delay itself for a moment until the player is able
// to step again.
MovementLoop()
var/loop_delay=0
while(src)
if(loop_delay>=1)
sleep(world.tick_lag)
loop_delay--
else
if(key1||key2||key3||key4)
// if(canMove())
if(stepDiagonal())
loop_delay+=move_delay
sleep(world.tick_lag)

// canMove() is where you're able to prevent the player from moving.
// Use it for things like being dead, stunned, in a cutscene, and so on.
/* canMove()
if(move_disabled)return FALSE
return TRUE*/



// stepDiagonal() checks all the keys the player is holding then
// mixes them together into diagonal steps. In cases where both
// keys for one axis are being pressed they are both ignored.
//
// In order to prevent players from getting stuck on walls when
// stepping into them diagonally, diagonal steps are broken into
// two different steps along the x and y axes.
//
// After stepping the player's direction is corrected and it reports
// back if the player was able to step or not so MovementLoop() knows
// when to apply a step delay.
stepDiagonal()
var
dir_x
dir_y
switch(key1)
if(NORTH)if(key2!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key2!=NORTH&&key3!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key2!=WEST&&key3!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key2!=EAST&&key3!=EAST&&key4!=EAST)dir_x=WEST
switch(key2)
if(NORTH)if(key1!=SOUTH&&key3!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key3!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key3!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key3!=EAST&&key4!=EAST)dir_x=WEST
switch(key3)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key4!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key4!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key4!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key4!=EAST)dir_x=WEST
switch(key4)
if(NORTH)if(key1!=SOUTH&&key2!=SOUTH&&key3!=SOUTH)dir_y=NORTH
if(SOUTH)if(key1!=NORTH&&key2!=NORTH&&key3!=NORTH)dir_y=SOUTH
if(EAST)if(key1!=WEST&&key2!=WEST&&key3!=WEST)dir_x=EAST
if(WEST)if(key1!=EAST&&key2!=EAST&&key3!=EAST)dir_x=WEST

if(dir_x)
if(dir_y)
step(src,dir_x)
step(src,dir_y)

// If you don't want diagonal steps broken in two use this line.
//step(src,dir_x+dir_y)

dir=dir_x+dir_y
return 1
else
step(src,dir_x)
dir=dir_x
return 1
else
if(dir_y)
step(src,dir_y)
dir=dir_y
return 1
else return 0

// keySet() and keyDel() are used to change the order in which the player
// has pressed their movement keys. It's crucial to preserve the sequence
// of key presses in order to determine which directions are prioritized.
keySet(dir)
if(key1)
if(key2)
if(key3)key4=dir
else key3=dir
else key2=dir
else key1=dir

keyDel(dir)
if(key1==dir)
key1=key2
key2=key3
key3=key4
key4=0
else
if(key2==dir)
key2=key3
key3=key4
key4=0
else
if(key3==dir)
key3=key4
key4=0
else key4=0
Okay so the only people that can use MovementLoop() are your players. Why? It takes information from the keyboard to work.

mob/Player is the only place it should be.

If you want movement for anything that isn't a player you must use something else.

MovementLoop won't work with anything that isn't a player.
you right but when i put it in

mob/player/login()
it dsnt work
and shold i add usr to while() in the movment()?
Is this from a library or demo? It should include an example of how to use it. Basically it's not working because I don't think you've got the key macros.

Basically when you press a key, you want it to call a process that remembers the key.

The library should tell you how to do this. If you don't have the keys setup, it won't do anything.
its from demo and the readme dsnt explain much like i said if i change the mob/PC/login()
pc -> Player it works but the icons missin from the player and the login screen
Okay I'm just going to say I can't help. I thought knew what you want but I can't understand you.

Sorry but maybe some one else can help you.
i want to make the player to move diagonal

i have 2 login

1 . mob/Player/login() - when creating new char
2. mob/PC/login() - when login after the creation(PlayerChar)

when i change the PC to Player it works but when i do that ther some bugs

all i need xD is moving diagonaly for the players not only up , down , left ,and right

can you help me do this ?
Best response
Players should be able to move diagonally already in BYOND (though, by default, it is using the numpad).

If you see the interface's macro file, you can see they are already defined as .northeast, etc.

Simply define new diagonal keys through the interface, no hacking needed since the demo you are using is likely pre-4.0


What is your objective using that (inefficient) snippet, making a combo system?
-------------------

Edit: As people told you, you should place that spawn() under /mob/Player/Login()

mob/Player/Login()
spawn()MovmentLoop()
return ..()


The reason why it causes other issues to you is because you are NOT calling ..() which allows other instances (including the default action) of that proc.

I think it makes more sense of have that under client/Move() but... w/e floats your boat.

-------------------

Now, if you want ONLY the /mob/Player to use diagonals and NOT NPCs or other /mob types, that's different. You can do this by checking the directional bit flags
atom/movable/Move(NewLoc,Dir=0,step_x=0,step_y=0)   //  Called when any /atom/movable objects (including /obj & /mob) attempts to move
if(!istype(src, /mob/Player)) // If the object moving is not a Player mob type

// Check if the person is moving diagonally by seeing if the direction is going north/south AND east/west
if((Dir & (NORTH|SOUTH)) && (Dir & (EAST|WEST)))
// aka if((Dir & 3) && (Dir & 12))
// Another alternative is if(Dir & (Dir - 1)). If TRUE, the object is moving diagonally
return 0 // Deny diagonal movement

return ..()
what i want is when i press with a character mob/PC(Player Character) when thers 3 for each Player

Up and Left it go to NorthWest and so on
In response to CrazyDog
CrazyDog wrote:
when thers 3 for each Player

No idea what you meant by that...

And that snippet you posted already does that...

Unless you put NORTH/SOUTH & EAST/WEST at the same sequence entry (e.g. NORTH, WEST, EAST, SOUTH).

In that example, because how the snippet is, this is what it finds:

key# -> (current X, current Y)

key1 -> (0, 0) <-- Because SOUTH is present on key4, key1 is NORTH, it disallows you to set anything

key2 -> (0,0) <-- Same scenario as above but this is because EAST is in key3
key3 & key4 -> (0,0)

---

Now, if you did NORTH, SOUTH, EAST, EAST, it would do:
key1 -> (0,0)
key2 -> (0,0)
key3 -> (EAST,0) // No WEST in any key
key4 -> (EAST,0)

---

And if you did (any combination) of NORTH, NORTH, EAST, EAST, you should be able to move NORTHEAST because there is no SOUTH or WEST entered.

-----------------------------------------------------

Now, show us your snippet where you placed keySet()/keyDel() (not its definition but when the person presses the keys). What is your world.tick_lag set to?

If the issue is that there's not enough time for the two keys (ex: you press UP, RIGHT and the person moves NORTH then EAST individually instead of NORTHEAST), try increasing your move_delay to give more time for entry.
This is the first code its macro set + del and set keys
thos are the only 2 codes i have for diagonal movment

client
New()
..()
setMacros()

// These are here so the default movement commands don't interfere.
North()
South()
East()
West()
Northeast()
Northwest()
Southeast()
Southwest()

proc

// setMacros() injects movement commands into all macro lists.
setMacros()

var/macros=params2list(winget(src,null,"macro"))
for(var/m in macros)
/*
winset(src,"W","parent=[m];name=W;command=north")
winset(src,"W+UP","parent=[m];name=W+UP;command=north-up")
winset(src,"A","parent=[m];name=A;command=west")
winset(src,"A+UP","parent=[m];name=A+UP;command=west-up")
winset(src,"S","parent=[m];name=S;command=south")
winset(src,"S+UP","parent=[m];name=S+UP;command=south-up")
winset(src,"D","parent=[m];name=D;command=east")
winset(src,"D+UP","parent=[m];name=D+UP;command=east-up")

*/


// Arrow keys
winset(src,"NORTH","parent=[m];name=NORTH;command=north")
winset(src,"NORTH+UP","parent=[m];name=NORTH+UP;command=north-up")
winset(src,"WEST","parent=[m];name=WEST;command=west")
winset(src,"WEST+UP","parent=[m];name=WEST+UP;command=west-up")
winset(src,"SOUTH","parent=[m];name=SOUTH;command=south")
winset(src,"SOUTH+UP","parent=[m];name=SOUTH+UP;command=south-up")
winset(src,"EAST","parent=[m];name=EAST;command=east")
winset(src,"EAST+UP","parent=[m];name=EAST+UP;command=east-up")



mob/PC

// This will initiate movement whenever a client logs into a /mob/player.
/* Login()
..()
spawn()
MovementLoop()*/


// These are the actual commands players will be using for movement.
// They're set to instant so player inputs react as quickly, as possible.
// Having them hidden isn't required, it just prevents them from filling
// up a statpanel.
verb
north()
set
hidden=1
instant=1
src.keySet(NORTH)
north_up()
set
hidden=1
instant=1
src.keyDel(NORTH)
south()
set
hidden=1
instant=1
src.keySet(SOUTH)
south_up()
set
hidden=1
instant=1
src.keyDel(SOUTH)
east()
set
hidden=1
instant=1
src.keySet(EAST)
east_up()
set
hidden=1
instant=1
src.keyDel(EAST)
west()
set
hidden=1
instant=1
src.keySet(WEST)
west_up()
set
hidden=1
instant=1
src.keyDel(WEST)