#can someone help me understand why this works perfectly for ranged attacks but not melee?

17 messages · Page 1 of 1 (latest)

pseudo pike
#

ive been following seargent indie's tutorial on strategy rpg (dungeons and dragons style), and ive been successful in making it more like final fantasy tactics so far.

so, ive run into an issue with the sneak attack part, it works perfectly for ranged attacks, but with melee, depending on the attacker's position, the attack target's unit team check seems to not be checking every grid space around the attack target.

positions that didnt work:
unit1 on the right of the enemy unit, unit2 on the left
unit1 on bottom of the enemy unit, unit2 on left or top or right
unit1 on top of the enemy unit, unit2 on right and left

   positions that worked correctly
    unit1 on right of the enemy unit, unit2 on the  top or bottom
unit1 on left of the enemy unit, unit2 on top right and bottom work
unit1 on top of the enemy unit, unit2 on bottom worked

unit 1 is the one with sneak attack.
unit 2 is another party member.

inside my hit check script (takes _attacker and  _attackTarget arguments)

//if the attacker has sneak attack
if(_attacker.sneakAttack == true){
  tempNode = combatGridMap[_attackTarget.gridX, _attackTarget.gridY];
//look at the targets neighbors and find out if any of them are not on the same team
  for(var i = 0; i < ds_list_size(tempNode.neighbors); i++){
    current = ds_list_find_value(tempNode.neighbors, i);
//if the target is next to something hostile to it, apply sneak attack
        if(current.occupant != noone){
          if(current.occupant != _attacker){
            if(current.occupant.unitTeam != _attackTarget.unitTeam){
            
        _attacker.applySneakAttack = true;
            }
          } else {_attacker.applySneakAttack = false;}
        }
      }// for loop end
    }//if the attacker has sneak attack check end

the code for how im making the grid is too long for this post and apparently i cant make another one

surreal ocean
#

ive tried reading and helping but its quite unclear whats supposed to happen and whats happening instead, maybe bc i never played the games in question

pseudo pike
#

so, im trying to build a strategy rpg. sneak attack is an ability in dungeons and dragons where if a unit that is hostile to the unit youre attacking is next to the unit youre attacking, then you get bonus damage. also:
the grid is being created in a battle manager object

mapWidth = room_width/TILE_SIZE;
mapHeight = room_height/TILE_SIZE;

#region create the nodes
//create the nodes

for(xx = 0; xx < mapWidth; xx += 1){
    for(yy = 0; yy < mapHeight; yy +=1){
        combatGridMap[xx,yy] = instance_create_depth(
        xx*TILE_SIZE,
        yy*TILE_SIZE,
        layer_get_depth("Collision"),
        obj_node
        );
        combatGridMap[xx,yy].gridX = xx;
        combatGridMap[xx,yy].gridY = yy;
        
    }
}
#endregion

#region populate neighbor lists#
// populate neighbor lists
for(xx = 0; xx < mapWidth; xx += 1){
    for(yy = 0; yy < mapHeight; yy +=1){
        node = combatGridMap[xx,yy];    
        //add left neighbor
        if(xx > 0){
        ds_list_add(node.neighbors, combatGridMap[xx-1, yy]);
        }
        //add right neighbor
        if(xx < mapWidth - 1){
        ds_list_add(node.neighbors, combatGridMap[xx+1, yy]);
        }
        //add top neighbor
        if(yy > 0){
        ds_list_add(node.neighbors, combatGridMap[xx, yy-1]);
        }
        //add bottom neighbor
        if(yy < mapHeight - 1){
        ds_list_add(node.neighbors, combatGridMap[xx, yy+1]);
        }
     } 
  }
        

im wondering if the current.occupant != attacker check is doing it? i had to add that to make the attacking unit not trigger the ability on its own though, as its supposed to require a second unit. the code in the first post is supposed to step through each gridspace around the attacked unit and check if any of them are occupied by a unit that isnt on the same team as it.

#
                occupant = instance_position(x+(TILE_SIZE/2), y+(TILE_SIZE/2),par_actor);
                occupant.gridX = gridX;
                occupant.gridY = gridY;
            }
        }          ```        this is in the battle manager's step event, "initializing" state
surreal ocean
#

have you tried stopping with the debugger and watching the variable in the watch tab, checking to see what they looks like on occasions where it should work but doesnt?

#

ive read the code and there is nothing that pops out to me as obviosuly bad

#

in general what other tools are avilable to eliminate factors? does it happens with other attacks? what kind of other things\features are involved?

pseudo pike
# surreal ocean meaning there are 3 parties involved? or also if there is an ally next to the un...

yeah, theres the attacker, the attacked unit, and another unit that is not on the same team as the attacked unit(not necessarily on the same team as the attacker). it works with ranged attacks perfectly fine, tested all the possible angles. i havent tried to set it up to work with anything other than basic attacks yet. this is pretty minimal, what i posted is everything, aside from the damage calc that just adds +2 damage if the applysneakattack variable is set to true.

#

i havent used the debugger yet

surreal ocean
#
  • press at the left of a code line to insert a breakpoint (marked in a red circle)
  • run the game with F6 (or the debug icon next to the play button)
  • when reaching a line with a breakpoint, the game will pause and enter debug mode, where you can progress line by line while watching the variables. hovering over variables will let you see their current value, and you can also look at variables directly by writing them down in the "watch" tab
#

you could get all that easily with some video

pseudo pike
#

alright ill try that

pseudo pike
# surreal ocean in that case i strongly recommend learning it, there isnt much to learn and it a...

so, stepping through with the debugger using a break point is showing that my current.occupant is correctly being assigned to the other unit (not the attacker and not the attack target). but applySneakAttack is still showing to be false. it is supposed to be getting set to true here. in this test i had unit 2 on the left of the attack target, and the attacker on the bottom of the attack target. Pause event has been registered for this frame
Pause event has been unregistered
hit
ref 100927
apply sneak attack = true
ref 100975
ref 100950
ref 100952
apply sneak attack = false
Pause event has been registered for this frame
Pause event has been unregistered

#

i think i have an idea of whats happening... the else statement on the end may be setting apply sneak attack to false after it was set to true because its still checking the other gridspaces despite being unoccupied

#

it would seem that i put my else {_attacker.applySneakAttack = false;} at the end of the !_attacker check instead of the unit team check. seems to be fixed now. ty for the help