Welcome to AC Web.

View Poll Results: Should this tutorial be sticky?

Voters
154. You may not vote on this poll
  • Yes

    131 85.06%
  • No

    23 14.94%
Page 1 of 7 123 ... LastLast
Results 1 to 15 of 103
  1. #1

    [Trinity] How to add a c++ script to your core.


    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.

    Hello all,

    this is a tutorial on how to add a custom C++ script to your Trinity core.

    I know there are more of these only some are not very clear.

    lets start:


    How to add a C++ script to your server?:


    1. You NEED a self-compiled server, so NOT a repack.

    2. Open up your Trinitycore solution in Microsoft Visual Studio , hit Ctrl+N then a screen will pop-up, click on Visual C++ and click on C++ file.cpp

    3. paste the whole code in the new text box and save it as your desired name.cpp and place it in your C:/Trinity/src/server/scripts/Custom folder.

    4. open up C:/Trinity/src/server/scripts/Custom/Cmakelists.txt

    5. you will see some copyright text, scroll down till you find this:
    Code:
    set(scripts_STAT_SRCS
      ${scripts_STAT_SRCS}
    )
    add a new line, that looks like this : Custom/yourscriptname.cpp
    so example:
    Code:
    set(scripts_STAT_SRCS
      ${scripts_STAT_SRCS}
    Custom/mynewscript.cpp
    )
    then save that

    6. Go to your build folder Default C:/Build.

    7. Open the TrinityCore.sln file with the type: Microsoft Visual Studio Solution

    8. on the left of the screen you should have a solution explorer, if not then hit CTRL+ Alt + L

    9. open up the project "game" in your solution explorer by clicking on the arrow left to the "game" project.

    10. click on the arrow that says "Source files" and scroll down until you see Scriptloader.cpp

    11. open the file Scriptloader.cpp, scroll all the way down until you see this:
    Code:
    #ifdef SCRIPTS
    /* This is where custom scripts' loading functions should be declared. */
    #endif
    
    void AddCustomScripts()
    {
    #ifdef SCRIPTS
        /* This is where custom scripts should be added. */
    #endif
    }
    12. Find the code of your script and scroll all the way down until you see something like this:
    Code:
    void AddSC_Example()
    {
    	new Example;
    }
    I used example but at your code there can be other text ofcourse.

    13. Copy the void AddSC_Example() then go back to your Scriploader.cpp file and paste that, so that it will look like this :
    Code:
    #ifdef SCRIPTS
    /* This is where custom scripts' loading functions should be declared. */
    void AddSC_Example();
    #endif
    
    void AddCustomScripts()
    {
    #ifdef SCRIPTS
        /* This is where custom scripts should be added. */
    AddSC_Example();
    #endif
    }
    Remember to add the ; at the end to both and remove the void at the second.

    14. Go back to your Solution Explorer and search the project "scripts", then click on the arrow left from the project.

    15. Right-click on the Source files folder and click on Add->Existing Item.

    16. You will see a window popping up that will ask where your .cpp file is, we already saved it in a folder so lets go and open that folder.
    Go to C:/Trinity/src/server/scripts/Custom and double-click on your .cpp file to add it.

    17. Recompile and your done, Congratulations!


    How to recompile?

    A lot of people don't know what the word "recompiling" means in when starting, the meaning of this word is just the re-making (building) of your server, how to do this?
    1. on the top of your screen you will see a green triangle and a dropdown- menu on the side of it.
    2. Make sure that the dropdown-menu is set to Release and set to the right Bit version, according to your Computer (32/64 bit)
    3. Click on the green triangle, a box will pop-up asking you to build some projects, click on "yes" and the recompiling will start, Congratulations!


    This part is only for adding a script to an areatrigger/creature/gameobject/instance/item, if your script is not about any of these categories then you are done.

    If you want to add a areatrigger/creature/gameobject/instance/item
    then you have to do one more thing, I will show you in a few steps.


    1. Open up your Database and open up the catergory table of what you want to add like : creature_template for creatures.

    2. Make or edit an existing areatrigger/creature/gameobject/instance/item

    3. Go to the column named "ScriptName".

    4. Go to your script, and search something like this ( used Faded's teleporter (a creature)) :
    Code:
    class tc_teleporter : public CreatureScript
    {
    	public:
    		tc_teleporter()
    			: CreatureScript("tc_teleporter")
    			{}
    5. When you have that then you will need
    Code:
    : CreatureScript("tc_teleporter")
    6. Go back to your Database and Write in ScriptName, the part i wrote in red:

    Code:
    : CreatureScript("tc_teleporter")
    7. You are done now, you may need to restart your server or reload your areatrigger/creature/gameobject/instance/item.

    Note: I took Faded's teleporter script so that why its : tc_teleporter, ofcourse there can be something else in your script.
    Last edited by Jameyboor; 09-07-2013 at 01:20 PM.

  2. #2
    weird like that

    Join Date
    Feb 2010
    Location
    http://rochet2.github.io/
    Posts
    5,289
    The cmake text stuff doesnt need to be done in your guide in reality.
    It does add it to the core if you use cmake later with the same source though.

    So if you edit the cmake file you can use cmake again and skip the add an existing item part.
    If you use add an existing item, you dont /need/ to do the cmake text file edit.

    Anyways, guide seems to work on a quick look.

  3. #3
    Can you upload a self compiled server for me? Ive been struggling with making trinity repacks (and arc) for 4 months withour results.
    PM me if you can <3

  4. #4
    /bumpty

  5. #5


    Join Date
    Jul 2010
    Location
    Bulgaria/Sofia
    Posts
    188
    ohhh nice Thread !!!

  6. #6
    Quote Originally Posted by lasoto View Post
    ohhh nice Thread !!!
    Thanks

  7. #7
    This is absolutely necessary for those beginning to custom script =) good post.

  8. #8
    Quote Originally Posted by wazy View Post
    This is absolutely necessary for those beginning to custom script =) good post.
    Thank you .

    buump

  9. #9
    Thank you for this really helped me out!

  10. #10
    Quote Originally Posted by H4ckz0r View Post
    Thank you for this really helped me out!
    No problem, Thanks

  11. #11


    Join Date
    Jun 2010
    Location
    Omnipresent
    Posts
    210
    There is one more thing you didn't add to your tutorial,it's kinda important,SOME scripts won't work without it.

    item scripts,creature scripts,gameobject scripts,areatrigger scripts,instance scripts are bound to one item,creature,gameobject,area,instance.

    So,trinity core needs to know which item,creature,blah blah.
    You do it in database.

    So,if it's a creature,you add your script name to field ScriptName in 'creature_template' table,if it's item script,add script name to ScriptName in 'item_template' etc.

    also,here are same tutorials:

    Seejay's

    Jeutie's

    on Trinity wiki

    not sure if another was needed,lol.
    Last edited by Vozho; 06-07-2012 at 03:14 PM.

  12. #12
    Quote Originally Posted by Vozho View Post
    There is one more thing you didn't add to your tutorial,it's kinda important,SOME scripts won't work without it.

    item scripts,creature scripts,gameobject scripts,areatrigger scripts,instance scripts are bound to one item,creature,gameobject,area,instance.

    So,trinity core needs to know which item,creature,blah blah.
    You do it in database.

    So,if it's a creature,you add your script name to field ScriptName in 'creature_template' table,if it's item script,add script name to ScriptName in 'item_template' etc.

    also,here are same tutorials:

    Seejay's

    Jeutie's

    on Trinity wiki

    not sure if another was needed,lol.
    I know there are more of these only some are not very clear.
    .

  13. #13


    Join Date
    Jun 2010
    Location
    Omnipresent
    Posts
    210
    I see you added,interesting

  14. #14
    Bump

  15. #15

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Before I add more scripts I wanted to see if this error meant that the script wouldn't work..
    Code:
    game.lib(ScriptLoader.obj) : error LNK2019: unresolved external symbol "void __cdecl AddSC_Example(void)" (?AddSC_Example@@YAXXZ) referenced in function "void __cdecl AddCustomScripts(void)" (?AddCustomScripts@@YAXXZ)
    Its for that boss announce script.


    Also when I did a recompile my worldserver.exe was deleted?
    Last edited by H4ckz0r; 06-12-2012 at 02:05 PM.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •