Raised This Month: $12 Target: $400
 3% 

Common Issues and Examples/Solutions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-25-2010 , 17:07   Common Issues and Examples/Solutions
Reply With Quote #1

This is a compilation of examples, explanations, and answers for commonly asked questions / issues.

The Countdown
Code:
#include <amxmodx> #define TASKID  1996 #define SECONDS 10 new iSeconds public plugin_init() {     register_plugin( "Countdown Example", "1.0", "Wrecked" )         register_logevent( "LogEventRoundStart", 2, "1=Round_Start" ) } public LogEventRoundStart() {     if( task_exists( TASKID ) )         remove_task( TASKID )             iSeconds = SECONDS     set_task( 1.0, "TaskShowCountdown", TASKID, _, _, "a", SECONDS ) } public TaskShowCountdown() {     set_hudmessage( 120, 120, 120, 0.50, 0.50, 0, 0.1, 0.8, 0.1, 0.1, -1 )     show_hudmessage( 0, "Seconds Remaining: %i", iSeconds-- ) }
Detecting Kill/Headshot Streaks

Code:
#include <amxmodx> new Headshots[33] new Kills[33] public plugin_init() {     register_plugin( "How To Keep Kill Counts", "1.0", "Wrecked" )         register_event( "DeathMsg", "EventDeathMsg", "a" )         register_logevent( "LogEventRoundStart", 2, "1=Round_Start" ) } public EventDeathMsg() {     new killer = read_data( 1 )     new victim = read_data( 2 )         Headshots[victim] = 0     Kills[victim] = 0     Kills[killer]++         if( read_data( 3 ) ) // headshot         Headshots[killer]++             // Kills holds kills of each player     // Headshots holds headshots } public LogEventRoundStart() {     arrayset( Headshots, 0, 33 )     arrayset( Kills, 0, 33 ) }
Once Every x Rounds

Code:
#include <amxmodx> #define ROUND_INTERVAL  4 new iRound public plugin_init() {     register_plugin( "Do Something Every X Rounds", "1.0", "Wrecked" )         register_logevent( "LogEventRoundStart", 2, "1=Round_Start" ) } public LogEventRoundStart() {     if( ( ++iRound % ROUND_INTERVAL ) == 1 )         // do whatever you need to do here }
Blocking Weapon Pickup
Code:
#include <amxmodx> #include <hamsandwich> public plugin_init() {     register_plugin( "Block Weapon Pickup", "1.0", "Wrecked" )         RegisterHam( Ham_Touch, "weaponbox", "HamTouchPre", 0 )     RegisterHam( Ham_Touch, "armoury_entity", "HamTouchPre", 0 ) } public HamTouchPre( weapon )     return HAM_SUPERCEDE; // blocks function call

Properly Removing Buyzones (by Exolent[jNr])
Code:
#include < amxmodx > #include < engine > #include < fakemeta > new const info_map_parameters[ ] = "info_map_parameters"; new g_hSpawn; public plugin_precache( ) {     new iEntity = create_entity( info_map_parameters );     DispatchKeyValue( iEntity, "buying", "3" );     DispatchSpawn( iEntity );         g_hSpawn = register_forward( FM_Spawn, "FwdSpawn" ); } public FwdSpawn( iEntity ) {     static szClassname[ 32 ];     entity_get_string( iEntity, EV_SZ_classname, szClassname, 31 );         if( equal( szClassname, info_map_parameters ) ) {         remove_entity( iEntity );                 return FMRES_SUPERCEDE;     }         return FMRES_IGNORED; } public plugin_init( ) {     if( g_hSpawn > 0 ) {         unregister_forward( FM_Spawn, g_hSpawn );     } }

Properly Removing an Entity at Plugin Start (by Alucard^)
Code:
#include <amxmodx> #include <fakemeta> new const g_RemoveEntity[] = "classname_here"; public plugin_precache() {     register_plugin("Fine", "and", "you?");         // Remember to do this in plugin_precache, if you     // do this in plugin_init( ) this will not work!         register_forward(FM_Spawn, "HookFmSpawn"); } public HookFmSpawn(iEntity) {     if(!pev_valid(iEntity) )         return FMRES_IGNORED;         static szClassName[32];     pev(iEntity, pev_classname, szClassName, 31);         if(equali(szClassName, g_RemoveEntity) )     {         engfunc(EngFunc_RemoveEntity, iEntity);         return FMRES_SUPERCEDE;     }         return FMRES_IGNORED; }

What is the proper way to respawn someone?
Well, there are two methods that are correct and efficient.
Code:
// GOOD, hamsandwich ExecuteHamB( Ham_CS_RoundRespawn, playerindex ) // GOOD, fakemeta set_pev( playerindex, pev_deadflag, DEAD_RESPAWNABLE ) // BAD, fun // This is usable, but requires a fix that really isn't worth it. spawn( playerindex ) // BAD, cstrike cs_user_spawn( playerindex )

What module should I use for my large plugin? Fakemeta or engine?
You should use whatever module gets the job done. The actual efficiency impact between including either is very trivial. Don't be hesitant to include both if you need both to get what you need done properly.

I've compiled my plugin and the loose indentation warning has come up. What is this and how can I fix it?
This warning shows up whenever you indent your lines with spaces AND tabs. Conform to using one style; I personally use tabs because they're much easier.

How do I dynamically add values into my menu title / items?
Code:
menufunc() {     new info[128]     formatex( info, 127, "Welcome to the Point Shop^nYour Points: %i", iVariableForPoints[id] )     new menu = menu_create( info, "HandlerFunction" )         // rest of menu code }


If you have any issues that you feel people too commonly ask, please post the issue/question in a post or PM and I'll consider adding it to the list. This is the list that I thought up that people commonly ask.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 08-04-2010 at 23:12.
wrecked_ is offline
fezh
Veteran Member
Join Date: Dec 2008
Location: BANNED
Old 06-25-2010 , 17:48   Re: Common Issues and Examples/Solutions
Reply With Quote #2

Little fix to the "Blocking Weapon Pickup" code:
Code:
#include <amxmodx> #include <hamsandwich> public plugin_init() {     register_plugin( "Block Weapon Pickup", "1.0", "Wrecked" )         new classname[20] // weapon_smokegrenade (19) + 1         for( new i = CSW_P228; i <= CSW_P90; i++ )     {         if ( get_weaponname( i, classname, charsmax( classname ) ) )         {             RegisterHam( Ham_Item_Deploy, classname, "HamItemDeployPre", 0 )             /* Other forwards that you could've used:                 * Ham_AddPlayerItem                 * Ham_Item_CanDeploy             */         }     } } public HamItemDeployPre( weapon ) {     return HAM_SUPERCEDE; // blocks function call }
PD: 2 is the shield and you can add another forward: Ham_Touch (passing weaponbox, armoury_entity, and weapon_shield as classnames).
__________________
"There is no knowledge, that is not power"

Last edited by fezh; 06-25-2010 at 17:51.
fezh is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-25-2010 , 17:51   Re: Common Issues and Examples/Solutions
Reply With Quote #3

Quote:
Originally Posted by fezh View Post
Little fix to the "Blocking Weapon Pickup" code:
Code:
#include <amxmodx> #include <hamsandwich> public plugin_init() {     register_plugin( "Block Weapon Pickup", "1.0", "Wrecked" )         new classname[20] // weapon_smokegrenade (19) + 1         for( new i = CSW_P228; i <= CSW_P90; i++ )     {         if ( get_weaponname( i, classname, charsmax( classname ) ) )         {             RegisterHam( Ham_Item_Deploy, classname, "HamItemDeployPre", 0 )             /* Other forwards that you could've used:                 * Ham_AddPlayerItem                 * Ham_Item_CanDeploy             */         }     } } public HamItemDeployPre( weapon ) {     return HAM_SUPERCEDE; // blocks function call }
PD: 2 is the shield and you can add another forward: Ham_Touch
Fixed; thanks.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 06-25-2010 , 18:12   Re: Common Issues and Examples/Solutions
Reply With Quote #4

Nice job! here two things... add it if you like.

How to remove properly the BuyZones in the map:

Code:
#include <amxmodx> #include <fakemeta> public plugin_precache() {     register_plugin("How", "are", "you?");     // If i am not wrong, this must be made in plugin_precache( )         new iEnt;         iEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_map_parameters") );     SetKeyValue(iEnt, "buying", "3", "info_map_parameters");     dllfunc(DLLFunc_KeyValue, iEnt, 0); } SetKeyValue(iEnt, const szKey[], const szValue[], const szClassName[]) {     set_kvd(0, KV_ClassName, szClassName);     set_kvd(0, KV_KeyName, szKey);     set_kvd(0, KV_Value, szValue);     set_kvd(0, KV_fHandled, 0);         dllfunc(DLLFunc_KeyValue, iEnt, 0); }

How to remove properly an entity in the map:

Code:
#include <amxmodx> #include <fakemeta> new const g_RemoveEntity[] = "func_push"; public plugin_precache() {     register_plugin("Fine", "and", "you?");         // Remember to do this in plugin_precache, if you     // do this in plugin_init( ) this will not work!         register_forward(FM_Spawn, "HookFmSpawn", 1); } public HookFmSpawn(iEntity) {     if(!pev_valid(iEntity) )         return FMRES_IGNORED;         new szClassName[32];     pev(iEntity, pev_classname, szClassName, 31);         if(equali(szClassName, g_RemoveEntity) )     {         engfunc(EngFunc_RemoveEntity, iEntity);         return FMRES_SUPERCEDE;     }         return FMRES_IGNORED; }

Sry for my english!
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...

Last edited by Alucard^; 06-25-2010 at 18:16.
Alucard^ is offline
Send a message via Skype™ to Alucard^
fezh
Veteran Member
Join Date: Dec 2008
Location: BANNED
Old 06-25-2010 , 18:28   Re: Common Issues and Examples/Solutions
Reply With Quote #5

@Alucard^: For the first one, this is better: http://forums.alliedmods.net/showpos...1&postcount=12

For the second example I'd preffer using static instead of new since FM_Spawn is called a lot during precache...
Anyway, I think this is a good way to remove more than one entity from the map:
http://forums.alliedmods.net/showpos...38&postcount=8
__________________
"There is no knowledge, that is not power"
fezh is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 06-25-2010 , 18:36   Re: Common Issues and Examples/Solutions
Reply With Quote #6

mMm... interesting things, for the first one, you can explain me why is better? i can't understand... as far as i understand he is doing something like my method but with engine, AND... apart of that he is removing the info_map_parameters entity with the same method as my second example. Why to do the two things when you can remove at all with the first thing?

And also... the pev_valid( ) check is not need it?

And for the second example, cool... i am doing something similar but without tries and without the unregister thing... i will implement this on my surf plugin... thanks!

EDIT: Would be cool if someone can post one example of a good method to do a TIMER for a kz for example... and another example to do a good top15 (specially the sorting thing... i am using the natives of sort.inc but i don't think is a good method, or is a good method?)
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...

Last edited by Alucard^; 06-25-2010 at 18:38.
Alucard^ is offline
Send a message via Skype™ to Alucard^
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-25-2010 , 21:49   Re: Common Issues and Examples/Solutions
Reply With Quote #7

Thank you, Alucard^! I've added your suggestions and examples to the list.

Also, yes I would also like a top15 sorting function. I've had some issues with that in the past and I'd be interested in how it's done. I'd be delighted to add that to the list if anyone posted it here.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Devil259
Veteran Member
Join Date: Dec 2009
Location: France (59)
Old 06-26-2010 , 05:57   Re: Common Issues and Examples/Solutions
Reply With Quote #8

PHP Code:
if( task_existsTASKID ) )
        
remove_taskTASKID 
I don't understand ??
__________________
You can do anything you set your mind to, man.

Devil259 is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-26-2010 , 06:00   Re: Common Issues and Examples/Solutions
Reply With Quote #9

Quote:
Originally Posted by Devil259 View Post
PHP Code:
if( task_existsTASKID ) )
        
remove_taskTASKID 
I don't understand ??
If there is a countdown task at round start, he is removing it so he can start a new countdown task
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Devil259
Veteran Member
Join Date: Dec 2009
Location: France (59)
Old 06-26-2010 , 06:02   Re: Common Issues and Examples/Solutions
Reply With Quote #10

Ok, thank's
__________________
You can do anything you set your mind to, man.

Devil259 is offline
Reply


Thread Tools
Display Modes

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 12:46.


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