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

Common Issues and Examples/Solutions


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 05:23.


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