From 1af005a047a8354b44da4cf87cfb93e3aa8db751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bergstr=C3=B6m?= Date: Thu, 17 Jun 2004 15:42:43 +0000 Subject: [PATCH] Added cs_get_no_knives, cs_set_no_knives --- dlls/cstrike/cstrike.cpp | 43 +++++++++++++++++++++++++++++++++---- dlls/cstrike/cstrike.h | 4 +++- dlls/cstrike/moduleconfig.h | 4 ++-- plugins/include/cstrike.inc | 12 ++++++++++- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/dlls/cstrike/cstrike.cpp b/dlls/cstrike/cstrike.cpp index 653155ed..8483b22d 100755 --- a/dlls/cstrike/cstrike.cpp +++ b/dlls/cstrike/cstrike.cpp @@ -178,10 +178,10 @@ static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params) // cs_set // Update scoreboard here..? MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "ScoreInfo", NULL)); WRITE_BYTE(params[1]); - WRITE_SHORT((int)pPlayer->v.frags); - WRITE_SHORT(params[2]); - WRITE_SHORT(0); // dunno what this parameter is (doesn't seem to be vip) - WRITE_SHORT(*((int *)pPlayer->pvPrivateData + OFFSET_TEAM)); + WRITE_SHORT((int)pPlayer->v.frags); // should these be byte? + WRITE_SHORT(params[2]); // should these be byte? + WRITE_SHORT(0); // dunno what this parameter is (doesn't seem to be vip) // should these be byte? + WRITE_SHORT(*((int *)pPlayer->pvPrivateData + OFFSET_TEAM)); // should these be byte? MESSAGE_END(); return 1; @@ -1326,6 +1326,20 @@ static cell AMX_NATIVE_CALL cs_get_user_hasprimary(AMX *amx, cell *params) // cs return *((int *)pPlayer->pvPrivateData + OFFSET_PRIMARYWEAPON); } +static cell AMX_NATIVE_CALL cs_get_no_knives(AMX *amx, cell *params) // cs_get_no_knives(); = 0 params +{ + // Returns 1 when g_noknives is true, else 0 + return g_noknives ? 1 : 0; +} + +static cell AMX_NATIVE_CALL cs_set_no_knives(AMX *amx, cell *params) // cs_set_no_knives(noknives = 0); = 1 param +{ + // Sets noknives mode on/off. When params[1] is 1, g_noknives goes true and no weapon_knife:s will from there be created until switch off again. + g_noknives = params[1] == 0 ? false : true; + + return 1; +} + AMX_NATIVE_INFO cstrike_Exports[] = { {"cs_set_user_money", cs_set_user_money}, {"cs_get_user_money", cs_get_user_money}, @@ -1357,10 +1371,31 @@ AMX_NATIVE_INFO cstrike_Exports[] = { {"cs_set_weapon_ammo", cs_set_weapon_ammo}, {"cs_get_weapon_ammo", cs_get_weapon_ammo}, {"cs_get_user_hasprim", cs_get_user_hasprimary}, + {"cs_get_no_knives", cs_get_no_knives}, + {"cs_set_no_knives", cs_set_no_knives}, //------------------- <-- max 19 characters! {NULL, NULL} }; +edict_s* FN_CreateNamedEntity(int classname) { + if (g_noknives && !strcmp(STRING(classname), "weapon_knife")) { + if (g_precachedknife) { + // Knife is creating + RETURN_META_VALUE(MRES_SUPERCEDE, NULL); + } + // Let it create a knife first time; this seems to keep it precached properly in case anyone give_items a knife later. + g_precachedknife = true; + } + + RETURN_META_VALUE(MRES_IGNORED, CREATENAMEDENTITY(classname)); +} + +void FN_ServerDeactivate() { + g_precachedknife = false; + + RETURN_META(MRES_IGNORED); +} + /***GetEngineFunctions******************/ void MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) { // Reset player model a short while (MODELRESETTIME) after this if they are using an edited model. diff --git a/dlls/cstrike/cstrike.h b/dlls/cstrike/cstrike.h index 6409a450..c0537604 100755 --- a/dlls/cstrike/cstrike.h +++ b/dlls/cstrike/cstrike.h @@ -44,6 +44,7 @@ #define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer) #define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue) #define GETCLIENTKEYVALUE (*g_engfuncs.pfnInfoKeyValue) +#define CREATENAMEDENTITY (*g_engfuncs.pfnCreateNamedEntity) #if defined __linux__ #define EXTRAOFFSET 5 // offsets 5 higher in Linux builds @@ -201,5 +202,6 @@ enum CS_Internal_Models { // cstrike-specific defines above CCstrikePlayer g_players[33]; -//bool g_initialized = false; +bool g_precachedknife = false; +bool g_noknives = false; // Globals above diff --git a/dlls/cstrike/moduleconfig.h b/dlls/cstrike/moduleconfig.h index c4f4d467..8f3f90c8 100755 --- a/dlls/cstrike/moduleconfig.h +++ b/dlls/cstrike/moduleconfig.h @@ -75,7 +75,7 @@ // #define FN_ClientCommand ClientCommand /* pfnClientCommand() (wd) Player has sent a command (typed or from a bind) */ #define FN_ClientUserInfoChanged ClientUserInfoChanged /* pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure */ // #define FN_ServerActivate ServerActivate /* pfnServerActivate() (wd) Server is starting a new map */ -// #define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */ +#define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */ // #define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */ #define FN_PlayerPostThink PlayerPostThink /* pfnPlayerPostThink() */ // #define FN_StartFrame StartFrame /* pfnStartFrame() */ @@ -180,7 +180,7 @@ // #define FN_AngleVectors AngleVectors // #define FN_CreateEntity CreateEntity // #define FN_RemoveEntity RemoveEntity -// #define FN_CreateNamedEntity CreateNamedEntity +#define FN_CreateNamedEntity CreateNamedEntity // #define FN_MakeStatic MakeStatic // #define FN_EntIsOnFloor EntIsOnFloor // #define FN_DropToFloor DropToFloor diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index 594e6734..64fc4abe 100755 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -175,4 +175,14 @@ native cs_get_weapon_ammo(index); /* Set amount of ammo in weapon's clip. */ -native cs_set_weapon_ammo(index, newammo); \ No newline at end of file +native cs_set_weapon_ammo(index, newammo); + +/* Returns 1 if no knives mode is enabled, else 0. + */ +native cs_get_no_knives(); + +/* Enabled no knives mode by calling this with value 1. Disabled with 0. + * No knives mode means that player will not be given a knife when spawning. + * You can still give knives (ie through fun's give_item). + */ +native cs_set_no_knives(noknives = 0);