PDA

View Full Version : Gani Solutions!


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.

Chompy
02-23-2007, 07:38 PM
hmm, would this work if the player.attr[21] were the same?
I need some help with my flaot text and I gotta test this method :D

xXziroXx
02-23-2007, 07:39 PM
hmm, would this work if the player.attr[21] were the same?
I need some help with my flaot text and I gotta test this method :]

Yes, it would.

Chandler
02-23-2007, 08:06 PM
I was about to make a thread about making player.attr support arrays!
I suppose this will do though, thank you! :)

xXziroXx
07-20-2007, 08:07 AM
ADD: I ran into this problem again, and I think that I should tell everyone what the REALLY IMPORTANT part is that WILL make it function properly.


Example 1 (non working):


player.attr[21] = @{ "foo", "bar" };
player.attr[22] = "yourganiname.gani";


SCRIPT
function onPlayerEnters() setTimer(.05);

function onTimeOut()
{
player.chat = "[" @ player.attr[21][0] @ "]";
setTimer(.05);
}
SCRIPTEND


This will set your chat to: [foo]

However, if you try to change player.attr[21] to something else (atleast serversided, didnt try to do it on clientside) - your chat will not update. I guess this is because attr is not supposed to be used as an array, but, it WILL work if you tokenize the attr array.


Example 2 (working):


player.attr[21] = @{ "foo2", "bar2" };


SCRIPT
function onPlayerEnters() setTimer(.05);

function onTimeOut()
{
player.chat = "[" @ player.attr[21].tokenize()[0] @ "]";
setTimer(.05);
}
SCRIPTEND



I hope this will be of more help. :)

PrinceOfKenshin
07-20-2007, 08:26 AM
very nice can you explain to me how to make a gani script im not good at it