What are you wanting to do?

If pKiller is an NPC than it cannot be typecast to both a player and an NPC.
The player typecast will return NULL.

I think you want something like this

If( pKiller->IsNPC() )
{
        CAI_BaseNPC *pNPC = dynamic_cast<CAI_BaseNPC *>(pKiller);
        CHL2MP_Player *pMaster = NULL;

        If(pNPC->LikesMaster())
                pMaster = pNPC->GetMasterPlayer();
}

So now if pMaster is not NULL than you know that the npc likes his master
and that he had a valid master pointer.

Chris

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Matthew Dryden
Sent: Tuesday, June 03, 2008 3:31 PM
To: Discussion of Half-Life Programming
Subject: Re: [hlcoders] Casting BaseNPC to CHL2MP_Player

But the information I'm trying to pull is actually a player...it's just 
the owner of this particular NPC...:S

Emiel Regis wrote:
> You cannot type_cast from player to npc safely, because they differ  
> considerably. You should think of other way of doing this, I guess ;)
>
> On Tue, 03 Jun 2008 21:15:40 +0200, Matthew Dryden <[EMAIL PROTECTED]>  
> wrote:
>
>   
>> Hey all, I'm not familiar with pointers...wondering if you can give me a
>> push in the right direction:
>>
>>         if ( pKiller->IsNPC() )
>>         {
>> //            CAI_BaseNPC *pNPC = (CAI_BaseNPC*)pKiller;
>>             CAI_BaseNPC *pNPC = dynamic_cast<CHL2MP_Player*>(pKiller);
>>             if ( pNPC->LikesMaster() )
>>                 pKiller = pNPC->GetMasterPlayer();
>>         }
>>
>> I'm getting these errors:
>>
>> hl2mp_gamerules.cpp
>> ..\shared\hl2mp\hl2mp_gamerules.cpp(452) : error C2440: 'initializing' :
>> cannot convert from 'CHL2MP_Player *' to 'CAI_BaseNPC *'
>>         Types pointed to are unrelated; conversion requires
>> reinterpret_cast, C-style cast or function-style cast
>> ..\shared\hl2mp\hl2mp_gamerules.cpp(454) : error C2440: '=' : cannot
>> convert from 'CBasePlayer *' to 'CHL2MP_Player *'
>>         Cast from base to derived requires dynamic_cast or static_cast
>>
>> The idea is that if my monster likes me and kills another player or
>> monster...it will make the killer the owner of said monster...meaning I
>> killed the player.
>>
>> _______________________________________________
>> To unsubscribe, edit your list preferences, or view the list archives,  
>> please visit:
>> http://list.valvesoftware.com/mailman/listinfo/hlcoders
>>
>>     
>
>
>
>   


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to