Quake3 programming: continued

Open discussion about any topic, as long as you abide by the rules of course!
Post Reply
eepberries
Posts: 1975
Joined: Mon Jan 24, 2005 10:14 pm

Quake3 programming: continued

Post by eepberries »

So I hacked money into my mod. I did it by adding a PERS_MONEY inxdex to the player_state->persistant[] indexes. When a players kills someone, it adds the money into PERS_MONEY. Now, this is working fine until the map changes. When this happens, the games crashes. I understand from previous discussion on the topic that this is because the data would need to be saved and carried over.

So, what is the best way to fix it? I'm guessing that before the round change the index needs to be cleared or something, right? How could I save this data to an external file after each round then load it back up the next round? (Also, what do I need to do to keep it from crashing? :D)
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post by ^misantropia^ »

Did you alter MAX_PERSISTANT, i.e. did you add a new member to persEnum_t? If so, that's again one of those things that the SDK and the engine share[1]. You can't safely tinker with it.

[1] You're actually overwriting the first member of the powerups array then, which comes next in the playerPersistant_t structure.
eepberries
Posts: 1975
Joined: Mon Jan 24, 2005 10:14 pm

Post by eepberries »

I dunno. I added it into here. So I gues that's a yes? How else can I do it then? I think the problem you're talking about is if you overwrite the first one, or write before it. Because this works fine until the map changes. Then it freezes

// player_state->persistant[] indexes
// these fields are the only part of player_state that isn't
// cleared on respawn
// NOTE: may not have more than 16
typedef enum {
PERS_SCORE, // !!! MUST NOT CHANGE, SERVER AND GAME BOTH REFERENCE !!!
PERS_HITS, // total points damage inflicted so damage beeps can sound on change
PERS_RANK, // player rank or team rank
PERS_TEAM, // player team
PERS_SPAWN_COUNT, // incremented every respawn
PERS_PLAYEREVENTS, // 16 bits that can be flipped for events
PERS_ATTACKER, // clientnum of last damage inflicter
PERS_ATTACKEE_ARMOR, // health/armor of last person we attacked
PERS_KILLED, // count of the number of times you died
// player awards tracking
PERS_IMPRESSIVE_COUNT, // two railgun hits in a row
PERS_EXCELLENT_COUNT, // two successive kills in a short amount of time
PERS_DEFEND_COUNT, // defend awards
PERS_ASSIST_COUNT, // assist awards
PERS_GAUNTLET_FRAG_COUNT, // kills with the guantlet
PERS_CAPTURES, // captures
PERS_MONEY
} persEnum_t;
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post by ^misantropia^ »

eepberries wrote:So I gues that's a yes?
Yes.
eepberries wrote:How else can I do it then?
Add the money variable to the gclient_t structure (g_local.h). Define a new event, say EV_MONEY (EV_* enumerations in bg_public.h) and, upon a kill, use G_AddEvent() to send it to the client. The client must then catch it in CG_EntityEvent (cg_event.c).

EDIT: or you could just send a message:

Code: Select all

trap_SendServerCommand( clientNum, va( "print "$ %d\n"", client->money ) );
Post Reply