AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [PROBLEM SOLVED] - Converting from engine to fakemeta (https://forums.alliedmods.net/showthread.php?t=28157)

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.

SweatyBanana 05-08-2006 19:18

Try using this:

http://www.amxmodx.org/funcwiki.php?go=func&id=952

EF_EmitSound

SubStream 05-08-2006 19:21

would that make any difference since emit_sound is from the amxmodx core module??? Also.. I hear the sound at the time but for some reason I hear it everywhere I go.

Twilight Suzuka 05-08-2006 19:22

I want to know why you would go through the effort of converting from engine to FM.

SubStream 05-08-2006 19:24

go check out the anti-silent plant forum. VEN suggested I do it and he knows more than me so I thought it was a good idea since he said so. He said I could use only fakemeta and do the same job. I personally am only getting a headache so far.

What is your suggestions Suzuka? Does switching from engine and fakemeta to only fakemeta matter that much?

Brad 05-08-2006 20:30

Generally speaking, given the choice of using engine or not using engine, it's better not to use it because if it's enabled, it'll raise your CPU usage all by itself.

Having said that, I'd reckon that most people have engine enabled already anyway and thus, using engine in your plugin wouldn't matter.

It really just boils down to principle unless there becomes a massive push to convert the majority of plugins that use engine to use fakemeta instead.

SubStream 05-08-2006 20:33

do you have any insight Brad on how I might convert it? I understand what your point is and Suzuka said there is no point to worry about it either.. however I would like to learn where my mistakes are.

Brad 05-08-2006 20:38

I wish I did but I'm a bit fuzzy on using fakemeta in general. Engine is much easier. :wink:

SubStream 05-08-2006 20:40

Quote:

Originally Posted by Brad
I wish I did but I'm a bit fuzzy on using fakemeta in general. Engine is much easier. :wink:

LOL... thats why I used it... I immediately understood it...

FatalisDK 05-08-2006 22:10

Code:
g_entillusionary = engfunc ( EngFunc_CreateNamedEntity, "func_illusionary" )

->

Code:
new ClassName = engfunc( EngFunc_AllocString, "func_illusionary" ) g_entillusionary = engfunc ( EngFunc_CreateNamedEntity, ClassName )


All times are GMT -4. The time now is 04:59.

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