View Single Post
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 04-08-2018 , 06:34   Re: [EXTENSION] NPCs in CS:S (extended)
Reply With Quote #10

Here is my first try to build the extension for linux:

HTML Code:
In file included from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Navigator.h:16:0,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CAI_NPC.h:10,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CCycler_Fix.h:5,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.h:6,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:2:
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h: In member function ‘void CSimpleSimTimer::Set(float, float)’:
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h:57:42: error: request for member ‘RandomFloat’ in ‘random’, which is of non-class type ‘long int() throw ()’
    m_next = gpGlobals->curtime + random->RandomFloat( minInterval, maxInterval );
                                          ^
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h: In member function ‘void CRandSimTimer::Set(float, float, bool)’:
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h:141:43: error: request for member ‘RandomFloat’ in ‘random’, which is of non-class type ‘long int() throw ()’
     m_next = gpGlobals->curtime + random->RandomFloat( m_minInterval, m_maxInterval );
                                           ^
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h: In member function ‘void CRandSimTimer::Reset()’:
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h:150:42: error: request for member ‘RandomFloat’ in ‘random’, which is of non-class type ‘long int() throw ()’
    m_next = gpGlobals->curtime + random->RandomFloat( m_minInterval, m_maxInterval );
                                          ^
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h: In member function ‘void CRandStopwatch::Start(float, float)’:
/home/d/SDK/hl2sdk-css/game/shared/simtimer.h:281:42: error: request for member ‘RandomFloat’ in ‘random’, which is of non-class type ‘long int() throw ()’
    m_next = gpGlobals->curtime + random->RandomFloat( minOverride, maxOverride );
                                          ^
In file included from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CAI_NPC.h:27:0,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CCycler_Fix.h:5,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.h:6,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:2:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h: In static member function ‘static void* CAI_Squad::operator new(size_t)’:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h:204:19: error: ‘g_pMemAlloc’ was not declared in this scope
   void *pResult = g_pMemAlloc->Alloc( nBytes );
                   ^
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h: In static member function ‘static void* CAI_Squad::operator new(size_t, int, const char*, int)’:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h:211:19: error: ‘g_pMemAlloc’ was not declared in this scope
   void *pResult = g_pMemAlloc->Alloc( nBytes, pFileName, nLine );
                   ^
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h: In static member function ‘static void CAI_Squad::operator delete(void*)’:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h:218:3: error: ‘g_pMemAlloc’ was not declared in this scope
   g_pMemAlloc->Free(pMem);
   ^
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h: In static member function ‘static void CAI_Squad::operator delete(void*, int, const char*, int)’:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/AI/CAI_Squad.h:222:3: error: ‘g_pMemAlloc’ was not declared in this scope
   g_pMemAlloc->Free(pMem);
   ^
In file included from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/CEntity.h:100:0,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.h:5,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:2:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CAI_NPC.h: In member function ‘virtual void CNPCBaseInteractive<NPC_CLASS>::InitDataMap()’:
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/macros.h:42:56: error: there are no arguments to ‘BaseEntity’ that depend on a template parameter, so a declaration of ‘BaseEntity’ must be available [-fpermissive]
   datamap_t *pMap = gamehelpers->GetDataMap(BaseEntity()); \
                                                        ^
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CAI_NPC.h:2019:2: note: in expansion of macro ‘CE_DECLARE_CLASS’
  CE_DECLARE_CLASS( CNPCBaseInteractive, NPC_CLASS );
  ^
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/macros.h:42:56: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
   datamap_t *pMap = gamehelpers->GetDataMap(BaseEntity()); \
                                                        ^
/home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/Class/CAI_NPC.h:2019:2: note: in expansion of macro ‘CE_DECLARE_CLASS’
  CE_DECLARE_CLASS( CNPCBaseInteractive, NPC_CLASS );
  ^
In file included from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:2:0:
/home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.h: At global scope:
/home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.h:11:6: error: use of enum ‘Entity_Function’ without previous declaration
 enum Entity_Function;
      ^
/home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp: In member function ‘void CE_NPC_Custom::CE_PostInit()’:
/home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:84:2: error: ‘CE_PostInit’ is not a member of ‘CE_NPC_Custom::BaseClass {aka CE_Cycler_Fix}’
  BaseClass::CE_PostInit();
  ^
/home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:96:34: error: invalid conversion from ‘unsigned char*’ to ‘size_t {aka unsigned int}’ [-fpermissive]
   memset(member_data, 0, sm_npc->original_member_data);
                                  ^
In file included from /home/d/SDK/hl2sdk-css/public/tier0/platform.h:56:0,
                 from /home/d/SDK/hl2sdk-css/public/tier0/basetypes.h:11,
                 from /home/d/SDK/hl2sdk-css/public/mathlib/vector.h:20,
                 from /home/d/SDK/hl2sdk-css/public/datamap.h:15,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/extension.h:4,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/CEntity/CEntity.h:82,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.h:5,
                 from /home/d/SDK/sourcemod/extensions/npc/Extension/SM/npc_custom.cpp:2:
/usr/include/string.h:62:14: note:   initializing argument 3 of ‘void* memset(void*, int, size_t)’
 extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
The SDK is about 1 year old... you can see all kinds of errors here, there are SDK problems and platform-specific problems and not sure about g_pmAlloc. A fast glance showed no roots for this variable. There are problems with the names of files as linux is case-sensitive. Well, and more errors is yet to come, ambuild doesn't show all of them.
Based on 4284d24

For playing sounds in CSS I use IEngineSound:
Code:
#include "engine/IEngineSound.h"
IEngineSound *engsound = NULL;
bool Extension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
	GET_V_IFACE_ANY(GetEngineFactory, engsound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
}
That's the way it works here: https://forums.alliedmods.net/showthread.php?t=268065
It provides all kinds of interfaces and can be used instead of EmitSound hooks.

For DispatchEffect TE_DispatchEffect can be used (or not... not sure):
Code:
	IServerTools *servertools = NULL;
	bool Tracer::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
	{
		GET_V_IFACE_ANY(GetServerFactory, servertools, IServerTools, VSERVERTOOLS_INTERFACE_VERSION);
	}
	ITempEntsSystem * tesystem = servertools->GetTempEntsSystem();
SetVariantString("ParticleEffectStop");
AcceptEntityInput(entity, "DispatchEffect");
Code:
	char conf_error[255];
	if (!gameconfs->LoadGameConfigFile("sdktools.games", &g_pGameConf, conf_error, sizeof(conf_error)))
	{
		if (error)
		{
			#if defined SHOW_MSG
			g_pSM->LogError(myself, "Could not read sdktools.games: %s", conf_error);
			#endif
		}
		return false;
	}
	int offset = 0;
	
	if(!g_pGameConf->GetOffset("AcceptInput", &offset) || !offset) {
		#if defined SHOW_MSG
		g_pSM->LogError(myself, "AcceptInput offset is broken");
		#endif
		gameconfs->CloseGameConfigFile(g_pGameConf);
		return false;
	}

	SH_MANUALHOOK_RECONFIGURE(AcceptInput,offset,0,0);

SH_DECL_MANUALHOOK5(AcceptInput, 0, 0, 0, bool, const char *, CBaseEntity *, CBaseEntity *, variant_t, int);
SH_MCALL(pEntity, AcceptInput)("DispatchEffect", pEntity, pEntity, value, 0);
SDKHooks can be used to control entities:

Code:
#include <ISDKHooks.h>
ISDKHooks *g_pSDKHooks = NULL;

bool Extension::SDK_OnLoad(char *error, size_t maxlength, bool late)
{	
	if(!g_pGameConf->GetOffset("PostThink", &offset) || !offset) {
		#if defined SHOW_MSG
		g_pSM->LogError(myself, "PostThink offset is broken");
		#endif
		gameconfs->CloseGameConfigFile(g_pGameConf);
		return false;

	}
	//Spawn
	//SetTransmit
	//PreThink...
	//All kinds of vhooks
	sharesys->AddDependency(myself, "sdkhooks.ext", true, true);   
	SM_GET_IFACE(SDKHOOKS, g_pSDKHooks);
	if (g_pSDKHooks != NULL)
	{
		g_pSDKHooks->AddEntityListener(&g_entlistener);
	}  
}
void Extension::SDK_OnUnload()
{
	if (g_pSDKHooks != NULL)
	{
		g_pSDKHooks->RemoveEntityListener(&g_entlistener);
	}
}
GameRules can be taken from sdktools:
https://sm.alliedmods.net/new-api/sd...eRules_GetProp

Collision tests:
Code:
#include <IEngineTrace.h>
class CTraceFilterPhysicsEntity : public CTraceFilterEntitiesOnly
{
public:
	CTraceFilterPhysicsEntity()
	{
	}
	virtual bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask)
	{
		CBaseEntity *pEntity = (CBaseEntity *) pServerEntity;
		char *classname = CHelper::getClassname(pEntity);
		if(!classname || !strstr (classname, "prop_physics")) {
			return false; 
		}
		return true;
	}
};
IEngineTrace *enginetrace = NULL;
bool Extension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
	GET_V_IFACE_ANY(GetEngineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER);
}
	Ray_t ray;
	ray.Init(eye_position, vec_end);
	
	trace_t tr;
	CTraceFilterEntity simple(pEdict->GetIServerEntity());	
	enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr);	
	if (tr.fraction == 1.0f)
	{
		return NULL;
	}
Attached Files
File Type: 7z npc.7z (753.6 KB, 271 views)

Last edited by kadet.89; 04-08-2018 at 08:11.
kadet.89 is offline
Send a message via Skype™ to kadet.89