Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Get victim's name only.

Newbie Spellweaver
Joined
May 20, 2013
Messages
12
Reaction score
0
I want to get the name of the character that I've shot with a rocket, I was doing something like this.

In the OnExplosionGrenade, inside the loop I add this:
Code:
ZCharacter* pTargetCharacter = ZGetGame()->m_CharacterManager.Find( pTarget->GetUID() );

So then I can just do
Code:
pTargetCharacter->GetProperty()->GetName()
But instead of giving me just the name of the one I hit with the rocket, it gives me the name of all the characters in the room. How can I get only the name of the victim?.
 
Last edited:
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
What you're saying is impossible, unless you're calling the .Find method from within a loop where pTarget contains the next element in a container.
 
Upvote 0
Newbie Spellweaver
Joined
May 20, 2013
Messages
12
Reaction score
0
I tried also outside the loop with
Code:
ZCharacter *pTargetCharacter=ZGetGameInterface()->GetCombatInterface()->GetTargetCharacter();
but I got the same result. That should work? Because if it should work, then the problem is on my packet.
 
Upvote 0
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
I tried also outside the loop with
Code:
ZCharacter *pTargetCharacter=ZGetGameInterface()->GetCombatInterface()->GetTargetCharacter();
but I got the same result. That should work? Because if it should work, then the problem is on my packet.

Add it to the bottom of the function, right before where it returns. Then output it to mlog and verify you have the correct data.
 
Upvote 0
Newbie Spellweaver
Joined
May 20, 2013
Messages
12
Reaction score
0
Add it to the bottom of the function, right before where it returns. Then output it to mlog and verify you have the correct data.
Didn't think on that before tbh. I debugged it and, for my bad luck, it returns the name of all the players in the room.
Now I really don't know how the hell get the name of just the one I hit with a rocket. Btw, thanks for all.
 
Upvote 0
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Didn't think on that before tbh. I debugged it and, for my bad luck, it returns the name of all the players in the room.
Now I really don't know how the hell get the name of just the one I hit with a rocket. Btw, thanks for all.

Could you paste the entire function in this thread?
 
Upvote 0
Newbie Spellweaver
Joined
May 20, 2013
Messages
12
Reaction score
0
Is the OnExplosionGrenade in ZGame.cpp.
Code:
void ZGame::OnExplosionGrenade(MUID uidOwner,rvector pos,float fDamage,float fRange,float fMinDamage,float fKnockBack,MMatchTeam nTeamID)
{
    ZObject* pTarget = NULL;


    float fDist,fDamageRange;


    for(ZObjectManager::iterator itor = m_ObjectManager.begin(); itor != m_ObjectManager.end(); ++itor) 
    {
        pTarget = (*itor).second;
        
        bool bReturnValue = !pTarget || pTarget->IsDie();
        if( !pTarget || pTarget->IsDie())
            PROTECT_DEBUG_REGISTER(bReturnValue)
                continue;


        fDist = Magnitude(pos-(pTarget->GetPosition()+rvector(0,0,80)));
        
        bReturnValue = fDist >=fRange;
        if(fDist >= fRange)
            PROTECT_DEBUG_REGISTER(bReturnValue)
                continue;


        rvector dir=pos-(pTarget->GetPosition()+rvector(0,0,80));
        Normalize(dir);


        if(GetDistance(pos,pTarget->GetPosition()+rvector(0,0,50),pTarget->GetPosition()+rvector(0,0,130))<50)
        {
            fDamageRange = 1.f;
        }
        else
        {
#define MAX_DMG_RANGE    50.f
            fDamageRange = 1.f - (1.f-fMinDamage)*( max(fDist-MAX_DMG_RANGE,0) / (fRange-MAX_DMG_RANGE));
        }


        ZActor* pATarget = MDynamicCast(ZActor,pTarget);


        bool bPushSkip = false;


        if(pATarget) 
        {
            bPushSkip = pATarget->GetNPCInfo()->bNeverPushed;
        }


        if(bPushSkip==false)
        {
            pTarget->AddVelocity(fKnockBack*7.f*(fRange-fDist)*-dir);
        }
        else 
        {
            ZGetSoundEngine()->PlaySound("fx_bullethit_mt_met");
        }


        ZCharacter* pOwnerCharacter = ZGetGame()->m_CharacterManager.Find( uidOwner );
        if(pOwnerCharacter) 
        {
            CheckCombo(pOwnerCharacter, pTarget,!bPushSkip);
            CheckStylishAction(pOwnerCharacter);
        }


        float fActualDamage = fDamage * fDamageRange;
        float fRatio = ZItem::GetPiercingRatio( MWT_FRAGMENTATION , eq_parts_chest );
        pTarget->OnDamaged(pOwnerCharacter,pos,ZD_EXPLOSION,MWT_FRAGMENTATION,fActualDamage,fRatio);
    }


#define SHOCK_RANGE        1500.f


    ZCharacter *pTargetCharacter=ZGetGameInterface()->GetCombatInterface()->GetTargetCharacter();
    float fPower= (SHOCK_RANGE-Magnitude(pTargetCharacter->GetPosition()+rvector(0,0,50) - pos))/SHOCK_RANGE;


    if(fPower>0)
        ZGetGameInterface()->GetCamera()->Shock(fPower*500.f, .5f, rvector(0.0f, 0.0f, -1.0f));


    GetWorld()->GetWaters()->CheckSpearing( pos, pos + rvector(0,0,MAX_WATER_DEEP), 500, 0.8f );
}
I added
Code:
mlog("%s\n", pTargetCharacter->GetProperty()->GetName());
just after pTargetCharacter is defined and it prints me the name of all the players.
 
Upvote 0
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Is the OnExplosionGrenade in ZGame.cpp.
Code:
void ZGame::OnExplosionGrenade(MUID uidOwner,rvector pos,float fDamage,float fRange,float fMinDamage,float fKnockBack,MMatchTeam nTeamID)
{
    ZObject* pTarget = NULL;


    float fDist,fDamageRange;


    for(ZObjectManager::iterator itor = m_ObjectManager.begin(); itor != m_ObjectManager.end(); ++itor) 
    {
        pTarget = (*itor).second;
        
        bool bReturnValue = !pTarget || pTarget->IsDie();
        if( !pTarget || pTarget->IsDie())
            PROTECT_DEBUG_REGISTER(bReturnValue)
                continue;


        fDist = Magnitude(pos-(pTarget->GetPosition()+rvector(0,0,80)));
        
        bReturnValue = fDist >=fRange;
        if(fDist >= fRange)
            PROTECT_DEBUG_REGISTER(bReturnValue)
                continue;


        rvector dir=pos-(pTarget->GetPosition()+rvector(0,0,80));
        Normalize(dir);


        if(GetDistance(pos,pTarget->GetPosition()+rvector(0,0,50),pTarget->GetPosition()+rvector(0,0,130))<50)
        {
            fDamageRange = 1.f;
        }
        else
        {
#define MAX_DMG_RANGE    50.f
            fDamageRange = 1.f - (1.f-fMinDamage)*( max(fDist-MAX_DMG_RANGE,0) / (fRange-MAX_DMG_RANGE));
        }


        ZActor* pATarget = MDynamicCast(ZActor,pTarget);


        bool bPushSkip = false;


        if(pATarget) 
        {
            bPushSkip = pATarget->GetNPCInfo()->bNeverPushed;
        }


        if(bPushSkip==false)
        {
            pTarget->AddVelocity(fKnockBack*7.f*(fRange-fDist)*-dir);
        }
        else 
        {
            ZGetSoundEngine()->PlaySound("fx_bullethit_mt_met");
        }


        ZCharacter* pOwnerCharacter = ZGetGame()->m_CharacterManager.Find( uidOwner );
        if(pOwnerCharacter) 
        {
            CheckCombo(pOwnerCharacter, pTarget,!bPushSkip);
            CheckStylishAction(pOwnerCharacter);
        }


        float fActualDamage = fDamage * fDamageRange;
        float fRatio = ZItem::GetPiercingRatio( MWT_FRAGMENTATION , eq_parts_chest );
        pTarget->OnDamaged(pOwnerCharacter,pos,ZD_EXPLOSION,MWT_FRAGMENTATION,fActualDamage,fRatio);
    }


#define SHOCK_RANGE        1500.f


    ZCharacter *pTargetCharacter=ZGetGameInterface()->GetCombatInterface()->GetTargetCharacter();
    float fPower= (SHOCK_RANGE-Magnitude(pTargetCharacter->GetPosition()+rvector(0,0,50) - pos))/SHOCK_RANGE;


    if(fPower>0)
        ZGetGameInterface()->GetCamera()->Shock(fPower*500.f, .5f, rvector(0.0f, 0.0f, -1.0f));


    GetWorld()->GetWaters()->CheckSpearing( pos, pos + rvector(0,0,MAX_WATER_DEEP), 500, 0.8f );
}
I added
Code:
mlog("%s\n", pTargetCharacter->GetProperty()->GetName());
just after pTargetCharacter is defined and it prints me the name of all the players.

Add a call to mlog() at the top of the function as well to rule out that the function is being repeatedly called.
 
Upvote 0
Newbie Spellweaver
Joined
May 20, 2013
Messages
12
Reaction score
0
Add a call to mlog() at the top of the function as well to rule out that the function is being repeatedly called.
Nope, it's called just once.

Also, I was wrong. Using
Code:
ZCharacter ZGetGameInterface()->GetCombatInterface()->GetTargetCharacter();
returns my character.
 
Upvote 0
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Nope, it's called just once.

Also, I was wrong. Using
Code:
ZCharacter ZGetGameInterface()->GetCombatInterface()->GetTargetCharacter();
returns my character.

There's a MUID in the ZMyCharacter object which is called lastattacker. What's the value of that?
 
Upvote 0
Back
Top