3

I have the following code to send a block of text to a users' game console (Crysis Wars):

        CMCCPlayer(player, "================================================================================================================");
        CMCCPlayer(player, "$4####     ###      ###     ######     ####");
        CMCCPlayer(player, "$4##        ###    ###     ##    ##      ##");
        CMCCPlayer(player, "$4##         ### ###       ##            ##");
        CMCCPlayer(player, "$4## ###      #####         ######   ### ##");
        CMCCPlayer(player, "$4##         ### ###             ##      ##");
        CMCCPlayer(player, "$4##        ###   ###     ##     ##      ## ");
        CMCCPlayer(player, "$4####     ###     ###     ######      ####");
        CMCCPlayer(player, "================================================================================================================");

But I get this result:

Wrong Text

This problem has practically plagued the Crysis Wars developer community, and there have been no real solutions to this. The code formats fine if I do it straight from C++ as opposed to Lua to C++,, so this must be a problem Lua-side.

I have tried timing the messages to 1ms apart, and this resulted in some messages going missing (probably because recent messages override the old ones). Do you guys have any suggestions or solutions to this issue? If you provide a working solution, you'll be pretty famous within the Crysis Wars developer community as you would have solved a pretty annoying bug :). I would offer some of my reputation but unfortunately I awarded the bounty this morning to someone for solving another issue.

Function code for sending the messages:

function CMCCPlayer(player, msg)
    g_gameRules.game:SendConsoleMessage(player.id, g_gameRules.game:CentreTextForConsole(msg)); 
end

If this helps for anything, here's the C++ SendConsoleMessage code:

int CScriptBind_GameRules::SendConsoleMessage(IFunctionHandler *pH, ScriptHandle playerId, const char *msg)
{
CGameRules *pGameRules=GetGameRules(pH);
if (!pGameRules)
    return pH->EndFunction();

int channelId=pGameRules->GetChannelId((EntityId)playerId.n);
pGameRules->SendTextMessage(eTextMessageConsole, msg, eRMI_ToClientChannel, channelId);
msg=0; //Null the message.
return pH->EndFunction();
}

Edit:

Please note that this isn't to do with the text used to center and that the image and text block below is only provided as an example; this issue occurs on every piece of code that is sent.

enter image description here

Msg1

4

2 回答 2

2

所以你说这些函数的序列总是导致输出与函数顺序完全相反。所以......只需以相反的顺序发送数据。因此,这将使反转加倍并按预期顺序提交数据。

有很多方法可以做到这一点。你可以创建一个简单的 Lua 函数,它接受一个字符串数组并以相反的顺序广播它们:

function BroadcastToPlayer(player, strings)
  for i = #strings, 1, -1 do
    CMCCPlayer(player, strings[i]);
  end 
end

您可以扩充它以将字符串作为数组或可变参数系列字符串,就地构建数组:

function BroadcastToPlayer(player, ...)
  local test = ...
  if(type(test) == "string") then return BroadcastToPlayer(player, {...}) end

  for i = #strings, 1, -1 do
    CMCCPlayer(player, strings[i]);
  end 
end

你甚至可以创建一个简单的 Lua 对象,给定要发送的字符串,然后调用它来发送所有存储的字符串。

function CreateStringMan()
    local man = {}
    function man:add(str)
        self._strings = self._strings or {}
        self._strings[#self._strings + 1] = str
    end
    function man:CMCCPlayer(player)
        for i = #self._strings, 1, -1 do
            CMCCPlayer(player, self._strings[i]);
        end
        self._strings = {} --clear the strings
    end
    return man
end
于 2013-07-21T09:03:01.890 回答
1

该输出与您的输入相反。如果您仔细查看输入内容,您会注意到倒数第二行内容比其他行长一个字符。这将导致它以不同的方式在屏幕上居中。尝试删除多余的空间并查看是否可以解决问题。

于 2013-07-15T23:36:05.053 回答