ID:173912
Oct 29 2003, 10:26 am
|
|
How do I make it so if a monster attacks diagnal it stops it from attacking?
|
Oct 29 2003, 10:33 am
|
|
If get_dist() returns 1, I think the target must be right next to the sorce. That is, if it only adds the X distance and the Y distance.
|
In response to Yota
|
|
that won't work, straight up attacks are ok, but if they attack diagnally the player can't attack back
|
In response to DarkCampainger
|
|
that won't work, straight up attacks are ok, but if they attack diagnally the player can't attack back Before the AI attack use get_dir() to check the direction from the AI to the player. Then do the following test on the result if(!(dir & dir-1)) |
In response to DarkCampainger
|
|
This is what I added:
get_dir(src,M) It says "warning: statement has no effect" what am I doing wrong? |
In response to DarkCampainger
|
|
DarkCampainger wrote:
This is what I added: get_dir(src,M) It says "warning: statement has no effect" Two problems. First, you didn't take the return value from get_dir()--that value should be a new var, and that should go in your if() instead of dir. The second problem is indentation. The if() is indented too far. Lummox JR |
In response to Lummox JR
|
|
It Worked!
Thanks! How do I get the badguy to move if he can't attack? |
In response to DarkCampainger
|
|
DarkCampainger wrote:
It Worked! Try this one: var/d = get_dir(src, M) |
In response to Lummox JR
|
|
Thanks! That Worked Great =D
|
In response to DarkCampainger
|
|
How did you ever come up with that equation?
D & D-1 I'm gonna try to figure that out. 1st, it returns true if both sides of "&" are true. 2nd, if D = 2 (South), both will be true. 3rd, if D = 5 (Northeast), both are still true. HOW DOES THAT WORK!? EDIT: After more look, 1 (North) and 0 (Center) will return false. |
In response to Yota
|
|
Yota wrote:
How did you ever come up with that equation? 1st, it returns true if both sides of "&" are true.& returns the bitwise and of two variables not the logical and (ie &&). All the cardinal directions(NORTH, SOUTH, EAST, and WEST) directions all have only one leading bit whereas the other directions have some combination. If you and a value with itself minus one you will only get a non-zero value if there is more than one bit set. |
In response to Yota
|
|
Yota wrote:
How did you ever come up with that equation? D=2 returns false (2&1==0), so there's a minor flaw in your analysis, but here's how it looks in binary: 20: 10100 So the test if(D&D-1) returns a nonzero value only if D has 2 or more bits set. If D is 0 or a power of 2, the test is false. Since all of BYOND's directions are bit flags, they all have a single on bit; the diagonal directions combine those, for two on bits. Lummox JR |