Index out of bounds
I would like to know why the following code is out of bounds.
Code:
public fw_TakeDamage(victim, inflictor, attacker, Float:damage) {Also I've read something of returning the HAM function, however there is no return value. How is it possible to get this? Code:
if (!is_user_connected(victim) || !is_user_connected(attacker)) return HAM_IGNOREDThanks in advance. |
Re: Index out of bounds
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? |
Re: Index out of bounds
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:
PHP Code:
|
Re: Index out of bounds
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.
|
Re: Index out of bounds
Quote:
To initialize it I got the following in client_connect: Code:
player_power[id] = 0Quote:
Quote:
Code:
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage") |
Re: Index out of bounds
Yes, just check if the attacker is a player entity (if his index is between 0 and your maxplayers).
What you showed is not how you initialize the array, show me the line with new in front of it. |
Re: Index out of bounds
Oh. In that case this is my init: new player_power[33]
|
Re: Index out of bounds
What line are you getting the error on exactly? With your current code
|
Re: Index out of bounds
The actual errors are gone for now, however I would still like to get some information about the "pre" part that Fr33m@n was talking about. Is there a link where I can read about this?
|
Re: Index out of bounds
In every Ham hook you can specify if it's a pre or post hook (the last argument in RegisterHam).
If it's a pre hook, it happens before the action happens so you can use the return values to block the action, you also have an arsenal of natives to use such as SetHamParamInt/Float/... However in post hook the action has already happened and there's nothing you can do about it. It's good to hook post if you for example want to check the DEFINITE damage in TakeDamage. If you hooked it as a pre, there's a chance another plugin might still change the value. |
| All times are GMT -4. The time now is 09:40. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.