AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How does return FMRES_SUPERCEDE; work in this plugin? (https://forums.alliedmods.net/showthread.php?t=25682)

SubStream 03-18-2006 13:51

How does return FMRES_SUPERCEDE; work in this plugin?
 
Code:

#include <amxmodx>
#include <fakemeta>

#define        PLUGIN                "Silent Assault"
#define        VERSION                "0.1"
#define        AUTHOR                "v3x"

public plugin_init()
{
  register_plugin(PLUGIN, VERSION, AUTHOR);
  register_forward(FM_EmitSound, "EmitSound");
}

#define MAX_SOUNDS        20

new g_szSnds[MAX_SOUNDS][] =
{
  "doors/doormove2.wav",
  "doors/doormove9.wav",
  "doors/doormove10.wav",
  "doors/doorstop4.wav",
  "debris/bustmetal1.wav",
  "debris/bustmetal2.wav",
  "debris/metal1.wav",
  "debris/metal2.wav",
  "debris/metal3.wav",
  "debris/metal4.wav",
  "debris/metal5.wav",
  "debris/metal6.wav",
  "player/pl_duct1.wav",
  "player/pl_duct2.wav",
  "player/pl_duct3.wav",
  "player/pl_duct4.wav",
  "player/pl_ladder1.wav",
  "player/pl_ladder2.wav",
  "player/pl_ladder3.wav",
  "player/pl_ladder4.wav"
}

new bool:g_bActive = false;

public plugin_cfg()
{
  new szMap[64];
  get_mapname(szMap, 63);

  if(containi(szMap, "_assault") != -1)
  {
    g_bActive = true;
    server_print("[AMXX] Silent Assault: ON");
  }
  else
    server_print("[AMXX] Silent Assault: OFF");
}

public EmitSound(entity, channel, const sound[])
{
  if(g_bActive)
  {
    //client_print(0, 3, "[SA] Sound emitted: %s", sound);

    for(new iSnd = 0; iSnd < MAX_SOUNDS; iSnd++)
    {
      if(containi(sound, g_szSnds[iSnd]) != -1)
        return FMRES_SUPERCEDE;
    }
  }
  return FMRES_IGNORED;
}

return FMRES_SUPERCEDE; - First of all... why did v3x put a ; after that line? Secondly... it says FMRES_SUPERCEDE returns a value of 4... so does that mean that line means return 4???? I am confused how that stops the sound if it returns a value of 4... unless the tutorial is misleading...

I assume with the name SUPERCEDE tied to it that it means to supercede any other functions/whatever that may be called normally by the forward... and I assume the FMRES_IGNORED; means to ignore anything else that may be called such as the sounds??? yet in tutorial it says FMRES_IGNORED = 1... and why is there a ; there as well???

Can someone clear this up for me and explain what returning those values actually does and if I am right in my assumption of what they do... ty

Twilight Suzuka 03-18-2006 13:57

the semi-colon denotes a line end. It is not nessasary, but it looks nice.

FMRES_*'s denote what to tell MetaMod about the forward return type. IGNOR E means continue on past, HANDLE means stop here, SUPERCEDE means this return value and operation goes above all others, OVERRIDE means to override the value.

Look it up in the documentation before asking here; it saves time and effort.

PM 03-19-2006 05:12

Quote:

Originally Posted by Twilight Suzuka
the semi-colon denotes a line end. It is not nessasary, but it looks nice.

FMRES_*'s denote what to tell MetaMod about the forward return type. IGNOR E means continue on past, HANDLE means stop here, SUPERCEDE means this return value and operation goes above all others, OVERRIDE means to override the value.

Look it up in the documentation before asking here; it saves time and effort.

In fact, HANDLED doesn't mean much; it's only provided for other plugins to be able to see that you did something. Metamod handles (F)MRES_IGNORED/(F)MRES_HANDLED equally IIRC. Only SUPERCEDE actually stops the original function from being called; and you can't stop other plugins from seeing the function call.


All times are GMT -4. The time now is 16:33.

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