xXziroXx
02-23-2007, 07:21 PM
Ive come up to a solution to all the resent gani problems, mainly that a gani is not able to read data from other players. I'll refer to the HUD gani I made on Mythic (most parts of it have been removed though).
This is a non-working example of it:
player.attr[20] = "ml_hud.gani";
function onPlayerEnters() setTimer(.05);
function onTimeOut()
{
if (mousex in |player.x + .5, player.x + 2.5| && mousey in |player.y - 1, player.y + 3|) {
hideimgs(300, 309);
ShowHUD();
for (i = 0; i < 4; i ++) changeimgzoom(300 + i, .7);
}
setTimer(.05);
}
function ShowHUD()
{
showimg(304, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2, player.y - 1.5 - (19/16)/2);
showimg(305, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2 + 6/16, player.y - 1.5 - (19/16)/2 + 4/16);
changeimgpart(304, 0, 0, 37, 13);
changeimgpart(305, 0, 14, 24/(player.fullhearts/player.hearts) + 1, 5);
changeimgvis(305, 3);
}
This example will not work since apparently, player.fullhearts is not readable for other players along with several other things. So with this, you will only be able to see your own health bar.
However, you can easily create an array-like player.attr and store the data in that.
player.attr[20] = "ml_hud.gani";
player.attr[21] = @{player.hearts, player.fullhearts};
function onPlayerEnters() setTimer(.05);
function onTimeOut()
{
if (mousex in |player.x + .5, player.x + 2.5| && mousey in |player.y - 1, player.y + 3|) {
hideimgs(300, 309);
ShowHUD();
for (i = 0; i < 4; i ++) changeimgzoom(300 + i, .7);
}
setTimer(.05);
}
function ShowHUD()
{
showimg(304, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2, player.y - 1.5 - (19/16)/2);
showimg(305, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2 + 6/16, player.y - 1.5 - (19/16)/2 + 4/16);
changeimgpart(304, 0, 0, 37, 13);
changeimgpart(305, 0, 14, 24/(player.attr[21].tokenize()[1]/player.attr[21].tokenize()[0]) + 1, 5);
changeimgvis(305, 3);
}
This example, will work. Not only for the current player, you will be able to see other player's health bars as well. Remember that you have to update player.attr[21] every time that the player's HP changes, possibly in a timeout.
NOTE: Whenever you use onCreated() in a gani, it will only be triggered the FIRST time the gani is shown. If you do onPlayerEnters(), it will be triggered every time you enter a level AND when you update the script of the gani.
This is a non-working example of it:
player.attr[20] = "ml_hud.gani";
function onPlayerEnters() setTimer(.05);
function onTimeOut()
{
if (mousex in |player.x + .5, player.x + 2.5| && mousey in |player.y - 1, player.y + 3|) {
hideimgs(300, 309);
ShowHUD();
for (i = 0; i < 4; i ++) changeimgzoom(300 + i, .7);
}
setTimer(.05);
}
function ShowHUD()
{
showimg(304, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2, player.y - 1.5 - (19/16)/2);
showimg(305, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2 + 6/16, player.y - 1.5 - (19/16)/2 + 4/16);
changeimgpart(304, 0, 0, 37, 13);
changeimgpart(305, 0, 14, 24/(player.fullhearts/player.hearts) + 1, 5);
changeimgvis(305, 3);
}
This example will not work since apparently, player.fullhearts is not readable for other players along with several other things. So with this, you will only be able to see your own health bar.
However, you can easily create an array-like player.attr and store the data in that.
player.attr[20] = "ml_hud.gani";
player.attr[21] = @{player.hearts, player.fullhearts};
function onPlayerEnters() setTimer(.05);
function onTimeOut()
{
if (mousex in |player.x + .5, player.x + 2.5| && mousey in |player.y - 1, player.y + 3|) {
hideimgs(300, 309);
ShowHUD();
for (i = 0; i < 4; i ++) changeimgzoom(300 + i, .7);
}
setTimer(.05);
}
function ShowHUD()
{
showimg(304, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2, player.y - 1.5 - (19/16)/2);
showimg(305, "ml_gui-hphud.png", player.x + 1.5 - getimgwidth("ml_gui-hphud.png")/16/2 + 6/16, player.y - 1.5 - (19/16)/2 + 4/16);
changeimgpart(304, 0, 0, 37, 13);
changeimgpart(305, 0, 14, 24/(player.attr[21].tokenize()[1]/player.attr[21].tokenize()[0]) + 1, 5);
changeimgvis(305, 3);
}
This example, will work. Not only for the current player, you will be able to see other player's health bars as well. Remember that you have to update player.attr[21] every time that the player's HP changes, possibly in a timeout.
NOTE: Whenever you use onCreated() in a gani, it will only be triggered the FIRST time the gani is shown. If you do onPlayerEnters(), it will be triggered every time you enter a level AND when you update the script of the gani.