Talk:Adding an experience system
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 (talk • contribs) Always sign your posts with four tildes (~~~~
)
- Has this information already been added to the experience page or do we still need to self edit it?
- It would also be helpful if you specified where exactly these fixes need to be applied to in the text. --Boogerhead 01:26, 23 August 2010 (UTC)
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) ((CSingleplayRules*)GameRules())->NPCKilled(this,info); }
- 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)
I'm adapting this system for MP but since the hl2mp_gamerules are in a different folder (i.e HL2MP) this bit in bold
if ( info.GetAttacker()->IsPlayer() )
{// we were killed by the player (only do this for kills by the player)
((CHL2MPRules*)GameRules())->NPCKilled(this,info);
}
Doesn't work, any suggestions --Disabled logic 12:44, 21 February 2012 (PST)
Also for single player, remember to add these in your player entity's BEGIN_DATADESC( CMyPlayerClassname ) block:
DEFINE_FIELD( m_iExp, FIELD_INTEGER ),
DEFINE_FIELD( m_iLevel, FIELD_INTEGER ),
Unless you want to start over at level 1 every time you play your mod.--Empbox 12:37, 7 August 2009 (UTC)
Pointer
How do you get a pointer to the player from singleplay_gamerules.cpp? I'm just trying to do this:
void CSingleplayRules::NPCKilled( CBaseEntity *pVictim, const CTakeDamageInfo &info ) { Cblahblah *pPlayer = blahblahblah; what goes here? nothing seems to work pPlayer->AddXP(1); }
--Empbox 00:57, 7 August 2009 (UTC)
- Use GetLocalPlayer(). It's global. --TomEdwards 10:27, 7 August 2009 (UTC)
- Yeah, my bad, I should be more specific. Using the following line:
CBasePlayer *pPlayer = GetLocalPlayer();
- results in:
1>..\shared\singleplay_gamerules.cpp(141) : error C3861: 'GetLocalPlayer': identifier not found
1>..\shared\singleplay_gamerules.cpp(142) : error C2039: 'AddXP' : is not a member of 'C_BasePlayer'
- The first one is an easy fix, but why is the second one getting a client player? Can we get our server player, where our new members reside? --Empbox 12:37, 7 August 2009 (UTC)
- I think what you're missing here is that GameRules is shared code that runs on both the server and the client, and that both errors are coming from the client. The first one must be a bug in Valve's code since the function is supposed to be available in both DLLs: Valve appear to use
C_BasePlayer::GetLocalPlayer()
on the client instead, so I'd do that with an #ifdef. The second error is because you've not implemented the AddXP() function to the player's clientside entity: the easiest solution is to move the entire XP system to shared code (hl2_player_shared.h and a new .cpp you create).
- I think what you're missing here is that GameRules is shared code that runs on both the server and the client, and that both errors are coming from the client. The first one must be a bug in Valve's code since the function is supposed to be available in both DLLs: Valve appear to use
I Have found a fix for this. You copy the GetLocalPlayer();
Function and dependencies and rename it something like GetLocalHLPlayer();
And modify it accordingly. Enjoy! MLSTRM 17:09, 13 December 2009 (UTC)
- Actually no, that doesn't work (compiler check shows error (facepalm*)) instead go to the
CHL2_Player
code and look for thedynamic_cast
involving apPlayer
. Copy that into the gamerules section and enjoy! This actually works! Yay. sorry about tthe first post. MLSTRM 16:38, 14 December 2009 (UTC)
Lines not working
Lines
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 (talk • contribs) Always sign your posts with four tildes (~~~~
)
- 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:
SetLabelText(vgui::localize()->Find("#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)
No hud_battery
When it says copy the contents of hud_battery to hud_level. BUT THERE IS NO HUD_BATTERY FILE.
RESOLVED
I found the hud_battery file.
Npc Killed in MP
I'm looking for some help on adding a function where when a npc is killed (Zombie) 1 XP is given to the player. Does anyone know how i can do that --Disabled logic 11:31, 21 February 2012 (PST)