| callimuc |
09-19-2012 09:44 PM |
Quote:
Posted by Johnaudi
(Post 201045)
Alright, so today I asked snk how do player.onHP() work... I got the major idea about it, I am still wondering of: how do they set the params about it? Let's say player.onHP(-50); would they have something like if (params[0] == "-50") or is there another way?
|
you should keep custom commands from iEra intern. anyway, lets say you have something like
than you could remove the damage (depending on the system you use) like this
PHP Code:
public function onDoDamage(dmg) {
if (clientr.health_cur == 0) return;
temp.damage = max(dmg, 0); //use max() to avoid positive damage (healing)
if (clientr.health_cur - damage > 0) clientr.health_cur -= damage;
else if (clientr.health_cur - dmg >= 0) {
clientr.health_cur = 0;
onRevivePlayer();
}
}
function onRevivePlayer() {
//add a revive gani or whatever you want to have
clientr.health = clientr.health_max;
}
and to add damage you would simply use such a function
PHP Code:
public function onAddDamage(dmg) {
if (clientr.health_cur == clientr.health_max) return;
clientr.health_cur = min(clientr.health_max, clientr.health_cur+dmg); //use min() to avoid negative damage
}
you can also change it so you can add and remove damage within one function. that could look like
PHP Code:
onDamage(somedamagehere);
function onDamage(dmg) {
clientr.health_cur -= dmg;
/*
in case you are not that familiar with maths:
if the dmg is positive, its adding the damage (hurt) with the -
but if the damage is negative, its returning in the "negative and negative = positive" rule in maths
*/
if (clientr.health_cur > clientr.health_max) clientr.health_cur = clientr.health_max;
else if (clientr.health_cur =< 0) onRevivePlayer();
}
function onRevivePlayer() {
//add some stuff like a revive gani or whatever you want to have
clientr.health_cur = clientr.health_max;
}
this is pretty barebone. you would be on your best way by joining the player to a class so you can call the functions with player.yourFunction() rather than with triggering the server or any other stuff.
|