Can someone show me how to implement SDKHook_ShouldCollide ?
I have now:
Code:
public Action:Command_abc(client, args)
{
new bool:ress;
ress= SDKHookEx(client, SDKHook_ShouldCollide, SDK_ShouldCollide);
PrintToChat(client, "ress=%i", ress);
}
public Action:SDK_ShouldCollide(entity, &collisiongroup, &contentsmask, &bool:result)
{
PrintToChatAll("entity=%i collisiongroup=%i contentsmask=%i result=%i", entity, collisiongroup, contentsmask, result);
return Plugin_Handled;
}
When I use on server !abc I get: ress=1. Plugin never enters SDK_ShouldCollide callback.
From source I found that 1 = HookRet_InvalidEntity so why it's bad entity ?
What entity I should use ?
Why it has callback with arguments:
Code:
Action:public(entity, &collisiongroup, &contentsmask, &bool:result)
when on SDK source I found:
Code:
// Called by physics to see if we should avoid a collision test....
virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
ShouldCollide function from
hl2sdk-ob-valve:
Code:
bool CGameRules::ShouldCollide( int collisionGroup0, int collisionGroup1 )
{
if ( collisionGroup0 > collisionGroup1 )
{
// swap so that lowest is always first
swap(collisionGroup0,collisionGroup1);
}
#ifndef HL2MP
if ( (collisionGroup0 == COLLISION_GROUP_PLAYER || collisionGroup0 == COLLISION_GROUP_PLAYER_MOVEMENT) &&
collisionGroup1 == COLLISION_GROUP_PUSHAWAY )
{
return false;
}
#endif
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS && collisionGroup1 == COLLISION_GROUP_PUSHAWAY )
{
// let debris and multiplayer objects collide
return true;
}
// --------------------------------------------------------------------------
// NOTE: All of this code assumes the collision groups have been sorted!!!!
// NOTE: Don't change their order without rewriting this code !!!
// --------------------------------------------------------------------------
// Don't bother if either is in a vehicle...
if (( collisionGroup0 == COLLISION_GROUP_IN_VEHICLE ) || ( collisionGroup1 == COLLISION_GROUP_IN_VEHICLE ))
return false;
if ( ( collisionGroup1 == COLLISION_GROUP_DOOR_BLOCKER ) && ( collisionGroup0 != COLLISION_GROUP_NPC ) )
return false;
if ( ( collisionGroup0 == COLLISION_GROUP_PLAYER ) && ( collisionGroup1 == COLLISION_GROUP_PASSABLE_DOOR ) )
return false;
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS || collisionGroup0 == COLLISION_GROUP_DEBRIS_TRIGGER )
{
// put exceptions here, right now this will only collide with COLLISION_GROUP_NONE
return false;
}
// Dissolving guys only collide with COLLISION_GROUP_NONE
if ( (collisionGroup0 == COLLISION_GROUP_DISSOLVING) || (collisionGroup1 == COLLISION_GROUP_DISSOLVING) )
{
if ( collisionGroup0 != COLLISION_GROUP_NONE )
return false;
}
// doesn't collide with other members of this group
// or debris, but that's handled above
if ( collisionGroup0 == COLLISION_GROUP_INTERACTIVE_DEBRIS && collisionGroup1 == COLLISION_GROUP_INTERACTIVE_DEBRIS )
return false;
#ifndef HL2MP
// This change was breaking HL2DM
// Adrian: TEST! Interactive Debris doesn't collide with the player.
if ( collisionGroup0 == COLLISION_GROUP_INTERACTIVE_DEBRIS && ( collisionGroup1 == COLLISION_GROUP_PLAYER_MOVEMENT || collisionGroup1 == COLLISION_GROUP_PLAYER ) )
return false;
#endif
if ( collisionGroup0 == COLLISION_GROUP_BREAKABLE_GLASS && collisionGroup1 == COLLISION_GROUP_BREAKABLE_GLASS )
return false;
// interactive objects collide with everything except debris & interactive debris
if ( collisionGroup1 == COLLISION_GROUP_INTERACTIVE && collisionGroup0 != COLLISION_GROUP_NONE )
return false;
// Projectiles hit everything but debris, weapons, + other projectiles
if ( collisionGroup1 == COLLISION_GROUP_PROJECTILE )
{
if ( collisionGroup0 == COLLISION_GROUP_DEBRIS ||
collisionGroup0 == COLLISION_GROUP_WEAPON ||
collisionGroup0 == COLLISION_GROUP_PROJECTILE )
{
return false;
}
}
// Don't let vehicles collide with weapons
// Don't let players collide with weapons...
// Don't let NPCs collide with weapons
// Weapons are triggers, too, so they should still touch because of that
if ( collisionGroup1 == COLLISION_GROUP_WEAPON )
{
if ( collisionGroup0 == COLLISION_GROUP_VEHICLE ||
collisionGroup0 == COLLISION_GROUP_PLAYER ||
collisionGroup0 == COLLISION_GROUP_NPC )
{
return false;
}
}
// collision with vehicle clip entity??
if ( collisionGroup0 == COLLISION_GROUP_VEHICLE_CLIP || collisionGroup1 == COLLISION_GROUP_VEHICLE_CLIP )
{
// yes then if it's a vehicle, collide, otherwise no collision
// vehicle sorts lower than vehicle clip, so must be in 0
if ( collisionGroup0 == COLLISION_GROUP_VEHICLE )
return true;
// vehicle clip against non-vehicle, no collision
return false;
}
return true;
}
Collision groups:
Code:
enum Collision_Group_t
{
COLLISION_GROUP_NONE = 0,
COLLISION_GROUP_DEBRIS, // Collides with nothing but world and static stuff
COLLISION_GROUP_DEBRIS_TRIGGER, // Same as debris, but hits triggers
COLLISION_GROUP_INTERACTIVE_DEBRIS, // Collides with everything except other interactive debris or debris
COLLISION_GROUP_INTERACTIVE, // Collides with everything except interactive debris or debris
COLLISION_GROUP_PLAYER,
COLLISION_GROUP_BREAKABLE_GLASS,
COLLISION_GROUP_VEHICLE,
COLLISION_GROUP_PLAYER_MOVEMENT, // For HL2, same as Collision_Group_Player, for
// TF2, this filters out other players and CBaseObjects
COLLISION_GROUP_NPC, // Generic NPC group
COLLISION_GROUP_IN_VEHICLE, // for any entity inside a vehicle
COLLISION_GROUP_WEAPON, // for any weapons that need collision detection
COLLISION_GROUP_VEHICLE_CLIP, // vehicle clip brush to restrict vehicle movement
COLLISION_GROUP_PROJECTILE, // Projectiles!
COLLISION_GROUP_DOOR_BLOCKER, // Blocks entities not permitted to get near moving doors
COLLISION_GROUP_PASSABLE_DOOR, // Doors that the player shouldn't collide with
COLLISION_GROUP_DISSOLVING, // Things that are dissolving are in this group
COLLISION_GROUP_PUSHAWAY, // Nonsolid on client and server, pushaway in player code
COLLISION_GROUP_NPC_ACTOR, // Used so NPCs in scripts ignore the player.
COLLISION_GROUP_NPC_SCRIPTED, // USed for NPCs in scripts that should not collide with each other
LAST_SHARED_COLLISION_GROUP
};
From:
CCollisionProperty
Code:
CBaseEntity::m_CollisionGroup determines which other entities will collide with this one. The rules for which collision groups collide are in CGameRules::ShouldCollide() and can be customized to suit the needs of a particular mod.
This function is testing if one group of entities should colide with other group of entites.
In my it should look like this:
Code:
public bool:SDK_ShouldCollide(collisionGroup0, collisionGroup1)
{
if ((collisionGroup0 == MY_GROUP_1) && (collisionGroup1 == MY_GROUP_2))
return true; // collide
}
than I would be able to write my own rules or even overload groups 'cos there are only about 30 groups.
I would be really grateful if someone could manage to create this hook.