Raised This Month: $ Target: $400
 0% 

Index out of bounds


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
egbertjan
Senior Member
Join Date: Mar 2007
Location: The Netherlands
Old 05-14-2014 , 06:47   Re: Index out of bounds
Reply With Quote #5

Quote:
Originally Posted by Backstabnoob View Post
No idea why you're checking for is_user_connected and is_user_alive, just check if both players are player entities.

You're probably getting that error because your player_power variable doesn't have enough cells, how do you initialize it?
I read somewhere that this could be a way to check for it, however if a player is already checked upon executing the script then it's kind of useless indeed.

To initialize it I got the following in client_connect:
Code:
player_power[id] = 0
If a player wants to level this up he use a menu to advance this. It's been done the same way with 5 other skills.

Quote:
Originally Posted by Fr33m@n View Post
Return values only matter if you are in Pre, Pre mean forward the takedamage call. In PRE, they allow you to modify some stuff, like blocking the incoming takedamage.

See ham_const.inc

PHP Code:
/**
 * Ham return types.
 * -
 * Return these from hooks to disable calling the target function.
 * Numbers match up with fakemeta's FMRES_* for clarity.  They are interchangable.
 * 0 (or no return) is also interpretted as HAM_IGNORED.
 */
#define HAM_IGNORED        1    /**< Calls target function, returns normal value */
#define HAM_HANDLED        2    /**< Tells the module you did something, still calls target function and returns normal value */
#define HAM_OVERRIDE    3    /**< Still calls the target function, but returns whatever is set with SetHamReturn*() */
#define HAM_SUPERCEDE    4    /**< Block the target call, and use your return value (if applicable) (Set with SetHamReturn*()) */ 
In your case you are in pre, so i think it's better to call it like that :
PHP Code:
public fw_TakeDamage(victiminflictorattackerFloat:damage)
{
    if ( 
is_user_connected(victim) && is_user_connected(attacker) && player_power[attacker] > )
    {
        
//new Float:extradmg = 1.0 + player_power[attacker]*0.01
        // skip useless variable when you can, this is the base of optimisation

        
SetHamParamFloat(4damage * (1.0 player_power[attacker]*0.01))

        return 
HAM_HANDLED
    
}
    return 
HAM_IGNORED

I get the part that you have to be in "pre" to use the return function, however I don't quite understand how to use the pre function and recognize when this is used. Could you explain where I can see where the pre is in the script you provided?

Quote:
Originally Posted by meTaLiCroSS View Post
Assuming that you registered that forward to "player" entities, there's no need to check if victim is a player; it would be always a player.
Yes I've forwarded it to a player entity, so I think it's kind of useless indeed.
Code:
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
egbertjan 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:40.


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