PDA

View Full Version : CBasePlayer class


vegittoss15
07-29-2007, 04:25 PM
I've spent a lot of time trying to understand why this doesn't work, but I'm afraid that I'm completely lost. I tested out accessibility of the CBasePlayer class by creating a temp variable and seeing if I could access it from the PlayerMove method. Alas, the client compiles correctly, but the server doesn't, claiming that the temp variable is not a member of the CBasePlayer class. Can someone please tell me what I'm doing wrong?

Nimgoble
07-29-2007, 06:07 PM
Show your code.

noob cannon lol
07-29-2007, 09:20 PM
If you seriously need help with variable declarations and classes, you shouldn't be jumping into the SDK right away.

vegittoss15
07-29-2007, 10:17 PM
I know plenty about c++, I've written code professionally for companies, and I've written basic low-level C for PIC processors, so please do not bring my knowledge of class structures into question here. As for the code, it's just a simple addition to the c_baseplayer.h and c_baseentity.h files where I've put in a temporary boolean variable in the public variables section.

Marine
07-30-2007, 09:38 AM
As for the code, it's just a simple addition to the c_baseplayer.h and c_baseentity.h files where I've put in a temporary boolean variable in the public variables section.
There is your problem. player.cpp = server side. c_ files are CLIENT SIDE.

If you want a networked variable you need to set it as a networked var in the server .h and then reference it in the client.h for it to show up.

I know plenty about c++, I've written code professionally for companies, and I've written basic low-level C for PIC processors, so please do not bring my knowledge of class structures into question here.

Please dont start a flame war... i get upset :(

vegittoss15
07-30-2007, 12:21 PM
I didn't start one, I was merely defending myself against a direct attack at my coding skills.

So simply adding the variable to server.h and referencing it wherever needed will solve my problems?

Keair
07-30-2007, 02:07 PM
No. You'll need to define it on both the client and the server. That means that you need to define the variable somewhere that both C_BasePlayer and CBasePlayer can get at it. player.h is for the server CBasePlayer and c_baseplayer.h is for the client. Just define it in both of these places. You can then use files such as baseplayer_shared.cpp (the shared means that both the client and the server access them) to initialize them. Be careful though, as when you change the variable, you likely WILL NOT be changing the variable in both places, as the code might only run on the client or the server side. This can cause a great deal of confusion.

If you want something to be specific to each player, for instance for multiplayer games, then you might want to look into including it into the m_hLocal structure (I think it's of class CLocalPlayerData or something, but I'm too lazy to look right now)

vegittoss15
07-30-2007, 02:12 PM
Can you please explain how I would make the variable networked then?

L. Duke
08-01-2007, 09:05 AM
Look at properties that are already networked to see how it works, for example, m_iHealth.

Or you could always try the Valve developer wiki (that's what it's for after all) which has an article about networking entities: http://developer.valvesoftware.com/wiki/Networking_Entities

vegittoss15
08-11-2007, 09:09 AM
Thanks, I did it the first way and it works now. :)