From 94b9bc9939dc4f023a66451bd74c418ab4e949f4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 23 Mar 2004 01:18:22 +0000 Subject: [PATCH] fixed give_item --- dlls/fun/fun.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/dlls/fun/fun.cpp b/dlls/fun/fun.cpp index 7d978fa3..2c3f6432 100755 --- a/dlls/fun/fun.cpp +++ b/dlls/fun/fun.cpp @@ -213,23 +213,46 @@ static cell AMX_NATIVE_CALL give_item(AMX *amx, cell *params) // native give_ite int length; const char *szItem = GET_AMXSTRING(amx, params[2], 1, length); + //check for valid item + if (strncmp(szItem, "weapon_", 7) && + strncmp(szItem, "ammo_", 5) && + strncmp(szItem, "item_", 5)) { + return 0; + } + //string_t item = MAKE_STRING(szItem); string_t item = ALLOC_STRING(szItem); // Using MAKE_STRING makes "item" contents get lost when we leave this scope! ALLOC_STRING seems to allocate properly... // Create the entity, returns to pointer pItemEntity = CREATE_NAMED_ENTITY(item); - VARS(pItemEntity)->origin = VARS(pPlayer)->origin; // nice to do VARS(ent)->origin instead of ent->v.origin? :-I - pItemEntity->v.spawnflags |= SF_NORESPAWN; + //VARS(pItemEntity)->origin = VARS(pPlayer)->origin; // nice to do VARS(ent)->origin instead of ent->v.origin? :-I + //I'm not sure, normally I use macros too =P + pItemEntity->v.origin = pPlayer->v.origin; + pItemEntity->v.spawnflags |= (1<<30); //SF_NORESPAWN; MDLL_Spawn(pItemEntity); + + int save = pItemEntity->v.solid; + MDLL_Touch(pItemEntity, ENT(pPlayer)); + + //The problem with the original give_item was the + // item was not removed. I had tried this but it + // did not work. OLO's implementation is better. + /* int iEnt = ENTINDEX(pItemEntity->v.owner); if (iEnt > 32 || iEnt <1 ) { MDLL_Think(pItemEntity); + }*/ + + if (pItemEntity->v.solid == save) { + REMOVE_ENTITY(pItemEntity); + //the function did not fail - we're just deleting the item + return -1; } - return 1; + return ENTINDEX(pItemEntity); } static cell AMX_NATIVE_CALL spawn(AMX *amx, cell *params) // spawn(id) = 1 param