1

Topic: Edit TW Source Code

hello
i want to start editing teeworlds source code,for example make a new MOD
but i don't know any thing about functions,classes,... and their actions in tw.

may i ask you explain a little about source code or show me simple example.

for example how can i make it ...
when i enter this command "cl_test" in console(Client) , a text("hello world") appear in screen, like "say" command

tnx

2

Re: Edit TW Source Code

Hold on, I thought I wrote a generic post about this.

Edit: finally found it, here it is:

Dune wrote:

You cannot code anything good (i.e not just tuning such as infinite grenade ammo) for Teeworlds unless you're investing yourself in learning C++ and programming in general.


This kind of topic can be good (great!) to help people to begin with the Teeworlds code if they already have a decent experience with programming. Looking into Teeworlds code can be a great way to get motivated to learn programming, but no topic of this kind can ever learn you half of what you need to know.



Programming is great, it can be relaxing, exciting. I'm not trying to demotivate you from learning it. It's great, imo. But it takes time - a lot of time - you have to be motivated to get into it and do not expect to be able to code into Teeworlds after a few 10hours.

TLDR: You need to learn the basics of programming before looking into the Teeworlds code.

Not Luck, Just Magic.

3

Re: Edit TW Source Code

i'm a c++ programmer , and i know c++ very well,but i want a simple example to start editing
i have a question
for editing source code will c++ suffice or other languages such as LUA or python are required??

4

Re: Edit TW Source Code

glancedx wrote:

i'm a c++ programmer , and i know c++ very well,but i want a simple example to start editing
i have a question
for editing source code will c++ suffice or other languages such as LUA or python are required??

Just C++ is enough.

For what you were asking, look into variables.hpp (src/game), you'll find all the variables you need. Use Ctrl+F to look for

g_Config.m_GfxHighDetail

in the code if your variable name is GfxHighDetail.

These variables are accessible anywhere in the code at the condition you

#include <engine/shared/config.h

in the concerned file.

Not Luck, Just Magic.

5 (edited by glancedx 2013-01-15 14:47:13)

Re: Edit TW Source Code

i found "GfxHighDetail" in this file "config_variables.h" !!

may i ask you explain about "g_Config.m_" ?? because i cant find it in the source!

i want know that when i declare a variable(command) in "variables.h"
where can i define functions for declared variable!

(sry for bad english)

6

Re: Edit TW Source Code

glancedx wrote:

i found "GfxHighDetail" in this file "config_variables.h" !!

may i ask you explain about "g_Config.m_" ?? because i cant find it in the source!

i want know that when i declare a variable(command) in "variables.h"
where can i define functions for declared variable!

(sry for bad english)

Oh, my bad it's

gConfig.m_

Also, just copy the existing patterns in variables.hpp to declare a new global variable :)

Not Luck, Just Magic.

7 (edited by glancedx 2013-01-15 16:59:19)

Re: Edit TW Source Code

i copied this line

MACRO_CONFIG_INT(ClShowhud, cl_showhud, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame HUD")

and changed it to

MACRO_CONFIG_INT(ClTest, cl_test, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show Text in Game")

now i want to create code for cl_test that when i enter "cl_test 1" in Console(Client), it shows "text1" in chat and when i enter "cl_test 0" it shows "text2" in chat.

how can i do that?!
or where should i define a code which does the above tasks??

8

Re: Edit TW Source Code

Well these are variables, parameters, configs, settings, whatever you want to call them. They are appropriate for changing state of things - such as text size, name, skin, level of detail, resolution...

They're not appropriate for actions. If you want to code a "test" action, you would rather look up in gameclient.cpp (src/game/client), for these:
http://puu.sh/1O4Kr

First thing I would advise you is to use the console for printing tests instead of the chat. If you want to print something in chat you'll have to do that in the src/game/client/component/chat.cpp module.

Not Luck, Just Magic.

9

Re: Edit TW Source Code

i could add test command to client (it was very simple)
but still it cant do any thing!

i find out, every function that belongs to "Console()->Register"  has this signature

static void ConXXX(IConsole::IResult *pResult, void *pUserData);

i need some information about parameters.

IConsole::IResult *pResult

and

void *pUserData

10

Re: Edit TW Source Code

Ctrl+F is your best friend when hacking in Teeworlds. Look for such a ConXXX function and see how it uses its parameters. I found this:

http://puu.sh/1OaQn

Not Luck, Just Magic.

11

Re: Edit TW Source Code

hi
is it possible to find Distance from the nearest tee?!

12

Re: Edit TW Source Code

What do you want to code?

Not Luck, Just Magic.

13

Re: Edit TW Source Code

Pretty sure there is no already made function to find that but you could easily write your own. Just loop through all the characters, get their position relative to the tee you are comparing against, and then use pythagorean's theorem to calculate the distance between them. Keep a variable for the smallest distance and check each new distance against the smallest distance and update the smallest distance accordingly.

14 (edited by 2013-01-17 01:50:01)

Re: Edit TW Source Code

how can i do  loop through all the characters?!

Dune wrote:

What do you want to code?

i want make a new class for hooking..!

15

Re: Edit TW Source Code

glancedx wrote:

i want make a new class for hooking..!

What? Explain further, I don't get it.

Not Luck, Just Magic.

16

Re: Edit TW Source Code

He probably wants to make a so called 'hookbot' that always hooks the nearest player which is very annoying. Also, if you really know C++ as you say, try to read the code, it explains itself if you go deep enough. At start it's a bit difficult, but that's the same for all projects you join.