Ive created a player class in which each player has another type called 'PlayerGun' which of course is the Players Gun. Each Gun has a 'Ammo' member and its not a problem until i drop the gun. I change guns by using a function to pickup items and it changes the guns by
Player[0].PlayerGun = Gun_to_pickup.
At This point every thing is fine. but when i use ammo, drop the gun by picking up another (Player[0].PlayerGun = New_Gun_to_pickup), the ammo on the other gun resets. Im not sure why this is happening so maybe someone can give me some advice
Gun Class
class Gun{
int Type;
int Shootdistance;
int damage;
public:
Gun();
Gun(int,ScopeType);
Gun(int,int,int,int,int,int,int,CINT,CINT,ScopeType);
int Ammo;
int MaxAmmo;
float gPosx,gPosy,gPosz;
int LocaleID;
int Recoil;
UINT RStart,RStop;
ScopeType scopetype;
void Shoot(Gun playerGun);
friend void Pickup(int);
#ifdef DEBUG
friend void Init_debug(int iID);//Just for debug purposes
#endif
protected:
int GetDistCollision(int,int);
};
item pickup function
char pickup[256] = "";
void Pickup(int itemType)
{
int itype = GetStaticCollision(itemType,iPlayer1,radius);
switch(itype)
{
case iGun:
if(Player[0].PlayerGun.Type != Colt.Type )
{
strcpy(pickup,"Press ENTER to pick up Colt.");
if(dbReturnKey())
Player[0].PlayerGun = Colt;
}
else strcpy(pickup,"");
break;
case iGun1:
if(Player[0].PlayerGun.Type != Enfield.Type )
{
strcpy(pickup,"Press ENTER to pick up Enfield.");
if(dbReturnKey())
Player[0].PlayerGun = Enfield;
}
else strcpy(pickup,"");
break;
case iGun2:
if(Player[0].PlayerGun.Type != AK_47.Type )
{
strcpy(pickup,"Press ENTER to pick up AK-47.");
if(dbReturnKey())
Player[0].PlayerGun = AK_47;
}
else strcpy(pickup,"");
break;
default:
strcpy(pickup,"");
break;
}
dbCenterText(dbScreenWidth()/2,205,pickup);
}
EDIT:
Here The player struct if it helps
struct NetPlayer{
unsigned char typeId;
RakString name;
RakString MapName;
RakNetGUID systemGUID;
int LocalID;
bool exist;
float Health;
float Posx,Posy,Posz;
float Roty,Frame;
Gun PlayerGun;
};
if(You.AddCode.toPost)TGC.Users.CanHelp = true;
else return NoCodeMessage;