AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Hooking entity output "OnPlayerUse" problem? (https://forums.alliedmods.net/showthread.php?t=69793)

jopmako 04-11-2008 13:31

Hooking entity output "OnPlayerUse" problem?
 
I'm create a "prop_physics" entity and hook it output.

Code:

#include <sourcemod>
#include <sdktools>
 
public OnPluginStart()
{
  HookEntityOutput("prop_physics", "OnHealthChanged", EntityOutput:OnEntityOutPut)
  HookEntityOutput("prop_physics", "OnPlayerUse", EntityOutput:OnEntityOutPut)
  RegConsoleCmd("ent_test", ConCmd:cmd_ent_test)
}
 
public OnMapStart()
{
  PrecacheModel("models/Gibs/HGIBS.mdl",true)
}
 
public Action:cmd_ent_test(id, args)
{
  new ent = CreateEntityByName("prop_physics")
  if (IsValidEntity(ent))
  {
      SetEntityModel(ent, "models/Gibs/HGIBS.mdl")
      // create an entity above of player
      new Float:origin[3]
      GetClientAbsOrigin(id, origin)
      origin[2] += 100
      DispatchKeyValueVector(ent, "origin", origin)
      DispatchKeyValue(ent, "targetname", "!activator")
      DispatchKeyValue(ent, "spawnflags", "256")
      DispatchSpawn(ent)
      SetEntityMoveType(ent, MOVETYPE_FLY)
      PrintToChat(id, "debug::CreateEntity(%d)", ent)
  }
  return Plugin_Handled
}
 
public OnEntityOutPut(const String:output[], caller, activator, Float:delay)
{
  PrintToChatAll("output=%s, caller=%d, activator=%d",output, caller, activator)
}

According of http://developer.valvesoftware.com/wiki/Prop_physics,
the output "activator" shoule be player index when we +USE or hit the entity.

In fact, when we hit the entity, output "OnHealthChanged" is working good.
But when +USE, the result alway "activator"=="caller" ?
Any problem with this code and how to get it work corrently?
Thanks.

blade81 07-21-2008 08:17

Re: Hooking entity output "OnPlayerUse" problem?
 
Hi, i've the same problem here. The !caller output is the same as !activator. Even if i do DispatchKeyValue(ent, "OnPlayerUse", "!activator,Kill,,1") for testing, the entity kills itself and not the activator. I would like to spawn medikits in my zombiemod, therefor i need this. Am i doing something wrong or is this a bug?

The code below doesn't work as well.
PHP Code:

    new ent CreateEntityByName("prop_physics");

    
PrecacheModel("models/Items/HealthKit.mdl");
    
SetEntityModel(ent,"models/Items/HealthKit.mdl");

    
// create an entity above of player
    
new Float:origin[3];
    
GetClientAbsOrigin(idorigin);
    
origin[1] += 100;
    
DispatchKeyValueVector(ent"origin"origin);
    
DispatchKeyValue(ent"spawnflags""256");
    
DispatchKeyValue(ent"OnPlayerUse""point_servercommand,command,sm_healthkit,0,-1");

    
PrintToChatAll("ent: %i"ent);
    
DispatchSpawn(ent); 


DiscoBBQ 07-21-2008 18:19

Re: Hooking entity output "OnPlayerUse" problem?
 
Same problem, I never got it to work. I just registered a console command to "+use" and save the ent in a public variable and catch it in the use function.


All times are GMT -4. The time now is 11:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.