1

Topic: [HELP] Creating entities

How can I create custom entities like freeze in DDRace mod?

2

Re: [HELP] Creating entities

what mod you want?
and  you only edit what you want and the mod what respond for your entities

3 (edited by Mo2 2012-05-07 22:50:26)

Re: [HELP] Creating entities

To create new entities or new tiles (DDRace-Freeze is a tile not an entity) you need knowledge about C++

So here a quick - "How to mod TW" tutorial:

If you don't know how to modify source-files and compile them forget it. Creating a mod is way more difficult then creating a new map or a "working" tileset. No need to worry ... it's even fun to create new maps or tilesets, ... smile


If you know how to modify source-files then:

  • Get the source and unzip

  • Modify the file "src/game/mapitems.h" (e.g. add TILE_FREEZE after the "TILE_NOHOOK" tile - or ENTITY_WEAPON_HAMMER after ENTITY_WEAPON_RIFLE)

  • If you add a TILE (not necessary with ENTITY): Num new collision-flag in "src/game/collision.h" - e.g. "COLFLAG_FREEZE=8,"

  • If you add a TILE (not necessary with ENTITY): Add new collision init entry in function "void CCollision::Init(class CLayers *pLayers)" in file "src/game/collision.cpp" (do it like it was done already for the other tiles)

  • Add some new behaviour via modding the at character.cpp or via creating new entities.


For example add something like that for "freeze" behaviour at top of CCharacter::Tick() in file "src/game/server/entities/character.cpp" and trigger it regarding your new COLFLAG_FREEZE (look for COLFLAG_DEATH as an example but put freeze stuff somehwere at top)

        if(m_Freeze)
        {
                m_Input.m_Direction = 0;
                m_Input.m_Jump = 0;
                m_Input.m_Hook = 0;
                SetWeapon(WEAPON_HAMMER);
        }

For sure this does not work fire and forget. Here starts the main modding part. "m_Freeze" of the above example is no common variable of class CCharacter in normal TW so you even need to modify the header of character.h in that example if you would look it that way and so on. If you don't have a clue what to do here you most likely don't speak C++ currently and have to learn that seriously first.

However if you could write C++ and need just a clue or some hints where to start:
Many stuff could be done in the files below src/game/server/entities/ (especially character.cpp). There are lot's of files that could give you some clue how to continue (e.g. projectile.cpp)
The "mod.cpp" file is good for general gameplay changes (e.g. change some end-condition behaviour... but in my opinion there are too less virtual functions to stay in that file only if you even would change behaviour of your tee)
The "character.cpp" is the file where you should be able to change most stuff regarding your "visible tee" (like freezing, jumping, fire weapon, ...)
The "player.cpp" is the file where you could change stuff of your player (even if your tee is not alive you own a player with a name if you are connected - for example that keeps score even if your character is currently dead and waits for respawn and owns a skin with a colour)
Entities could be different stuff. A simple pickup could be added in pickup.cpp... some other stuff like buttons or turrets would need some new entity files that add new behaviour like aiming or whatever.
To change the mod-name take a look into "src/game/server/gamecontext.cpp"
Take a look into "src/game/server/gamecontroller.h" and "src/game/server/gamecontroller.cpp" if you would add some more virtual functions for your mod.cpp and to get a clue for normal gamefunctions (for example what would be set at function StartRound and so on).
If you would add a lot new tiles you need to reserve/exclude some range and/or add a new layer. That means you can't just use 1,2,3,4,5,6,7, 8, 9, 10 for COLFLAG.... (you can use them but for example 6 = 2 + 4, 10 = 2 + 8 ... so even COLFLAG_DEATH (2) would be set at both numbers in character.cpp afterwards and that means if you don't change something to strictly deny that your tee dies there as well). Using following power-of-2 numbers up to 128 should be save without any exclude. Entities don't need that but are handled different. So for example you normally don't check the character if he collided with all the entities but check each entity if some character is near enough to give some powerup or to start aiming and shooting something, ...

  • If you are done changing compile use "bam" (you need some compiler as well e.g. VC or gcc).

  • To be nice you should create a new entities.png for mappers - so they get a clue which new tiles or entities would be used from your mod (if you don't add new layers that would mean add new tile-gfx right to nohook tile and add new entity-gfx right to the laser entity).

Greetings,
Mo(2)

4

Re: [HELP] Creating entities

Thanks! One more question, how to create rainbow? I tried this but it won't work.

 
void CGameContext::Rainbow(class CPlayer *pP)
{
    pP->m_TeeInfos.m_UseCustomColor = 1;
    if(pP->m_TeeInfos.m_ColorBody > 16711424 || pP->m_TeeInfos.m_ColorBody < 65280)
        pP->m_TeeInfos.m_ColorBody = 65280;
    else
    {
        int rainprev = pP->m_TeeInfos.m_ColorBody;
        int rain = rainprev + 65536;
        pP->m_TeeInfos.m_ColorBody = rain;
    }
}

Just switching to 255 color(red).

5

Re: [HELP] Creating entities

Use it :

void CGameContext::Rainbow(class CPlayer *pP)
{
    pP->m_TeeInfos.m_UseCustomColor = 1;
    if(pP->m_TeeInfos.m_ColorBody > 16711424 || pP->m_TeeInfos.m_ColorBody < 65280)
        pP->m_TeeInfos.m_ColorBody = 65280;
    else
        pP->m_TeeInfos.m_ColorBody += 65536;
}

and where do you use this function ?!

6

Re: [HELP] Creating entities

Hi,
I am actually creating a mod and would like to add a pickup entity, i.e an ammo crate,
I changed the content.py to linkf the sprites and generate the variables that should handle the crate
and modified the pickup.cpp. But here is the issue,
I just can't see them in the game, nor in the editor neither in maps..
Has someone ever created a new pickup and handled it, if yes I really need to know what I am missing.
Thanks.

Do not dig up threads like this. Closed. // Dune