AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [SM] How to make natives talk back and forth? (https://forums.alliedmods.net/showthread.php?t=249920)

Chdata 10-14-2014 14:51

[SM] How to make natives talk back and forth?
 
vsh.sp

PHP Code:

public APLRes:AskPluginLoad2(Handle:myselfbool:lateString: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:pluginnumParams)
{
    if (
VSHRoundState != 1)
    {
        return 
false;
    }

    return 
g_bIsCapEnabled;


vsh.inc

PHP Code:

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

capsplosion.sp

PHP Code:

#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

Re: [SM] How to make natives talk back and forth?
 
Make another native (VSH_SetCapEnabled)

friagram 10-15-2014 04:34

Re: [SM] How to make natives talk back and forth?
 
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.


All times are GMT -4. The time now is 07:31.

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