User:Dutchmega/code: Difference between revisions
Line 103: | Line 103: | ||
Also take a look at the code from [[SDK_Known_Issues_List#Sticky_Player_Collisions|Sticky Player Collisions]] | Also take a look at the code from [[SDK_Known_Issues_List#Sticky_Player_Collisions|Sticky Player Collisions]] | ||
== PHP's substr == | |||
By [[User:Vaber|Vaber]]: | |||
<pre>char * substr( char * dst, const char * src, signed int from, signed int to) | |||
{ | |||
if( (int)strlen( src ) < from ) | |||
{ | |||
strcpy( dst, src ); | |||
return dst; | |||
} | |||
int ifrom = (from >= 0) ? from : ((int)strlen(src) + from); | |||
int ito = (to >= 0) ? to : ((int)strlen(src) + to) - ifrom; | |||
int i = ifrom; | |||
int j = 0; | |||
for( ; i < ito + ifrom; i++, j++) | |||
{ | |||
dst[ j ] = src[ i ]; | |||
} | |||
dst[ j ] = 0; | |||
return dst; | |||
} | |||
char * substr( char * dst, const char * src, signed int pos ) | |||
{ | |||
return substr( dst, src, pos, (int)strlen( src ) ); | |||
}</pre> |
Revision as of 15:01, 20 August 2006
I've got more of this stuff. Where should I put them all? Just here or... somewhere else... (Ha! you didn't expect the last 2 words, did you?)
Making the antlion burn!
Add the following under protected
in npc_antlion.h
virtual bool AllowedToIgnite( void ) { return true; }
Well, now the damh thing burns but it doesn't visually respond to it. You can use the drown-animation: Add the following piece of code to the top of the function GatherConditions():
if( IsOnFire() ) { SetCondition( COND_ANTLION_IN_WATER ); }
UTIL_LoadTexture
Here's a very handy function from the Plan Of Attack source.
#ifdef CLIENT_DLL int UTIL_LoadTexture(const char *szFile) { char szStr[256]; // try to pull it int iID = vgui::surface()->DrawGetTextureId(szFile); // did we get it? if(iID >= 0) return iID; // does the file exist? Q_snprintf(szStr, sizeof(szStr), "materials/%s.vmt", szFile); if(!vgui::filesystem()->FileExists(szStr)) { DevMsg("UTIL_LoadTexture: texture %s does not exist!\n", szFile); return -1; } // create the new texture iID = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile(iID, szFile, true, false); return iID; } #endif
Disallow players connecting to a server with a different version
Add the file version.h
to your game_shared and add it to both projects. Content:
#define VERSION "0.01"
Then add to cdll_client_int.cpp
:
void cl_versionCallback_f( ConVar *var, char const *pOldString ) { if( Q_stricmp( var->GetString(), var->GetDefault() ) ) var->Revert(); } static ConVar cl_version ( "cl_version", VERSION, FCVAR_USERINFO|FCVAR_CLIENTDLL, "The version of this mod", cl_versionCallback_f );
Then open GameInterface.cpp
and find the function ClientConnect()
Replace the contents of that function with this:
// DM: Get the version of the client and compare it with the server's version const char* version = engine->GetClientConVarValue( engine->IndexOfEdict( pEdict ), "cl_version" ); if (stricmp(VERSION, version) == 0) { return g_pGameRules->ClientConnected( pEdict, pszName, pszAddress, reject, maxrejectlen ); // Aka true } else { char string [256]; Q_snprintf( string, sizeof(string), "The server runs a different version (%s)", VERSION); Q_strcpy( reject, string ); maxrejectlen = strlen(string); return false; }
Just don't forget to change the define everytime you release a new version
Improved lagcompensation code
Open dlls/player_lagcompensation.cpp
and replace, around line 369
// lost track, too much difference return;
with
// DM: Some small improvements for lagcompensation // From Plan of Attack-source // did we found a context smaller then target time ? if ( record->m_flSimulationTime <= flTargetTime ) break; // hurra, stop // store this position for the next time through the loop prevOrg = record->m_vecOrigin; // go one step back curr = track->Next( curr );
Also take a look at the code from Sticky Player Collisions
PHP's substr
By Vaber:
char * substr( char * dst, const char * src, signed int from, signed int to) { if( (int)strlen( src ) < from ) { strcpy( dst, src ); return dst; } int ifrom = (from >= 0) ? from : ((int)strlen(src) + from); int ito = (to >= 0) ? to : ((int)strlen(src) + to) - ifrom; int i = ifrom; int j = 0; for( ; i < ito + ifrom; i++, j++) { dst[ j ] = src[ i ]; } dst[ j ] = 0; return dst; } char * substr( char * dst, const char * src, signed int pos ) { return substr( dst, src, pos, (int)strlen( src ) ); }