Talk:Adding an experience system

From Valve Developer Community
Revision as of 03:15, 31 December 2008 by D1Hazel1337 (talk | contribs) (Single Player Experience System Tutorial)
Jump to: navigation, search

There are some typos in this tutorial, overall very great and i could imagine how hard it was to make. if you follow the text right off you will get min 92 errors. plz if you got the time look over it again, an example is that it says "chl2mp_player.h" when it should be "C_hl2mp_player.h" and on one point you say put the code in hl2map_player.h when you mean C_hl2mp_player.h. its great otherwise, easy to fix for an average coder. Unsigned comment added by Fabbecool (talkcontribs). Please use four tildes (~~~~) to sign your username.

Single-player implementation?

I like the tutorial, easy to follow, but I'm attempting to make this work with the Single-Player Half-Life 2. I've run into a problem with the "Giving XP for kills" part - I can't find the "npc killed" event. Could anyone help me out? Bubbinska 08:14, 11 Mar 2008 (PDT)

That would be because there is no such function! You could make one though, here's a suggestion:
Every NPC has an Event_Killed function, which among other things calls the BaseClass Event_Killed, which is in this case CAI_BaseNPC::Event_Killed, in AI_BaseNPC.cpp I suggest modifying this, add in something like the following snippet somewhere after the condition that would cause it to return if the NPC was frozen.
	if ( info.GetAttacker()->IsPlayer() )
	{// we were killed by the player (only do this for kills by the player)
Then that function just needs made. In singleplay_gamerules.h (just after the PlayerKilled function:
	virtual void NPCKilled( CBaseEntity *pVictim, const CTakeDamageInfo &info );
And somewhere in singleplay_gamerules.cpp:
	void CSingleplayRules::NPCKilled( CBaseEntity *pVictim, const CTakeDamageInfo &info )
		; // your code here
Hopefully the gamerules pointer bit there isnt rubbish.
--Winston 03:22, 26 Mar 2008 (PDT)

Lines not working


ClientPrint( this, HUD_PRINTTALK, "You have reached level %i\n", m_iLevel ); // write it on their screen
UTIL_ClientPrintAll( HUD_PRINTCONSOLE, "%s has reached level %i\n", GetPlayerName(), m_iLevel ); // write it in everyone's console

don't work.

I used even m_iLevel.M_iValue unsuccessfully. The only working thing is (char*)m_iLevel.M_iValue. but i don't know what effects could have.

Also, the way to add exp from killing isn't working. Unsigned comment added by Gravity0 (talkcontribs). Please use four tildes (~~~~) to sign your username.

Probably some weird NetworkVar behaviour - I'd replace m_iLevel with GetLevel() in those functions. GetLevel just returns m_iLevel, but its of type int (not that any casting is needed, which is why its strange)
--Winston 02:09, 4 Mar 2008 (PST)

I can't help with your first problem, but if the add xp for kills problem you're having is that the two variables don't exist, add this just before the code he gives:
CBaseEntity *pInflictor = info.GetInflictor();
CBaseEntity *pKiller = info.GetAttacker();
I have a problem where the game crashes at the line where the hud file searches for the Hud_Level:
Crashes from a memory read error every time. Anyone know why?
Also worth noting is that the way its written, you get XP for killing yourself / teammates. Adding this will fix that:
if ( pScorer && stricmp(pKillaz->GetPlayerName(),pScorer->GetPlayerName()) != 0)
PoopShipDestroyer 11:24, 27 Feb 2008 (PST)

Fixed the "points for killing teammates / self" issue, and added the missing player pointers to the player killed function. As for the #Hud_Level error - have you definately added the string to the right text file? It looks like its failing to find it. You realise you have to substitute your mod name into "yourmod_english.txt", yeah? (odds are it will be in that folder already!) --Winston 02:06, 4 Mar 2008 (PST)

Actually, I just started a mod and I have no your(my?)mod_english.txt file anywhere in my mod folder. I guess it isn't generated automatically..? In any case, this seems like a good tutorial, haven't checked if it is working yet, but it's compiling nicely. Removed my other post, I found that: wchar_t *tempString = (g_pVGuiLocalize->Find("#Hud_Level")); works for me, instead of the line similar to: SetLabelText(vgui::localize()->Find("#Hud_Level"));. BrokenTripod 18:21, 27 May 2008 (PDT)

Great tutorial, very good way to get familiar with many aspects of making a mod. Does the speed implementation work? I've tried a couple different ways, including the one outlined here, to consistently make a player move faster, but haven't had any success. The player's speed seems to be periodically or randomly reset and I can't figure out why/when, or what function is doing that - and it's not just one of the StartSprinting or StopSprinting etc functions. Any ideas?

Problems Compiling

Hi, This is an excellent tutorial. I have found compiling errors that I would like help on.

Error	1	error C2039: 'localize' : is not a member of 'vgui'	e:\***PROTECTED***\mmorpg_typemod\src\game\client\hl2mp\hl2mp_hud_target_id.cpp	186	
Error	28	error C3861: 'localize': identifier not found	e:\***PROTECTED***\mmorpg_typemod\src\game\client\hl2mp\ui\hud_level.cpp	66	
Error	29	error C2065: 'C_HL2MP_Player' : undeclared identifier	e:\***PROTECTED***\mmorpg_typemod\src\game\client\hl2mp\ui\hud_level.cpp	98	
Error	30	error C2065: 'pPlayer' : undeclared identifier	e:\***PROTECTED***\mmorpg_typemod\src\game\client\hl2mp\ui\hud_level.cpp	98	
Error	31	error C2064: term does not evaluate to a function taking 0 arguments	e:\***PROTECTED***\mmorpg_typemod\src\game\client\hl2mp\ui\hud_level.cpp	98	
Error	32	error C2227: left of '->GetLevel' must point to class/struct/union/generic type	e:\***PROTECTED***\mmorpg_typemod\src\game\client\hl2mp\ui\hud_level.cpp	100

Please help! I tried to follow the tutorial word for word .

--Frostyfrog 17:43, 3 Aug 2008 (PDT)

Fixed the localize by replacing the bit by that with g_pVGuiLocalize.

Fixed others by placing

#include "c_hl2mp_player.h" 

at the start of hudlevel.cpp --Frostyfrog 19:37, 3 Aug 2008 (PDT)

Strange Question

would it be possible to add this a to a map, not a mod but just 1 map. Every time you play it you gain XP and it's saved to the map.--Fire Tock 21:24, 3 Oct 2008 (PDT)

This article is on coding for a mod. This could not be implemented using only a map file, and although its possible that a very limited system could be made to emulate an XP system, it certainly wouldn't be able to save character data. Regardless, I'm no mapper. --Winston 10:40, 15 Oct 2008 (PDT)

Single Player Experience System Tutorial

I'm an experienced programmer (technically coder), but have no experience in C++. I've managed to modify the 357 to use a scope (using the scope tutorial), and to make a new map, an wanted to try out what I could do with an experience system. I tried doing what you said with the respective singleplayer files, except I couldn't figure what they were. Could you make a tutorial at at people using the Singleplayer Half Life 2 Episode 1 source? Thank you in advance. ----D1Hazel1337 02:15, 31 Dec 2008 (PST)