[Arcemu][C++] Help adding New (custom) CPP file to core? menu

Shout-Out

User Tag List

Results 1 to 13 of 13
  1. #1
    Pretzal's Avatar Member
    Reputation
    8
    Join Date
    Aug 2008
    Posts
    57
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Arcemu][C++] Help adding New (custom) CPP file to core?

    Okay i'm a little lost.

    My goal:
    1) Link a new cpp file to arcemu source
    2) Have that file so that I can (for now) do simple hooks/effects (Eg OnEnterWorld SetFFAPvPFlag)

    So far I think im doing it right - To Extrascripts\Main Resources Ive added
    Code:
    SetupMyCustomScript(mgr);
    to setup.cpp and
    Code:
    void SetupMyCustomScript(ScriptMgr* mgr);
    to setup.h (Right under the SetupNeutralGuards part of each script)

    then I added MyCustomScript.cpp to the Extrascripts\Scripts folder in the project.

    Now i start to run into errors. Im still very new to c++, so what do i do from here, what do i put into the MyCustomScript.cpp file? If i just do
    Code:
    OnEnterWorld()
    {
    SetFFAPvPFlag();
    }
    I get a bunch of errors. But, i know im missing on selecting the namespace or something of that effect. So really, I need a bit of a template or something. If it is really really hard then screwit i wont bother til ive learned some more about it (Still get rep for tellin me that tho ^^) So if you feel like givin me a hand, thanks Hopefully it isnt too complicated...

    [Arcemu][C++] Help adding New (custom) CPP file to core?
  2. #2
    blackhex666's Avatar Corporal
    Reputation
    5
    Join Date
    Feb 2010
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Last edited by blackhex666; 03-16-2010 at 02:36 AM.

  3. #3
    Dynashock's Avatar Contributor

    Reputation
    176
    Join Date
    Nov 2007
    Posts
    203
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MyCustomScript.cpp should look something like this:
    Code:
    void OnEnterWorld(Player * pPlayer)
    {
       pPlayer->SetFFAPvPFlag();
    }
    
    void SetupMyCustomScript(ScriptMgr * mgr)
    {
        mgr->register_hook(SERVER_HOOK_EVENT_ON_ENTER_WORLD, (void*)&OnEnterWorld);
    }
    Hope that helped.
    Ignorance is bliss.

  4. #4
    Pretzal's Avatar Member
    Reputation
    8
    Join Date
    Aug 2008
    Posts
    57
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep those were pretty much tellng me what I already had found out blackhex. Dynashock is more ontrack of what im asking for, but on compiling it i get

    9>.\MyCustomScript.cpp(1) : error C2065: 'Player' : undeclared identifier
    9>.\MyCustomScript.cpp(1) : error C2065: 'pPlayer' : undeclared identifier
    9>.\MyCustomScript.cpp(2) : error C2448: 'OnEnterWorld' : function-style initializer appears to be a function definition
    9>.\MyCustomScript.cpp(6) : error C2065: 'ScriptMgr' : undeclared identifier
    9>.\MyCustomScript.cpp(6) : error C2065: 'mgr' : undeclared identifier
    9>.\MyCustomScript.cpp(7) : error C2448: 'SetupMyCustomScript' : function-style initializer appears to be a function definition
    Hmm.

    Im gonna have a look at a few other extra scripts and see what I find. +rep anyways, i think im a bit closer

  5. #5
    mager1794's Avatar Member
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in your script you must include your header files

    put this at the very top of your script
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    Lunar Gaming - Reaching For The Stars

  6. #6
    Pretzal's Avatar Member
    Reputation
    8
    Join Date
    Aug 2008
    Posts
    57
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay now I have -
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
        void OnEnterWorld(Player * pPlayer)
            {
            pPlayer->SetFFAPvPFlag();
            }
    
    
    void SetupMyCustomScript(ScriptMgr * mgr)
    {
        mgr->register_hook(SERVER_HOOK_EVENT_ON_ENTER_WORLD, OnEnterWorld);
    }
    and it gives me this error:


    Code:
    1>Compiling...
    1>MyCustomScript.cpp
    1>Linking...
    1>   Creating library ..\..\..\bin\release\script_bin/ExtraScripts.lib and object ..\..\..\bin\release\script_bin/ExtraScripts.exp
    1>Setup.obj : error LNK2019: unresolved external symbol "void __cdecl MyCustomScript(class ScriptMgr *)" (?MyCustomScript@@YAXPAVScriptMgr@@@Z) referenced in function __exp_script_register
    1>../../../bin/release/script_bin/ExtraScripts.dll : fatal error LNK1120: 1 unresolved externals
    And if I change it to

    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    class SCRIPT_DECL MyCustomScript : public GossipScript
        {
        public:
        void OnEnterWorld(Player * pPlayer)
            {
            pPlayer->SetFFAPvPFlag();
            }
    
        };
    void SetupMyCustomScript(ScriptMgr * mgr)
    {
        mgr->register_hook(SERVER_HOOK_EVENT_ON_ENTER_WORLD, OnEnterWorld);
    }
    I get ...

    Code:
    1>Compiling...
    1>MyCustomScript.cpp
    1>..\src\ExtraScripts\MyCustomScript.cpp(15) : error C2065: 'OnEnterWorld' : undeclared identifier
    Looking at the other scripts i think I need the
    Code:
    class SCRIPT_DECL MyCustomScript : public GossipScript
    part but, it shouldnt be a GossipScript right? It should be a different class or w/e? but what? Gettiing closer ^_^ I think...

  7. #7
    mager1794's Avatar Member
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did you set it up in setup.h and setup.cpp?
    Lunar Gaming - Reaching For The Stars

  8. #8
    Pretzal's Avatar Member
    Reputation
    8
    Join Date
    Aug 2008
    Posts
    57
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think so - this is my setup.h
    Code:
    #include <string>
    #ifndef EXTRA_SCRIPTS_SETUP_H
    #define EXTRA_SCRIPTS_SETUP_H
    
    void SetupNeutralGuards(ScriptMgr* mgr);
    void MyCustomScript(ScriptMgr* mgr);
    
    #endif
    and this is my setup.cpp -
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    #define SKIP_ALLOCATOR_SHARING 1
    #include <ScriptSetup.h>
    
    extern "C" SCRIPT_DECL uint32 _exp_get_script_type()
    {
    	return SCRIPT_TYPE_MISC;
    }
    
    extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)	// Comment any script to disable it
    {
    	SetupNeutralGuards(mgr);
    	MyCustomScript(mgr);
    }
    
    #ifdef WIN32
    
    BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
    {
        return TRUE;
    }
    
    #endif
    All 3 files are in src\scripts\src\ExtraScripts\ (MyCustomScript.cpp, Setup.h, Setup.cpp) and MyCustomScript in the project is under Extrascripts\Scripts

    I think ive got the setup files done properly.

  9. #9
    rusfighter's Avatar Member
    Reputation
    1
    Join Date
    May 2008
    Posts
    22
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you have

  10. #10
    Link_S's Avatar Member
    Reputation
    125
    Join Date
    Dec 2008
    Posts
    293
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    This is how I'd write my OnEnterWorld script.

    OnEnterWorld.cpp
    Code:
    #include "StdAfx.h"
    
    void OnEnter(Player *_player)
    {
           _player->SetFFAPvPFlag();
    }
    
    void SetupMyCustomScript(ScriptMgr *mgr)
    {
    #ifdef WIN32
           mgr->register_hook(SERVER_HOOK_EVENT_ON_ENTER_WORLD, &OnEnter);
    #else
           mgr->register_hook(SERVER_HOOK_EVENT_ON_ENTER_WORLD, (void*)OnEnter);
    #endif
    }
    Setup.h
    Code:
    #ifndef MY_SCRIPTS_SETUP_H
    #define MY_SCRIPTS_SETUP_H
    
    void SetupMyCustomScript(ScriptMgr *mgr);
    
    #endif
    Setup.cpp
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    #define SKIP_ALLOCATOR_SHARING 1
    #include <ScriptSetup.h>
    
    extern "C" SCRIPT_DECL uint32 _exp_get_script_type()
    {
    	return SCRIPT_TYPE_MISC;
    }
    
    extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr *mgr)
    {
    	SetupMyCustomScript(mgr);
    }
    
    #ifdef WIN32
    BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
    {
        return TRUE;
    }
    #endif
    Of course, this code could be improved. Like setting an IF statement whether the player already have FFAPvP enabled or not.

    You should go learn basics of C++ before actually dealing with these things, it'd help you understand what the heck you're actually doin'.

    Some hints from me :

    - You don't need to create a class to declare a function, you just declare the function
    - Names are important, for example, you tried to use a function that didn't exists cause you named them wrong. ex;
    You used 'MyCustomScript' in the declaration and use within setup files. And used 'SetupMyCustomScript' in the actual script file. They should all have the same name otherwise it won't work -> And you'll receive that error :P

    NOTE; I don't think this code will work if you use the copy & paste shortcuts... Because I pulled it out of my ass xD




    Last edited by Link_S; 03-19-2010 at 03:35 PM. Reason: Added windows '&' instead of polymorph (void*) as my linux required '(void*)' and windows doesn't "/
    Why do I need a signature?

  11. #11
    Pretzal's Avatar Member
    Reputation
    8
    Join Date
    Aug 2008
    Posts
    57
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It almost worked, but i got it working. Brilliant
    Only problem was I had MyCustomScript in setup.* and setupcustomscript in the code you gave me. the other thing i noticed that im not very sure - whats the difference between pPlayer and _player? +rep anyways x4, will give the other half when i can

  12. #12
    Link_S's Avatar Member
    Reputation
    125
    Join Date
    Dec 2008
    Posts
    293
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    There is no difference at all, you could've named it 'retard' or 'babyface' if you'd like it, it's just a variable declaration.
    Go learn Basics of C++ and you'll understand :P
    Why do I need a signature?

  13. #13
    Pretzal's Avatar Member
    Reputation
    8
    Join Date
    Aug 2008
    Posts
    57
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh alright then =) Yeah im trying... lol. But ive never read anything about -> declaring a variable. anyways, thanks.

Similar Threads

  1. Need help! Client crashes with new custom editted models.
    By drsmoothness in forum WoW ME Questions and Requests
    Replies: 0
    Last Post: 05-09-2010, 09:44 PM
  2. New Here and new to ArcEmu. Please Help
    By echoezx in forum WoW EMU Questions & Requests
    Replies: 4
    Last Post: 09-14-2008, 06:01 PM
  3. [Solved] Adding new rows to DBC files?
    By eternalstrife in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 08-05-2008, 06:55 AM
  4. Help with executing custom item batch file to heidi sql?
    By Drelanarus in forum World of Warcraft Emulator Servers
    Replies: 10
    Last Post: 04-27-2008, 11:47 AM
  5. [HELP] CANNOT ADD MY NEW CUSTOM ITEM {error log inside}
    By vak in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 09-28-2007, 07:21 AM
All times are GMT -5. The time now is 11:51 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search