Jump to content

Photo

npc->CanPlace() Bug.


  • Please log in to reply
2 replies to this topic

#1 MObreck

MObreck

    Newbie

  • Members

Posted 04 March 2026 - 05:46 AM

While trying to make a custom Zora type monster I noticed that CanPlace() always returns invalid if you try check the combos in either the right or bottom corners of the screen. The custom Zoras worked as intended aside from utterly refusing to emerge from either of those corners.

 

For now setting the Can Walk Through Screen Edge flag seems to bypass the issue, but that is just a work around.

 

For reference here is a simplified version of the script I'm using to teleport the Zora's around. It functions through an Until check:
 

bool TeleportCheck(npc n, int TerrianFlag = SPW_NONE)
{
	//Find a valid spot to place an enemy.
	n->X = (Rand(16) * 16);
	n->Y = (Rand(11) * 16);
	return n->CanPlace(n->X, n->Y, TerrianFlag, false, -1, -1);
}

Unless the Can Walk Though Edge flag is set any result of 15 for X or 10 for Y comes back false even if it is a tile the Zora should be allowed appear on. The left and top corners work fine even without the flag set. The custom Zoras are the normal 16x16 pixel size.

 

I'm using version 255.12


Edited by MObreck, 04 March 2026 - 06:16 AM.


#2 coolgamer012345

coolgamer012345

    🔸

  • Members
  • Location:Indiana, USA

Posted 04 March 2026 - 06:54 PM

I think this is an off-by-1 scenario. The top/left of the screen is going to start at (0, 0). Try doing Rand(15) and Rand(10) and see if you get the same issue.

 

I checked the ZScript docs. Unless the functionality of this changed between versions, it looks like Rand(16) can go up to and including 16, so 16 * 16 = 256 (and similar for y), outside the bounds of the screen.

int Rand(int bound) 

Returns a random number 0 to bound, inclusive.

https://docs.zquestc...dgen-fun-rand-2



#3 Moosh

Moosh

    The Mush

  • Moderators

Posted 04 March 2026 - 09:12 PM

https://discord.com/...937214879793323
Made a dev forum report for this as well. The issue seems to get more severe as the size of the enemy's hitbox increases.


  • Emily likes this


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users