As CreateEntityByName has broken, this my way to get ammo type.
(Ammo type needs for me to check/give/remove grenades from player inventory)
I use engine basic function for it CAmmoDef::Index(const char *).
For call this function we need CAmmoDef object that we can get with GetAmmoDef() function.
PHP Code:
Handle g_hGameConf;
int g_HEGrenadeOffset;
int g_FlashbangOffset;
int g_SmokegrenadeOffset;
int g_MolotovOffset;
int g_DecoyOffset;
public void OnPluginStart()
{
g_hGameConf = LoadGameConfigFile("gamedata");
g_HEGrenadeOffset = CAmmoDef_Index("AMMO_TYPE_HEGRENADE");
g_FlashbangOffset = CAmmoDef_Index("AMMO_TYPE_FLASHBANG");
g_SmokegrenadeOffset = CAmmoDef_Index("AMMO_TYPE_SMOKEGRENADE");
g_MolotovOffset = CAmmoDef_Index("AMMO_TYPE_MOLOTOV");
g_DecoyOffset = CAmmoDef_Index("AMMO_TYPE_DECOY");
}
int CAmmoDef_Index(const char[] type)
{
static Handle call = null;
if (call == null) {
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "CAmmoDef_Index");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
call = EndPrepSDKCall();
if (!call)
SetFailState("Can't load function call.");
}
static any AmmoDef = 0;
if (AmmoDef == 0)
AmmoDef = GetAmmoDef();
return SDKCall(call, AmmoDef, type);
}
any GetAmmoDef()
{
static Handle call = null;
if (call == null) {
StartPrepSDKCall(SDKCall_Static);
PrepSDKCall_SetFromConf(g_hGameConf, SDKConf_Signature, "GetAmmoDef");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
// No args
call = EndPrepSDKCall();
if (!call)
SetFailState("Can't load function call.");
}
return SDKCall(call);
}
gamedata:
Code:
"Games"
{
"csgo"
{
"Signatures"
{
"GetAmmoDef"
{
"library" "server"
"windows" "\x80\x3D\x2A\x2A\x2A\x2A\x00\x0F\x85\x2A\x2A\x2A\x2A\x6A\x0E"
"linux" "\x55\x89\xE5\x83\xEC\x38\x80\x3D\x2A\x2A\x2A\x2A\x00\x0F\x85\x2A\x2A\x2A\x2A"
}
"CAmmoDef_Index"
{
"library" "server"
"windows" "\x55\x8B\xEC\x8B\x45\x08\x85\xC0\x75\x2A\x83\xC8\xFF"
"linux" "\x55\x89\xE5\x57\x56\x53\xBB\xFF\xFF\xFF\xFF\x83\xEC\x1C\x8B\x45\x0C"
}
}
}
}