Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 10-14-2014 , 14:51   [SM] How to make natives talk back and forth?
Reply With Quote #1

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.
__________________

Last edited by Chdata; 10-14-2014 at 14:53.
Chdata is offline
rswallen
SourceMod Donor
Join Date: Jun 2013
Location: 127.0.0.1
Old 10-14-2014 , 15:20   Re: [SM] How to make natives talk back and forth?
Reply With Quote #2

Make another native (VSH_SetCapEnabled)
__________________
rswallen is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 10-15-2014 , 04:34   Re: [SM] How to make natives talk back and forth?
Reply With Quote #3

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.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:12.


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