Page 1 of 1

[C/C++ Source issue]Making a chat command...

Posted: February 14th, 2011, 7:55 pm
by Popinman32
I need enough info to create a chat command, because I'm trying to add lua in addition to cubescript.

I'm aiming for something like "/lua {source}".

Don't give me *censored* about how you don't know lua. :P
Lua's source is C, so I know most of the developers can help me out here.

Why lua?
I like it, and I already have it so saved maps get a lua file, and these files are loaded with the map.

If you can't give info on making a chat command, I have a different question:
Is there a way that cubescript can be used in-game with a chat command and if so where is the source of this in-game chat method?

Re: [C/C++ Source issue]Making a chat command...

Posted: February 15th, 2011, 1:17 am
by Hirato
Lua before being compiled is C, so I know most of the developers can help me out here.

Code: Select all

function factorial(n)
  if n == 0 then
    return 1
  else
    return n * factorial(n - 1)
  end
end
Sure looks like C/C++ to me
no doubt about it, definitely C/C++
there's no mistaking that it's C/C++
:roll:

I also found this on wikipedia

Code: Select all

do
  local oldprint = print   -- Store current print function as oldprint
  function print(s)        -- Redefine print function
    if s == "foo" then
      oldprint("bar")
    else 
      oldprint(s) 
    end
  end
end
At any rate you should do something similar. This is pure speculation, but you'll probably want to expose conoutf to lua, and override print with it.
I really don't know a thing about lua (and frankly I really dislike its syntax), so you're by all means on your own.
Is there a way that cubescript can be used in-game and if so where is the source of this in-game method?
Depends on the game, they all do things differently.
For example, the RPG relies on everything being defined on a per game basis (typically somewhere in data/rpg/games/), while the FPS relies on everything being done on a per map basis. Village is a shining example of doing things the FPS way. If you have a copy of sauer handy, you should check out Lost as well.

Re: [C/C++ Source issue]Making a chat command...

Posted: February 15th, 2011, 3:01 pm
by Popinman32
Clarified the post...

CHAT COMMAND for cubescript?

Lua's SOURCE is C/C++

Re: [C/C++ Source issue]Making a chat command...

Posted: February 15th, 2011, 3:55 pm
by arcones
Cube 2 at one point had an implementation of Chat Commands in MP games. They might actually have some of that work on the wiki, but that's doubtful as I couldn't find it when I checked.

Re: [C/C++ Source issue]Making a chat command...

Posted: February 15th, 2011, 8:52 pm
by Hirato
Popinman32 wrote:Clarified the post...

CHAT COMMAND for cubescript?

Lua's SOURCE is C/C++
The built in console does 3 things, in order.
First it acts if "action" is defined, this requires that you explicitly define the input command (ie, team chat).
The second act is invoked when a / is present which causes it to the executed.
Other wise, everything is sent to game::toserver; the FPS game uses this to send chat.

FPS

Code: Select all

void toserver(char *text) { conoutf(CON_CHAT, "<%s>\f0 %s", colorname(player1), text); addmsg(N_TEXT, "rcis", player1, CHAT_TALK, text); }
Everything Else

Code: Select all

void toserver(char *text) {}