| SubStream |
05-08-2006 18:38 |
[PROBLEM SOLVED] - Converting from engine to fakemeta
I am converting (or attempting to anyhow) my plugin Anti-Silent Plant from using engine and fakemeta to only using fakemeta because VEN said it would be better this way. I need someone who fully understands fakemeta to tell me if the following has been done correctly.
Original code using fakemeta and engine:
Code:
/* AMXModX Script
*
* Title: Anti-Silent Plant (antisilentplant)
* Author: SubStream
*
* Current Version: 1.1
* Release Date: 2006-05-07
*
* For support on this plugin, please visit the following URL:
* fcos URL = <a href="http://forums.alliedmods.net/showthread.php?t=28133" target="_blank" rel="nofollow noopener">http://forums.alliedmods.net/showthread.php?t=28133</a>
*
* Anti-Silent Plant - Prevents a silent plant from occuring.
* Copyright (C) 2006 SubStream
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author Contact Email: <a href="mailto:[email protected]">[email protected]</a>
*/
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
new const gs_PLUGIN [] = "Anti-Silent Plant"
new const gs_VERSION [] = "1.1"
new const gs_AUTHOR [] = "SubStream"
new gs_C4_MODEL [] = "models/w_c4.mdl"
new bool: gb_CheckSound
new bool: gb_EntsReadyForUse
new Float: gf_c4origin [3]
new Float: gf_entorigin [3]
new g_c4entity
new g_entillusionary
new gi_soundnum
new g_sounds [5][] =
{
"weapons/c4_beep1.wav",
"weapons/c4_beep2.wav",
"weapons/c4_beep3.wav",
"weapons/c4_beep4.wav",
"weapons/c4_beep5.wav"
}
public plugin_init ()
{
register_plugin ( gs_PLUGIN, gs_VERSION, gs_AUTHOR )
if ( find_ent_by_class ( -1, "func_bomb_target" ) )
{
register_logevent ( "fn_triggerplanted" , 3, "1=triggered", "2=Planted_The_Bomb" )
register_logevent ( "fn_triggerroundstart" , 2, "1=Round_Start" )
register_forward ( FM_EmitSound, "fn_soundcheck" )
}
}
public fn_triggerplanted ()
{
gb_CheckSound = true
}
public fn_triggerroundstart ()
{
gb_CheckSound = false
gb_EntsReadyForUse = false
if ( is_valid_ent ( g_entillusionary ) )
{
remove_entity ( g_entillusionary )
}
}
public fn_soundcheck ( entity, channel, const s_SOUND [] )
{
if ( gb_CheckSound == true )
{
for ( gi_soundnum = 0; gi_soundnum < 5; gi_soundnum ++ )
{
if ( containi ( s_SOUND, g_sounds [gi_soundnum ] ) != -1 )
{
if ( gb_EntsReadyForUse == true )
{
fn_emitsound ()
}
else
{
fn_createentity ()
}
}
}
}
else
{
return PLUGIN_CONTINUE
}
return PLUGIN_CONTINUE
}
public fn_createentity ()
{
g_c4entity = find_ent_by_model ( -1, "grenade", gs_C4_MODEL )
entity_get_vector ( g_c4entity, EV_VEC_origin, gf_c4origin )
g_entillusionary = create_entity ( "func_illusionary" )
gf_entorigin = gf_c4origin
entity_set_origin ( g_entillusionary, gf_entorigin )
gb_EntsReadyForUse = true
fn_emitsound ()
}
public fn_emitsound ()
{
emit_sound ( g_entillusionary, CHAN_AUTO, g_sounds [gi_soundnum ], 1.0, ATTN_NORM, 0, PITCH_NORM )
}
Code Using ONLY fakemeta
Code:
/* AMXModX Script
*
* Title: Anti-Silent Plant (antisilentplant)
* Author: SubStream
*
* Current Version: 1.1
* Release Date: 2006-05-07
*
* For support on this plugin, please visit the following URL:
* fcos URL = <a href="http://forums.alliedmods.net/showthread.php?t=28133" target="_blank" rel="nofollow noopener">http://forums.alliedmods.net/showthread.php?t=28133</a>
*
* Anti-Silent Plant - Prevents a silent plant from occuring.
* Copyright (C) 2006 SubStream
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author Contact Email: <a href="mailto:[email protected]">[email protected]</a>
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
new const gs_PLUGIN [] = "Anti-Silent Plant"
new const gs_VERSION [] = "1.1"
new const gs_AUTHOR [] = "SubStream"
new gs_C4_MODEL [] = "models/w_c4.mdl"
new bool: gb_CheckSound
new bool: gb_EntReadyForUse
new Float: gf_c4origin [3]
new Float: gf_entorigin [3]
new g_c4entity
new g_entillusionary
new gi_soundnum
new g_sounds [5][] =
{
"weapons/c4_beep1.wav",
"weapons/c4_beep2.wav",
"weapons/c4_beep3.wav",
"weapons/c4_beep4.wav",
"weapons/c4_beep5.wav"
}
public plugin_init ()
{
register_plugin ( gs_PLUGIN, gs_VERSION, gs_AUTHOR )
if ( engfunc ( EngFunc_FindEntityByString, -1, "classname", "func_bomb_target" ) )
{
register_logevent ( "fn_triggerplanted" , 3, "1=triggered", "2=Planted_The_Bomb" )
register_logevent ( "fn_triggerroundstart" , 2, "1=Round_Start" )
register_forward ( FM_EmitSound, "fn_soundcheck" )
}
}
public fn_triggerplanted ()
{
gb_CheckSound = true
}
public fn_triggerroundstart ()
{
gb_CheckSound = false
if ( gb_EntReadyForUse == true )
{
engfunc ( EngFunc_RemoveEntity, g_entillusionary )
gb_EntReadyForUse = false
}
}
public fn_soundcheck ( entity, channel, const s_SOUND [] )
{
if ( gb_CheckSound == true )
{
for ( gi_soundnum = 0; gi_soundnum < 5; gi_soundnum ++ )
{
if ( containi ( s_SOUND, g_sounds [gi_soundnum ] ) != -1 )
{
if ( gb_EntReadyForUse == true )
{
fn_emitsound ()
}
else
{
fn_createentity ()
}
}
}
}
else
{
return PLUGIN_CONTINUE
}
return PLUGIN_CONTINUE
}
public fn_createentity ()
{
g_c4entity = engfunc ( EngFunc_FindEntityByString, -1, "model", gs_C4_MODEL )
pev ( g_c4entity, pev_origin, gf_c4origin )
g_entillusionary = engfunc ( EngFunc_CreateNamedEntity, "func_illusionary" )
gf_entorigin = gf_c4origin
engfunc ( EngFunc_SetOrigin, g_entillusionary, gf_entorigin )
gb_EntReadyForUse = true
fn_emitsound ()
}
public fn_emitsound ()
{
emit_sound ( g_entillusionary, CHAN_AUTO, g_sounds [gi_soundnum ], 1.0, ATTN_NORM, 0, PITCH_NORM )
}
I replaced line 76
Code:
if ( find_ent_by_class ( -1, "func_bomb_target" ) )
with line 75
Code:
if ( engfunc ( EngFunc_FindEntityByString, -1, "classname", "func_bomb_target" ) )
I replaced lines 92-96
Code:
gb_EntsReadyForUse = false
if ( is_valid_ent ( g_entillusionary ) )
{
remove_entity ( g_entillusionary )
with lines 92-96
Code:
if ( gb_EntReadyForUse == true )
{
engfunc ( EngFunc_RemoveEntity, g_entillusionary )
gb_EntReadyForUse = false
}
I replaced lines 129-136
Code:
public fn_createentity ()
{
g_c4entity = find_ent_by_model ( -1, "grenade", gs_C4_MODEL )
entity_get_vector ( g_c4entity, EV_VEC_origin, gf_c4origin )
g_entillusionary = create_entity ( "func_illusionary" )
gf_entorigin = gf_c4origin
entity_set_origin ( g_entillusionary, gf_entorigin )
with lines 128-135
Code:
public fn_createentity ()
{
g_c4entity = engfunc ( EngFunc_FindEntityByString, -1, "model", gs_C4_MODEL )
pev ( g_c4entity, pev_origin, gf_c4origin )
g_entillusionary = engfunc ( EngFunc_CreateNamedEntity, "func_illusionary" )
gf_entorigin = gf_c4origin
engfunc ( EngFunc_SetOrigin, g_entillusionary, gf_entorigin )
These are the changes I made to make the plugin work with fakemeta. I am new to using engfunc and pev.
Now here is the problem when used: When I plant the bomb, I hear the beeping noise anywhere I go. The entity with classname func_illusionairy is supposed to be created in the same origin as the c4 and beep when the c4 beeps and be removed at the beginning of the next round if it was created the round before. The version using engine and fakemeta together works perfectly fine. The rewrite of it only using fakemeta is not working fine. That is the version that I hear the beeping noise from anywhere I go. Does anyone know where I went wrong in using fakemeta??? Please point me in the right direction.
Edit: TY to Fatal and VEN for helping me solve this problem. Fixed code posted at the Anti-Silent Plant plugin page.
|