Raised This Month: $ Target: $400
 0% 

Dynamic Array help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 03-31-2009 , 23:22   Re: Dynamic Array help
Reply With Quote #9

Using dynamic arrays for this would be kinda unefficient:
Quote:
Originally Posted by cellarray.inc
/**
* These arrays are intended to be used for a form of global storage without
* requiring a #define that needs to be increased each time a person needs more
* storage.
* These are not designed to be used as a replacement for normal arrays, as
* normal arrays are faster and should be used whenever possible.
*/
If you don't care about it though, try this:
Code:
#include <amxmodx> #include <hamsandwich> #define MAX_PLAYERS 32 new Array:gEntityIndex[MAX_PLAYERS + 1] // Attacked entity's index new Array:gDamageDone[MAX_PLAYERS + 1] // Damage done to attacked entity public plugin_init() {     // Replace "player" with your entity's classname     RegisterHam( Ham_TakeDamage, "player", "Event_MonsterTakeDamage" )         // Create arrays for each player     for ( new player = 1; player <= get_maxplayers(); player++ )     {         gEntityIndex[player] = ArrayCreate( 1, 1 )         gDamageDone[player] = ArrayCreate( 1, 1 )     } } public Event_MonsterTakeDamage( idEnt, idInflictor, idAttacker, Float:damage, damageBits ) {     new Float:totaldamage     new index = -1     new size = ArraySize( gEntityIndex[idAttacker] )         // Check whether entity's data already exists on attacker's array     for ( new i = 0; i < size; i++ )         if ( idEnt == ArrayGetCell( gEntityIndex[idAttacker], i ) )             index = i;         // If index is still -1 at this point, there's no data for this entity yet     if ( index == -1 )     {         // Allocate new data         ArrayPushCell( gEntityIndex[idAttacker], idEnt )         ArrayPushCell( gDamageDone[idAttacker], damage )                 // Set index and totaldamage for following checks         index = size;         totaldamage = damage;     }     else     {         // Modify existent data         new Float:olddamage = ArrayGetCell( gDamageDone[idAttacker], index )         ArraySetCell( gDamageDone[idAttacker], index, olddamage + damage)                 // Set totaldamage for following checks         totaldamage = olddamage + damage;     }         //server_print("DEBUG: idEnt %d idAttacker %d arrayindex %d totaldmg %f", idEnt, idAttacker, index, totaldamage)         // Print message to player when entity's damage reaches 500.0     if (totaldamage >= 500.0)     {         client_print(idAttacker, print_center, "OMG! You've done a total of 500 dmg to ent %d!", idEnt)                 // Reset damage data         ArraySetCell( gDamageDone[idAttacker], index, 0.0)                 // Use this instead if you want the data to be erased (to save memory)         //ArrayDeleteItem( gEntityIndex[idAttacker], index )         //ArrayDeleteItem( gDamageDone[idAttacker], index )     } }
Attached Files
File Type: sma Get Plugin or Get Source (dnyamicentdamage.sma - 505 views - 2.1 KB)
__________________
MeRcyLeZZ 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 09:00.


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