Raised This Month: $51 Target: $400
 12% 

[core] Player's cur. weap. info update meth. should be impr.


  
 
 
Thread Tools Display Modes
Author Message
VEN
Veteran Member
Join Date: Jan 2005
Old 06-20-2006 , 13:20   [core] Player's cur. weap. info update meth. should be impr.
#1

Player's current weapon information (pPlayer->current) not always updated properly.

For exmaple if player is used a player_weaponstrip entity:
Code:
stock fm_strip_user_weapons(index) {     new ent = fm_create_entity("player_weaponstrip")     if (!pev_valid(ent))         return 0     dllfunc(DLLFunc_Spawn, ent)     dllfunc(DLLFunc_Use, ent, index)     engfunc(EngFunc_RemoveEntity, ent)     return 1 }
pPlayer->current isn't updated, so get_user_weapon returned result is equal to previous pPlayer->current.

I'm not sure but i think that the problem is in emsg.cpp:
Code:
void Client_CurWeapon(void* mValue) {     static int iState;     static int iId;         switch (mState++)     {         case 0:             iState = *(int*)mValue;             break;         case 1:             if (!iState) break;             iId = *(int*)mValue;             break;         case 2:             if (!mPlayer) return;             if (!iState || (iId < 1 || iId >= MAX_WEAPONS)) break;             mPlayer->weapons[iId].clip = *(int*)mValue;             mPlayer->current = iId;             mPlayer->lastHit = mPlayer->lastTrace;     } }

I think the "case 2" code block should be changed to something like this:
Code:
            if (!mPlayer) return;             if (!iState || (iId < 0 || iId >= MAX_WEAPONS)) break;             mPlayer->current = iId;             if (iId == 0) break;             mPlayer->weapons[iId].clip = *(int*)mValue;             mPlayer->lastHit = mPlayer->lastTrace;

Last edited by adm; 06-22-2006 at 08:43.
VEN is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 06-20-2006 , 13:53  
#2

dont see anything wrong nor does your change make any sense to me
Freecode is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 06-20-2006 , 14:27  
#3

On every weapon change CurWeapon message is sent to the client.
It's even sent on player_weaponstrip entity use:
Code:
    MESSAGE_BEGIN( MSG_ONE, gmsgCurWeapon, NULL, pev );         WRITE_BYTE(0);         WRITE_BYTE(0);         WRITE_BYTE(0);     MESSAGE_END();
Since weapon index is 0, that event is skipped:
Code:
if (!iState || (iId < 1 || iId >= MAX_WEAPONS)) break;
and hence mPlayer->current isn't updated:
Code:
mPlayer->current = iId
VEN is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 06-20-2006 , 14:30  
#4

weapon 0 doesnt exist
Freecode is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 06-20-2006 , 14:57  
#5

Of course i know. But the message listed above can be intercepted and then mPlayer->current can be set to 0. The practical point of that is that this will prevent the incorrect get_user_weapon result.

If you still didn't get what i mean, my question is why get_user_weapon returns incorrect result after player_weaponstrip entity use?
Answer: because pPlayer->current isn't updated to 0.
Why? Probably because we igrone CurWeapon WeaponIndex == 0
Code:
if (!iState || (iId < 1 || iId >= MAX_WEAPONS)) break;

Probably your point that we can't set pPlayer->current to 0 for some reason? Well, the fact is still that there is a bug and it should be fixed. If i offered the incorrect solution or pointed to the incorrect amxmodx code section i apologize.
VEN is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 06-20-2006 , 15:03  
#6

i think its suppose to be like that. I dont think its ignoring, current is only set to your CURRENT weapon and since there is no weapon 0 current should not be set to 0. Otherwise your most likely breaking the whole point of current.
Freecode is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 06-20-2006 , 15:07  
#7

Yes, i see what you mean, but i hope we can have a certain workaround for get_user_weapon anyhow.
VEN is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 06-20-2006 , 15:10  
#8

get_user_weapon returns what you hold, and you cant hold weapon 0...because it doesnt exist. This is the way engine is suppose to work. I doubt there is anything to do about your problem, as you are not following engine standards.
Freecode is offline
karlos
Veteran Member
Join Date: Apr 2004
Location: Germany/Poland
Old 06-20-2006 , 15:12  
#9

if player has no weapon what value should be returned in your eyes ?
the ID of last used weapon ? then you need to rename the function to get_user_last_weapon and NOT get_user_weapon
__________________
alias White Panther
karlos is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 06-20-2006 , 15:16  
#10

fun's strip_user_weapons uses:
Code:
    void *_wpns = MF_PlayerPropAddr(params[1], Player_Weapons);     *reinterpret_cast<int *>(MF_PlayerPropAddr(params[1], Player_CurrentWeapon)) = 0;
i believe that sets current to 0.

Quote:
the ID of last used weapon ? then you need to rename the function to get_user_last_weapon and NOT get_user_weapon
I think you overlooked my point. Vice versa: get_user_weapon acts as get_user_last_weapon on player_weaponstrip entity use. Is that logical?
VEN is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode