Incorrect string from AMX
#1

For example, I call GetPlayerName.

Sometimes i got incorrect name (for example, dLASH48 instead of FLASH4 or... part of some chat message.

What's the problem?

Code:
	cell amxArgs[4];	
	cell *nameCellAddr;

	amxArgs[0] = 3 * sizeof(cell);
	amxArgs[1] = player;
	amx_Allot(AMX, MaxPlayerNameLength, amxArgs + 2, &nameCellAddr);
	amxArgs[3] = MaxPlayerNameLength;

	InvokeAMX(Native::GetPlayerName, amxArgs);

	char* name = new char[MaxPlayerNameLength];

	amx_GetString(name, nameCellAddr, 0, MaxPlayerNameLength);
	amx_Release(AMX, amxArgs[2]);

	return name;
InvokeAMX is defined and works fine...
Reply
#2

A sidenote, always make sure to deallocate memory you allocate.

new -> delete
new[] -> delete[]
malloc() -> free()
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)