PDA

View Full Version : [SM] How to make natives talk back and forth?


Chdata
10-14-2014, 14:51
vsh.sp

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("VSH_IsCapEnabled", Native_IsCapEnabled);
return APLRes_Success;
}

// This controls the cap's state at all times
stock SetControlPoint(bool:enable)
{
new CPm = -1; //CP = -1;

while ((CPm = FindEntityByClassname2(CPm, "team_control_point")) != -1)
{
if (CPm > MaxClients && IsValidEdict(CPm))
{
AcceptEntityInput(CPm, (enable ? "ShowModel":"HideModel"));
SetVariantInt(enable ? 0:1);
AcceptEntityInput(CPm, "SetLocked");
}
}

g_bIsCapEnabled = enable;
}

public Native_IsCapEnabled(Handle:plugin, numParams)
{
if (VSHRoundState != 1)
{
return false;
}

return g_bIsCapEnabled;
}

vsh.inc

/**
*
* @return True if cap is enabled, false otherwise.
*/
native bool:VSH_IsCapEnabled();

capsplosion.sp

#include <vsh>

public OnPluginStart()
{
HookEvent("teamplay_point_captured", evCapped);
}

/*
If some jackass caps...

*/
public Action:evCapped(Handle:hEvent, const String:sName[], bool:bDontBroadcast)
{
if (!g_bEnabled || !VSH_IsCapEnabled())
{
return Plugin_Continue;
}

SetControlPoint(false);

return Plugin_Continue;
}

stock SetControlPoint(bool:enable)
{
new CPm = -1; //CP = -1;

while ((CPm = FindEntityByClassname2(CPm, "team_control_point")) != -1)
{
if (CPm > MaxClients && IsValidEdict(CPm))
{
AcceptEntityInput(CPm, (enable ? "ShowModel":"HideModel"));
SetVariantInt(enable ? 0:1);
AcceptEntityInput(CPm, "SetLocked");
}
}

// g_bIsCapEnabled = enable;
// How do I make vsh.sp know the cap was disabled by another plugin?
}

Note: Yes it's pointless to check if the cap is enabled when the point was just captured, this is just an example.

rswallen
10-14-2014, 15:20
Make another native (VSH_SetCapEnabled)

friagram
10-15-2014, 04:34
Or you can make a global forward...
Sometimes it's ok to use the global forward callback and call it in the same plugin... And then register and call it in another as well. Just make sure they have the same params.