1 (edited by Cartman34 2010-09-13 20:19:50)

Topic: [TUTORIAL] Personalize your MOD (By Cartman34)

Hi,

I'll present you some things you have to know to modify your MOD but first you have to know you should not edit official MODs (CTF, DM & TDM) because it's illegal and clients will reject your server.
That's why I created my MOD "NSCTF" (Non Standard CTF) but I'll post it later, I need to check Copyrights...

This tutorial require knowledges in C/C++.

I'll name the MOD's displayed name "MODDN", the MOD's config name "MODCN" and the MOD's hidden name "MODHN" for my examples (Uppercase or lowercase names).


* Create your own MOD

MODs source files are in the directory /src/game/server/gamemodes/ .
Each MOD require the modhn.hpp and modhn.cpp files, you can copy it from another MOD, I think files name are understandable.
Then modify the file "/src/game/server/hooks.cpp":
- After others similar lines, add:

#include "gamemodes/modhn.hpp"

- In function mods_init(), after other similar lines but before the line starting with else, add lines

        else if(strcmp(config.sv_gametype, "modcn") == 0)
        game.controller = new GAMECONTROLLER_MODHN;

* [CTF]Change the flag capture range

Your MOD have to be a MOD derived from CTF.

This part explain to you how to change the flag capture range.

In your modhn.cpp file, in GAMECONTROLLER_MODHN::tick() method , there is the line:

if(distance(f->pos, flags[fi^1]->pos) < 32)

Change 32 by you own distance in pixel, 32px seems to be the tile size.
My change: 352.


* [CTF]Change the flag catch/return range

Your MOD have to be a MOD derived from CTF.

This part explain to you how to change the flag catch/return range.

In your modhn.cpp file, in GAMECONTROLLER_MODHN::tick() method , there is the line:

int num = game.world.find_entities(f->pos, 32.0f, (ENTITY**)close_characters, MAX_CLIENTS, NETOBJTYPE_CHARACTER);

Change 32.0f by you own distance in pixel (float), 32.0f seems to be the tile size.
My change: 96.0f.


* [CTF][FIX]Collision and the flag capture range

Your MOD have to be a MOD derived from CTF.

With my previous change about the flag capture range make some maps bugging.
This part explain to you how to fix it considering flag capture will be impossible through walls.

In your modhn.cpp file, in GAMECONTROLLER_MODHN::tick() method , there is the line:

if(distance(f->pos, flags[fi^1]->pos) < 32)

Where 32 could be another number according to your previous changes.
Change to:

if( distance(f->pos, flags[fi^1]->pos) < 32 && !col_intersect_line(f->pos, flags[fi^1]->pos, NULL, NULL) )

Don't forget to change again the number 32 according to your previous changes.


* Add the "Killing Spree" system to your MOD

- In your modhn.hpp file, in GAMECONTROLLER_MODHN definition , add to the public part:

unsigned int killingsprees[MAX_CLIENTS];

- In your modhn.cpp file, at the end of GAMECONTROLLER_NSCTF::GAMECONTROLLER_NSCTF(), add:

    for( int i=0; i<MAX_CLIENTS; i++) {
        killingsprees[i] = 0; //Initializing killing sprees array.
    }

- In the same file, after:

int GAMECONTROLLER_NSCTF::on_character_death(class CHARACTER *victim, class PLAYER *killer, int weaponid)
{
    GAMECONTROLLER::on_character_death(victim, killer, weaponid);

Add:

    char buf[512];
    if( killer != victim->player ) {
        if( killingsprees[victim->player->client_id] >= 5 ) { //Victim was on a killing spree
            int vksnb = 5;//5 is the minimum.
            if( killingsprees[victim->player->client_id] >= 10 ) { //Begin the score steps with the maximum (10 here, but you can add other scores).
                vksnb = 10;
            }
            str_format(buf, sizeof(buf), "%s %d-kills killing spree was ended by %s.", server_clientname(victim->player->client_id), vksnb, server_clientname(killer->client_id));
            dbg_msg("game", buf);
            game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
            killer->score += (vksnb -(vksnb/5) -1);
        }
        killingsprees[killer->client_id] = killingsprees[killer->client_id]+1;
        if( killingsprees[killer->client_id] >= 5 ) { //killer is on a killing spree
            int kksnb = 0;//0 for not entering on a killing spree.
            if( killingsprees[killer->client_id] == 5 ) {
                kksnb = 5;
            } else if( killingsprees[killer->client_id] == 10 ) {
                kksnb = 10;
            }
            if( kksnb ) {
                str_format(buf, sizeof(buf), "%s is on a killing spree with %d kills.", server_clientname(killer->client_id), kksnb );
                dbg_msg("game", buf);
                game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
                killer->score += kksnb;
            }
        }
    }
    killingsprees[victim->player->client_id] = 0;

This is not the best way to implement killing sprees ont your server, it is the best way to implement it in your MOD.
Associate killing spree with the PLAYER would be better but here, it's not our business.


Ask me for questions/informations and report me for problems please.

You can join my home server on appart.cartman34.fr (instead of the usual IP address).

2 (edited by Dune 2010-09-10 19:12:17)

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Oh my gosh not again that kind "tutorial" that don't teach you anything saved by where to changes 3/4 values to make crazy mods...
Indeed, before to start to look in the Teeworlds code, learn C++. I know it's hard, I'm sorry for that, but that's the only way to make GOOD mods.
You always can manage to learn it when you're motivated enough ; and if you're not, do something else, dunno mapping for example.

Oh, and cartman, think to what your "tutorial" will afford to the Teeworlds community. Just mods from people that just change one value and say "hurray I made a mod".

Not Luck, Just Magic.

3

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

My topic is named "Personalize tour MOD" and I never said I'll show you how to make a complete MOD, just how to personalize an existant MOD.
I just want to afford some knowledges that nobody has never explained and to simplify the understood of the game server. Because with these some values, I understood all the CTF source and this is a way to create a MOD without to change the server source.
Apologize me if I does not agree with stupids MODs that does not improve original game.

4 (edited by CarmineZ 2010-09-11 14:21:46)

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

of the source code version 0.5.2
i already made a beta mod, but now i don't release it in official forum, i share it when i'll finish it; and i need help for this question:
i need to access in flag propriety from hook.cpp or from otherwhere, but i no able to point to flag.. i try game.controller->flags but is an error when compiling, someone know how access in the flags? (i no want access from ctf.cpp, i know how in ctf.cpp)

5 (edited by Cartman34 2010-09-11 20:27:05)

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

I advise you to use flags only in your MOD.

6

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Cartman34 wrote:

My topic is named "Personalize tour MOD" and I never said I'll show you how to make a complete MOD, just how to personalize an existant MOD.
I just want to afford some knowledges that nobody has never explained and to simplify the understood of the game server. Because with these some values, I understood all the CTF source and this is a way to create a MOD without to change the server source.
Apologize me if I does not agree with stupids MODs that does not improve original game.

If people already did a mod, they can easily do what you described.
Your "tutorial" is useless except for creating new 2-minutes mods for people that don't know anything to C++.

You're not "affording any knowledge", you're just saying in a bad english which line to go to change which value for very little modifications - and those modifications aren't anything original - it's not like if you provided patches for interesting features - just very basic ones, not improving in any way the gameplay.

Not Luck, Just Magic.

7

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Yeah, in bad english, I know but I could not help people in French ...
I thought people will never reject any help.

8 (edited by Lanta 2010-09-13 20:46:22)

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Oh oh, a flame war. Never seen one in this forum since months big_smile

http://4.bp.blogspot.com/_6jCh-5qXO6s/Ry0W3R77W6I/AAAAAAAAAX4/yOUweKgb7ho/s320/flamewar.jpg

Well, let's try to keep on topic. I'm here to bring you peace and love, because I decided you are flaming without a reason: simply this topic is useless and dangerous.
Useless, because we already had some simple tips about "how to build a mod" in other threads and they were all epic fails. This one won't be different. This forum is not a C developer support board, and we can't teach you how to code. You MUST learn the programming language, and you can't do it here. RTFM (read the fuckin manual), and if you don't have one follow online guides like this http://www.cplusplus.com/doc/tutorial/
Dangerous because you are teaching noobs to code a mod without knowing a language programming, and that could be the beginning of a new era of shitty mods with a few lines of changed code. Play vanilla, mods are not interesting...

Keep it simple, stupid!

Support Staff - ESL.eu Teeworlds Admin

9

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

http://stressreductioninstitute.files.wordpress.com/2009/03/calm-down-intro.jpg?w=300&amp;h=225
Oh oh, a moderator. Never seen one in this forum since some months big_smile
Thanks for making things clear Lanta, that was needed smile

Not Luck, Just Magic.

10 (edited by Lanta 2010-09-13 20:58:05)

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Dune wrote:

Oh oh, a moderator. Never seen one in this forum since some months big_smile

If I were a moderator this thread probably would have disappeared. But I'm not... sigh :'(
Btw moderators are always working and watching you, just from the backstage. tongue

Support Staff - ESL.eu Teeworlds Admin

11

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

i didn't know that messages go in spoiler by voting...  i believed that a moderator make it closed in spoiler

Dune Lanta and heinrich5991: yours messages are just OFF topic (and spam/flame), we don't need lesson from you, we are free to talk about everything, you only say: don't do this, don't do that, don't do theese.. nothing to learn from you!

12

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Well...there are more arguments of Lanta and Dune against this thread.
Maybe you, CarmineZ, should write something useful and stop crying.

Btw: Cartman, take a look at the source of 0.5 trunk and update your post, as its written for 0.5.

13

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

lanta and heinrich are innocent!

14

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

i don't cry, i think that the real useless messages are yours ->(Dune lanta alias Slayer heinrich), because everybody know what should learn to edit (mod) teeworlds, no need yours obvious suggestion!!!

15

Re: [TUTORIAL] Personalize your MOD (By Cartman34)

Too much offtopic. Stop whining so much, if you don't like a thread, don't read it and don't reply.