|
Member
|
01-09-2010
, 20:48
Re: [TF2] Detect ammo pickup
|
#9
|
Quote:
Originally Posted by J-Factor
1. Instead of using RemoveEdict simply use the inputs Disable/Enable/Toggle
2. Start a timer for 10 seconds (I think that's how long it takes)
3. Disable/Enable/Toggle again
4. Play the item spawn sound (look at the engineer dropping ammopack plugin for this)
|
I've tried that, but apparently, function EntityOutput_HealthKit is called even for a disabled entity, which resulted in timer being fired multiple times.
However, I've checked that dropping ammopack plugin, and apparently pickups can be simply spawned with DispatchSpawn, without any additional work required. The code below removes any touched medkit, and spawns a new one after 10 seconds.
PHP Code:
public OnPluginStart() { HookEntityOutput("item_healthkit_small", "OnCacheInteraction", EntityOutput_HealthKit); HookEntityOutput("item_healthkit_medium", "OnCacheInteraction", EntityOutput_HealthKit); HookEntityOutput("item_healthkit_full", "OnCacheInteraction", EntityOutput_HealthKit); }
public EntityOutput_HealthKit(const String:output[], caller, activator, Float:delay) { PrintToChatAll("Healthkit touched") if (activator > 0 && activator <= GetMaxClients() && IsClientInGame(activator) && IsPlayerAlive(activator)) { decl Float:Pos[3]; GetEntPropVector(caller, Prop_Send, "m_vecOrigin", Pos); PrintToChat(activator, "Pos: %f %f %f", Pos[0], Pos[1], Pos[2]); new Handle:dataPackHandle = CreateDataPack(); decl String:classname[32]; GetEdictClassname(caller, classname, sizeof(classname)); RemoveEdict(caller); WritePackString(dataPackHandle, classname); WritePackFloat(dataPackHandle, Pos[0]); WritePackFloat(dataPackHandle, Pos[1]); WritePackFloat(dataPackHandle, Pos[2]); CreateTimer(10.0, Timer_Medkit, dataPackHandle); } }
public Action:Timer_Medkit(Handle:timer, any:dataPackHandle) { ResetPack(dataPackHandle, false); decl String:classname[32]; ReadPackString(dataPackHandle, classname, sizeof(classname)); new Ammopack = CreateEntityByName(classname); DispatchSpawn(Ammopack); decl Float:Pos2[3]; Pos2[0] = ReadPackFloat(dataPackHandle); Pos2[1] = ReadPackFloat(dataPackHandle); Pos2[2] = ReadPackFloat(dataPackHandle); TeleportEntity(Ammopack, Pos2, NULL_VECTOR, NULL_VECTOR); }
Thanks a lot to all of you for the help! I would never have figured it out by myself.
Last edited by =MaTi=; 01-09-2010 at 20:58.
|
|
|
|