SpawnGift(Float:vOrigin[3], index)
{
new iEntity = CreateEntityByName("prop_dynamic_override");
decl String:sTargetName[32], String:tmp[70];
IntToString(index, sTargetName, sizeof(sTargetName));
DispatchKeyValueVector(iEntity, "origin", vOrigin);
DispatchKeyValue(iEntity, "solid", "6");
decl Float:fValue, String:sValue[PLATFORM_MAX_PATH];
DispatchKeyValue(iEntity, "model", (GetTrieString(g_hGiftsTrie[index], "Model", sValue, sizeof(sValue))) ? sValue:MODEL);
DispatchKeyValue(iEntity, "targetname", sTargetName);
DispatchSpawn(iEntity);
SetEntProp(iEntity, Prop_Send, "m_usSolidFlags", 8);
SetEntProp(iEntity, Prop_Send, "m_CollisionGroup", 1);
Format(tmp, sizeof(tmp), "OnUser1 !self:kill::%0.2f:-1", (GetTrieValue(g_hGiftsTrie[index], "Lifetime", fValue)) ? fValue : LIFETIME);
SetVariantString(tmp);
AcceptEntityInput(iEntity, "AddOutput");
AcceptEntityInput(iEntity, "FireUser1");
new iRotating = CreateEntityByName("func_rotating");
DispatchKeyValueVector(iRotating, "origin", vOrigin);
DispatchKeyValue(iRotating, "targetname", sTargetName);
DispatchKeyValue(iRotating, "maxspeed", "180");
DispatchKeyValue(iRotating, "friction", "0");
DispatchKeyValue(iRotating, "dmg", "0");
DispatchKeyValue(iRotating, "solid", "0");
DispatchKeyValue(iRotating, "spawnflags", "64");
DispatchSpawn(iRotating);
SetVariantString("!activator");
AcceptEntityInput(iEntity, "SetParent", iRotating, iRotating);
AcceptEntityInput(iRotating, "Start");
Call_StartForward(g_hOnCreate);
Call_PushCell(iEntity);
Call_Finish();
SDKHook(iEntity, SDKHook_StartTouch, Hook_GiftStartTouch);
}
public Hook_GiftStartTouch(iEntity, iClient)
{
if (iClient > 0 && iClient <= MaxClients && IsPlayerAlive(iClient))
{
decl String:sIndex[10];
GetEntPropString(iEntity, Prop_Data, "m_iName", sIndex, sizeof(sIndex));
new index = StringToInt(sIndex);
Call_StartForward(g_hOnPickUp);
Call_PushCell(g_hGiftsTrie[index]);
Call_PushCell(iClient);
Call_PushCell(iEntity);
Call_PushCell(index);
Call_Finish();
}
}
public Gifts_OnPickUpGift(Handle:hTrie, iClient, iEntity, index)
{
AcceptEntityInput(iEntity, "Kill");
g_iHasClientGift[iClient] = index;
decl String:sValue[PLATFORM_MAX_PATH];
new Float:iVec[3];
GetClientAbsOrigin(iClient, Float:iVec);
EmitAmbientSound(((GetTrieString(hTrie, "Sound", sValue, sizeof(sValue))) ? sValue:SOUND), iVec, iClient, SNDLEVEL_NORMAL);
if(GetTrieString(hTrie, "TextToAll", sValue, sizeof(sValue)))
{
EditString(sValue, sizeof(sValue), iClient);
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && i != iClient) PrintToChat(i, sValue);
}
}
if(GetTrieString(hTrie, "TextToPlayer", sValue, sizeof(sValue)))
{
EditString(sValue, sizeof(sValue), iClient);
PrintToChat(iClient, sValue);
}
}