In a post on the way player data transfers across level loads I linked to the following post by manoelka:
http://makaqu.tumblr.com/post/33894641346
It describes a situation where the player has runes when entering a map, makes a save game, and loads that save game in a fresh session of Quake. If they die and restart the map, they lose their runes. Today we are going to edit the QuakeC to work around this issue.
For a change of pace, today we’re going to start with the big, punchline change to the code, so you can work out the other changes for yourselves and clock out early! Start by finding the function respawn
in client.qc. Find the braces containing the comment // restart the entire server
and entirely replace the code contained with:
// put serverflags back to map's initial setting serverflags = startingserverflags; // request a reset to the parms reset_flag = TRUE; // "change" to the same level localcmd ("changelevel "); localcmd(mapname); localcmd("\n");
It is worth highlighting the important change. We are no longer using the “restart” command. Instead we’re using the “changelevel” command. How we will make this work is to restore serverflags and parms to how they would have been prior to entering this map, then re-entering the map.
Just two more changes to go! We will sort out parms first as that change is also in client.qc. Scroll up to SetChangeParms
and at the very start change it to
float reset_flag; void() SetChangeParms = { if(reset_flag) { setspawnparms(self); return; }
The setspawnparms
function is a builtin which does exactly what we want – put the parms back to how they were when we first entered the level. We’ve introduced the reset_flag
variable just as a way to communicate to this function that we’re attempting a “manual restart”, and that we want things to revert to level start settings.
That’s the parms, so what about the serverflags?. Well, in the code we’ve already seen, we restore them using a variable called startingserverflags
. So all we need to do is capture the initial state of serverflags
into that variable. Open world.qc and find the start of the worldspawn
function, then change the opening to:
float startingserverflags; void() worldspawn = { startingserverflags = serverflags;
Now this particular bug is vanquished.