X Z
#1
MCServer sometimes gives the wrong X and Z coordinates. Ive noticed this while i was working on my WorldEdit plugin. i was adding a command that changes all the block above you to air blocks but it kept changing the blocks next to me. This was the code i used:
function HandleRemoveAboveCommand( Split, Player )
	X = Player:GetPosX()
	y = Player:GetPosY()
	Z = Player:GetPosZ()
	World = Player:GetWorld()
	RemoveAboveBlocks[Player:GetName()] = 0
	for Y = y, World:GetHeight( X, Z ) do
		World:SetBlock( X, Y, Z, 0, 0 )
		RemoveAboveBlocks[Player:GetName()] = RemoveAboveBlocks[Player:GetName()] + 1
	end
	Player:SendMessage( cChatColor.LightPurple .. RemoveAboveBlocks[Player:GetName()] .. " block(s) have been removed." )
	return true
end
Reply
Thanks given by:
#2
Also, ForEachEntity don't work, please fix it.
Reply
Thanks given by:
#3
I don't think it's wrong coords, but rather it's because of rounding. The player position is a floating point value; cWorld:GetHeight() and cWorld:SetBlock() both expect an integral coord, so the Lua glue code must convert it somehow; and I'm pretty sure it's using the wrong kind of conversion.

Also, to make your code more efficient, don't do
RemoveAboveBlocks[Player:GetName()] = RemoveAboveBlocks[Player:GetName()] + 1
but instead do the calculation on a local variable and then assign the final value to RemoveAboveBlocks[Player:GetName()].
Not to mention that you could assign a value directly, because you know how many blocks will be replaced (GetHeight() - y). And why are you even storing the value in a per-player map, if you keep resetting the value with every replacement, anyway?

(05-19-2013, 09:08 PM)tonibm19 Wrote: Also, ForEachEntity don't work, please fix it.

Please don't derail by posting off-topic stuff. We know it's broken, it's in the bug tracker, and when we've got the time, we'll fix it. There are more pressing issues now, such as the pickups not working etc.
Reply
Thanks given by:
#4
I Added math.floor( ) and it is working now Wink thanks
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)