[HELP] C++ OnPlayerKill crash menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [HELP] C++ OnPlayerKill crash

    Hello,

    I've modified some scripts and merged them together since I suck at C++

    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    
    void AddGold(uint32 gold, Player * Plr)
    {
        uint32 gamm = Plr->GetUInt32Value(PLAYER_FIELD_COINAGE);
        uint32 goldammount = gamm + gold;
        Plr->SetUInt32Value(PLAYER_FIELD_COINAGE, goldammount);
    }
    
    void TakeGold(uint32 gold, Player * Plr)
    {
        uint32 gamm = Plr->GetUInt32Value(PLAYER_FIELD_COINAGE);
        uint32 goldammount = gamm - gold;
        Plr->SetUInt32Value(PLAYER_FIELD_COINAGE, goldammount);
    }
    
    void OnPlayerKill(Player* attacker, Player* victim)
    {
    	
        AddGold(10000, attacker);
    	if( attacker->GetSession() )
    		attacker->GetSession()->SendNotification("%sYou gain %u Gold.", "|cff00ff00", 1);
    
        TakeGold(5000, victim);
    	if( victim->GetSession() )
    		victim->GetSession()->SendNotification("%sYou lost %u Silver.", "|cff00ff00", 50);
    
    }
    
    
    void SetupArenaPvP(ScriptMgr * mgr)
    {
       mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, &OnPlayerKill);
    
    }
    Everything works fine, except the 'TakeGold'.

    It crashes the server if I kill another player.

    Does anyone know what the problem is?

    [HELP] C++ OnPlayerKill crash
  2. #2
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mm this seems familiar. XD

    Here, I'll give you a working version of the script you're trying to make:

    Code:
    void OnPlayerKill(Player* attacker, Player* victim)
    {
    	if( !attacker || !victim || victim==attacker )
    		return;
    
    	attacker->ModUnsigned32Value( PLAYER_FIELD_COINAGE , 10000 );
    	victim->ModUnsigned32Value( PLAYER_FIELD_COINAGE, -5000 );
    
    	if( attacker->GetSession() )
    		attacker->GetSession()->SendNotification("%sYou gain %u Gold.", "|cff00ff00", 1);
    
    	if( victim->GetSession() )
    		victim->GetSession()->SendNotification("%sYou lost %u Silver.", "|cff00ff00", 50);
    
    }
    
    
    void SetupArenaPvP(ScriptMgr * mgr)
    {
       mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, &OnPlayerKill);
    
    }

  3. #3
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, I'll try. Moment.

    Edit:
    Mmm, Server crashes again.

    The crash is because of this line:

    Code:
    victim->ModUnsigned32Value( PLAYER_FIELD_COINAGE, -5000 );
    Can it be that the server crashes because the victim doesn't have 50 silver? -- Has nothing to do with this, I tested it with 1 G.

    When I removed the line, it worked fine.. except the victim doesn't lose 50 S ofcourse.
    Last edited by gotiefan; 07-14-2009 at 06:03 AM.

  4. #4
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know a fix for this?

  5. #5
    Gastricpenguin's Avatar Legendary
    Reputation
    980
    Join Date
    Feb 2007
    Posts
    2,236
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple answer, check to see if they have 50 silver...

    Code:
    uint32 coin = victim->GetUInt32Value(PLAYER_FIELD_COINAGE);
    if(coin > 5000)
         victim->ModUnsigned32Value( PLAYER_FIELD_COINAGE, -5000 );
    else
         victim->SetUInt32Value(PLAYER_FIELD_COINAGE, 0);

    If they have more than 50 silver, it removes silver. If they have exactly 50 silver or less, it sets their money to 0.
    Life Puzzler WoW - Website | Forums

  6. #6
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Dr. Robotnik View Post
    Simple answer, check to see if they have 50 silver...

    Code:
    uint32 coin = victim->GetUInt32Value(PLAYER_FIELD_COINAGE);
    if(coin > 5000)
         victim->ModUnsigned32Value( PLAYER_FIELD_COINAGE, -5000 );
    else
         victim->SetUInt32Value(PLAYER_FIELD_COINAGE, 0);

    If they have more than 50 silver, it removes silver. If they have exactly 50 silver or less, it sets their money to 0.
    Like I said, it has nothing to do with that.

    It just crashes on kill...

    the Victim is the problem, something wrong with the code or something.

    He can't recognize the Victim?

  7. #7
    Gastricpenguin's Avatar Legendary
    Reputation
    980
    Join Date
    Feb 2007
    Posts
    2,236
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Test the script again and generate a crashdump (since it will crash).
    Open the crashdump and post the CallStack, piece of code that crashed, and locals.
    Life Puzzler WoW - Website | Forums

  8. #8
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    
    Loading Dump File [**]
    User Mini Dump File: Only registers, stack and portions of memory are available
    
    Symbol search path is: *** Invalid ***
    ****************************************************************************
    * Symbol loading may be unreliable without a symbol search path.           *
    * Use .symfix to have the debugger choose a symbol path.                   *
    * After setting your symbol path, use .reload to refresh symbol locations. *
    ****************************************************************************
    Executable search path is: 
    Windows Vista Version 6000 MP (4 procs) Free x86 compatible
    Product: WinNt, suite: SingleUserTS Personal
    Machine Name:
    Debug session time: Tue Jul 14 15:03:12.000 2009 (GMT+2)
    System Uptime: not available
    Process Uptime: 0 days 0:01:15.000
    .....................................................
    This dump file has an exception of interest stored in it.
    The stored exception information can be accessed via .ecxr.
    (a14.10f0): Access violation - code c0000005 (first/second chance not available)
    eax=00000237 ebx=1ec27530 ecx=1ec282a0 edx=1ec282a6 esi=1ec274f0 edi=14dbbe60
    eip=779d0f34 esp=14dbbb20 ebp=14dbbb30 iopl=0         nv up ei pl zr na pe nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll - 
    ntdll!KiFastSystemCallRet:
    779d0f34 c3              ret
    Code:
    victim->ModUnsigned32Value( PLAYER_FIELD_COINAGE, -5000 );
    What are the locals?
    Last edited by gotiefan; 07-14-2009 at 10:22 AM.

  9. #9
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mm that dump doesn't help much.

    The problem is most likely that you need to clean and rebuild both the core and the scripts.
    Try that and see what happens

  10. #10
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'm compiling them again.

    Edit:

    No succes... still crashing :-S
    Last edited by gotiefan; 07-14-2009 at 02:15 PM.

  11. #11
    gotiefan's Avatar Sergeant
    Reputation
    1
    Join Date
    Jan 2008
    Posts
    54
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed 2 things:

    Code:
     mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, &OnPlayerKill);
    To
    Code:
     mgr->register_hook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, (void*)OnPlayerKill);
    And

    Code:
    void OnPlayerKill(Player* attacker, Player* victim)
    To
    Code:
    void OnPlayerKill(PlayerPointer attacker, PlayerPointer victim)

    And it worked..

    Anyone can tell me what one made it work?

  12. #12
    Gastricpenguin's Avatar Legendary
    Reputation
    980
    Join Date
    Feb 2007
    Posts
    2,236
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would have helped if you told us you were using Aspire...
    ArcEmu scripts are NOT compatible for aspire. Aspire uses shared pointers, i.e. the PlayerPointer, GameObjectPointer, etc.

  13. #13
    AzolexX's Avatar Contributor
    Reputation
    179
    Join Date
    May 2007
    Posts
    587
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No they don't anymore, and even if they do he could not compile it.

    EDIT1:
    Originally Posted by Dr. Robotnik View Post
    Simple answer, check to see if they have 50 silver...

    Code:
    uint32 coin = victim->GetUInt32Value(PLAYER_FIELD_COINAGE);
    if(coin > 5000)
         victim->ModUnsigned32Value( PLAYER_FIELD_COINAGE, -5000 );
    else
         victim->SetUInt32Value(PLAYER_FIELD_COINAGE, 0);

    If they have more than 50 silver, it removes silver. If they have exactly 50 silver or less, it sets their money to 0.
    Thats worst code i ever saw...
    should be
    Code:
    uint32 pCoin = victim->GetUInt32Value(PLAYER_FIELD_COINAGE);
    
    if( pCoin <= 5000 )
         victim->SetUInt32Value(PLAYER_FIELD_COINAGE, 0)
    else
         victim->SetUInt32Value(PLAYER_FIELD_COINAGE, pCoin - 5000);


    Last edited by AzolexX; 07-15-2009 at 11:46 AM.

    Find about scripting, programming and music! My blog: https://worldofsmth.wordpress.com!

  14. #14
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ....
    There's virtually no difference azolex.
    And to correct both of you, you don't need that. ModUnsigned32Value checks to make sure that the value does not go negative, by default.

  15. #15
    Gastricpenguin's Avatar Legendary
    Reputation
    980
    Join Date
    Feb 2007
    Posts
    2,236
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol Azolex. Nice try being a smartass.

Page 1 of 2 12 LastLast

Similar Threads

  1. URGENT HELP NEEDED - Strange Crash, Will + Rep!!!
    By advantage in forum WoW EMU Questions & Requests
    Replies: 4
    Last Post: 08-07-2008, 07:30 PM
  2. [Help] Deeprun Tram crashing issue
    By DrkAngl in forum World of Warcraft Emulator Servers
    Replies: 0
    Last Post: 06-19-2008, 12:01 PM
  3. [HELP] Access Restriction Crash
    By volitle in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 06-19-2008, 08:09 AM
  4. need help with wow crashing
    By project anthrax in forum WoW EMU Guides & Tutorials
    Replies: 0
    Last Post: 03-29-2008, 01:11 AM
  5. [Help] Ascent.exe crashes with a strange error
    By Lakelog in forum World of Warcraft Emulator Servers
    Replies: 7
    Last Post: 01-07-2008, 11:30 PM
All times are GMT -5. The time now is 12:53 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