Author Topic: Battle avatars  (Read 13848 times)

Alchemion

  • Guest
Battle avatars
« on: September 09, 2008, 09:38:33 am »
Hi,

I am trying to show user avatar in battles, so that it would work with addmonster pics module (showing pictures of opponents in battle) and i have tried to modify the avatar core module as updated by Nightborn...

This is the not working hook to battle i've inserted into the module, as not so brightly copy/pasted from within the module :

Code: [Select]
case "battle":
if (get_module_pref("avatar","avatar",$user)!='' && $bio)  {
if (get_module_pref("validated","avatar",$user)) {
$image="<img align='left' src='".get_module_pref("avatar","avatar",$user)."' ";
if (get_module_setting("restrictsize")) {
//stripped lines from Anpera's avatar module =)
$maxwidth = get_module_setting("maxwidth");
$maxheight = get_module_setting("maxheight");
$pic_size = @getimagesize(get_module_pref("avatar","avatar",$user)); // GD2 required here - else size always is recognized as 0
$pic_width = $pic_size[0];
$pic_height = $pic_size[1];
if ($pic_width > $maxwidth) $image.=" width=\"$maxwidth\" ";
if ($pic_height > $maxheight) $image.=" height=\"$maxheight\" ";
}
$image.=">";
} else {
$image=translate_inline("Avatar not validated yet");
}
}
break;

Please, lend a helping hand here for extending a good game functionality :) what is wrong with the code ?

extremely appreciated.

Thank you.



« Last Edit: September 09, 2008, 09:41:18 am by Alchemion »

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #1 on: September 09, 2008, 09:55:35 am »
erm, show his avatar where?

in every forest fight? Oo ouch.
Another everyhit module ... and the avatar module is quite bulky.

@your code

You should realize you NEVER give out the output ... $image is most likely properly set, but you never rawoutput() it ;)
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #2 on: September 09, 2008, 12:49:26 pm »
i played last night with the copy/paste... quite tired... hope to succeed this evening...

@Nightborn
Quote
erm, show his avatar where?

in every forest fight? Oo ouch.
Another everyhit module ... and the avatar module is quite bulky.

you forget one thing (if not known by now...) : I use forest , graveyard and pvp resting time out, in my game scenario (with the modules I have linked in this forum..)... so, I won't crowd the server too much with forest fighting presence...

on other hand, the pictures get cached so there will be no problem with reloading it once in a while...

on another hand, if the avatar module is quite bulky, i haven't dared nor wanted to ask you to realease here your own modifications that swifts the avatar module or the code YOU use for your servers to show pictures... I only asked for hints and snippets so I try to work myself on the idea, not take some work for granted...

yet, if you wish to release here and show grace, you may attach the modifications made for using images everywhere ... just a thought...

Code: [Select]
You should realize you NEVER give out the output ... $image is most likely properly set, but you never rawoutput() it
thanks for the hint.... as always, your hints always made sense and helped out...
stand by...
« Last Edit: September 09, 2008, 01:13:56 pm by Alchemion »

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #3 on: September 09, 2008, 02:39:39 pm »
Quote
you forget one thing (if not known by now...) : I use forest , graveyard and pvp resting time out, in my game scenario (with the modules I have linked in this forum..)... so, I won't crowd the server too much with forest fighting presence...
Well, IF people agree to it, that is.
The issue is: I would not like having to stay 30 minutes on a server to get through with my turns - if later people have 200 fights to do (with flawless ones) it's a PITA.

But anyway: okay, it should limit the stress.

Quote
on other hand, the pictures get cached so there will be no problem with reloading it once in a while...
The avatar module gets queried and called each pagehit, this is what I referred to.
The images itself are browser cached - sure, but the filename and location comes out of the database - asked each pagehit.
Sure, cached too, but one more module to ask. Multiply this by online players.

However, see previous, if you limit fights - ok.

Quote
on another hand, if the avatar module is quite bulky, i haven't dared nor wanted to ask you to realease here your own modifications that swifts the avatar module or the code YOU use for your servers to show pictures... I only asked for hints and snippets so I try to work myself on the idea, not take some work for granted...

I have further developed the avatar module, but it's still bulky. And will stay bulky, because picture management with validation stuff is a mess.

A few months ago I cleaned it up, I'll upload my current version to lotgd-downloads.com soon.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #4 on: September 10, 2008, 03:23:47 pm »
Nightborn, I have added the rawoutput($image) and other rawoutput code for image that i have found inside the avatar module, i have even copied and pasted integral code that shows the avatar image in the bioinfo page, I have set all conditions to yes so that they are met in full.......

yet, the avatar image didn't appear in battle....

please, provide a code to place in a specific hook... so that the sought effect is obtained...avatar vs monsterpic in battle ...

when you have the time....

I will keep trying testing different alternatives... but, at the moment, i cannot see the light at the end of the tunnel...

thank you very much.



Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #5 on: September 10, 2008, 06:30:21 pm »
First, you show the code.

Now, you don't say where you changed what.

I don't fish in Mist, sorry.

You should, given the time, be able to solve this one, it's pretty easy and you need to figure some things out to learn.
I have given you a great deal of information ;)
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #6 on: September 10, 2008, 09:18:07 pm »
you don't believe by words.... :) ... i am just ashamed to show the code... yet I have given a lot of tries... do you want me to copy/paste de bioinfo or biotop hook cases code, to give you the code i have used ?

Code: [Select]
if (!get_module_setting("navdisplay")&& !get_module_setting("bioheaddisplay"))
if (get_module_pref("user_seeavatar") &&
get_module_pref("bought", "avatar", $args['acctid']) && get_module_pref("user_seeotheravatars")) {
$set = get_module_pref("setname", "avatar", $args['acctid']);
$race = strtolower($args['race']);
if ($args['sex'] == SEX_MALE) {
$gender = "male";
} else {
$gender = "female";
}
$image = avatar_getimage($race, $gender, $set,true,$args['acctid']);
rawoutput("<table><tr><td valign='top'>");
output("`^Avatar:`0`n");
rawoutput("</td><td valign='top'>$image</td></tr></table>");
//rawoutput($image);

i have all conditions set ok and fullfilled.... the avatar shows only in bio.... i hooked the upper code in case "battle"...

i will keep givin it more tries... but, as told, at the moment, the code don't work for battle avatars... busy day... i'll get back...

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #7 on: September 11, 2008, 06:15:02 am »
I ask for the code for a purpose - you could have added it where it was not executed - then we'd run searching for phantom errors around the house, never getting into it.


Code: [Select]
if (!get_module_setting("navdisplay")&& !get_module_setting("bioheaddisplay"))
if (get_module_pref("user_seeavatar") &&
get_module_pref("bought", "avatar", $args['acctid']) && get_module_pref("user_seeotheravatars")) {
remove that line, you obviously have no nav here.
don't forget to remove the closing bracket, too.

note, that you need to change all $args['acctid'] to $session['user']

because in the case "battle", $args holds the enemies, and $args['acctid'] has no value...
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #8 on: September 12, 2008, 12:19:07 am »
I have updated and tested the code :

Code: [Select]
case "battle":
if (get_module_pref("validated")==1 && get_module_pref("user_seeavatar")==1) {
$image="<img align='left' src='".get_module_pref("avatar")."' ";
if (get_module_setting("restrictsize")==1) {
//stripped lines from Anpera's avatar module =)
$maxwidth = get_module_setting("maxwidth");
$maxheight = get_module_setting("maxheight");
$pic_size = @getimagesize(get_module_pref("avatar","avatar",$user)); // GD2 required here - else size always is recognized as 0
$pic_width = $pic_size[0];
$pic_height = $pic_size[1];
if ($pic_width > $maxwidth) $image.=" width=\"$maxwidth\" ";
if ($pic_height > $maxheight) $image.=" height=\"$maxheight\" ";
}
$image.=">";
} else {
$image=translate_inline("Avatar not validated yet");
}
rawoutput("<table><tr><td valign='top'>");
rawoutput("</td><td valign='left'>$image</td></tr></table>");
break;

It now SHOWS the player's avatar, but the image does not restrict according to the settings...
Why does not restrict ?...

thank you very much for helping out...
« Last Edit: September 12, 2008, 12:23:09 am by Alchemion »

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #9 on: September 12, 2008, 05:54:32 am »
Code: [Select]
function avatar_getimage($race, $gender, $set,$bio=false,$user=0) {
        $usedefault = 0;
        $file = "modules/avatar/$set/$race-$gender.gif";
        if (!file_exists($file)) {
                $usedefault = 1;
                $file = "modules/avatar/default.gif";
        }
        if (get_module_pref("avatar","avatar",$user)!='' && $bio)  {
                if (get_module_pref("validated","avatar",$user)) {
                        $picname=str_replace(" ","",get_module_pref("avatar","avatar",$user));
                        $image="<img align='left' src='".$picname."' ";
                        if (get_module_setting("restrictsize")) {
                                //stripped lines from Anpera's avatar module =)
                                $maxwidth = get_module_setting("maxwidth");
                                $maxheight = get_module_setting("maxheight");
                                $pic_size = @getimagesize($picname); // GD2 required here - else size always is recognized as 0
                                $pic_width = $pic_size[0];
                                $pic_height = $pic_size[1];
                                //other arguments are channels,bits etc

                                //aspect ratio. We are scaling for height/width ratio
                                $resizedwidth=$pic_width;
                                $resizedheight=$pic_height;
                                if ($pic_height > $maxheight) {
                                        $resizedheight=$maxheight;
                                        $resizedwidth=round($pic_width*($maxheight
/$pic_height));
                                }
                                if ($resizedwidth > $maxwidth) {
                                        $resizedheight=round($resizedheight*($maxwidth
/$resizedwidth));
                                        $resizedwidth=$maxwidth;

                                }
                                $image.=" height=\"$resizedheight\"  width=\"$resizedwidth\" ";

                        }
                        $image.=">";
                } else {
                        $image=translate_inline("Avatar not validated yet");
                }
        } else {
                $l = translate_inline("Licensed for use in LoTGD");
                $image = "<center><img align='center' src='$file'>$l</img>";
                if (!$usedefault) {
                        require("modules/avatar/$set/setinfo.php");
                        $image .= "<br><center>$setcopy<br>$l</center>";
                }
        }
        return $image;
}


check modules/avatar/func.php if the function above is the same - I remember fixing a size issue about 3 month ago.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #10 on: September 12, 2008, 02:27:47 pm »
Indeed the function was not the same inside the avatar.php module file... i don\t have but only one file for this module...

I have replaced the function as you have indicated, within the avatar.php module file...

Also, I have modified the battle hook :

Code: [Select]
case "battle":
if (get_module_pref("validated")==1 && get_module_pref("user_seeavatar")==1) {
$image="<img align='left' src='".get_module_pref("avatar")."' ";
if (get_module_setting("restrictsize")==1) {
                                $maxwidth = get_module_setting("maxwidth");
                                $maxheight = get_module_setting("maxheight");
                                $pic_size = @getimagesize($picname);
                                $pic_width = $pic_size[0];
                                $pic_height = $pic_size[1];
                                $resizedwidth=$pic_width;
                                $resizedheight=$pic_height;
                                if ($pic_height > $maxheight) {
                                        $resizedheight=$maxheight;
                                        $resizedwidth=round($pic_width*($maxheight/$pic_height));
                                }
                                if ($resizedwidth > $maxwidth) {
                                        $resizedheight=round($resizedheight*($maxwidth/$resizedwidth));
                                        $resizedwidth=$maxwidth;
                                }
                                $image.=" height=\"$resizedheight\"  width=\"$resizedwidth\" ";
}
                        $image.=">";
} else {
$image=translate_inline("Avatar not validated yet");
}
rawoutput("<table><tr><td valign='top'>");
rawoutput("</td><td valign='left'>$image</td></tr></table>");
break;

But the avatar image won't resize............

Please help.

Thank you very much.
« Last Edit: September 12, 2008, 02:33:32 pm by Alchemion »

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #11 on: September 12, 2008, 02:55:18 pm »
try debugging.

debug($image);

on a location where the image is ready - and you should see the code. Alternatively here you see it in your browser, too.

if it does not work - you have a PHP that cannot handle image resizes would be my wild guess.

remove the @ here: " $pic_size = @getimagesize($picname); "
and see if you get a nice error ... if not, debug $pic_size and see if it gets that right.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #12 on: September 14, 2008, 04:55:14 pm »
Quote
if it does not work - you have a PHP that cannot handle image resizes would be my wild guess.

I have activated from game settings the debug output for admin...

I didn\t  mention, but the avatar gets resized in the bio.php page ... so the php handling resize is not an issue...

I have merged the addmonsterpic.php and avatar.php (into the avatar) module... i have managed to show both creature and avatar pictures... but is a mess... the avatar still doesn't resize...


Code: [Select]
case "battle":
if (get_module_pref("validated")==1 && get_module_pref("user_seeavatar")==1) {
$image="<img align='left' src='".get_module_pref("avatar")."' ";
if (get_module_setting("restrictsize")==1) {
                                $maxwidth = get_module_setting("maxwidth");
                                $maxheight = get_module_setting("maxheight");
                                $pic_size = @getimagesize($picname);
                                $pic_width = $pic_size[0];
                                $pic_height = $pic_size[1];
                                $resizedwidth=$pic_width;
                                $resizedheight=$pic_height;
                                if ($pic_height > $maxheight) {
                                        $resizedheight=$maxheight;
                                        $resizedwidth=round($pic_width*($maxheight/$pic_height));
                                }
                                if ($resizedwidth > $maxwidth) {
                                        $resizedheight=round($resizedheight*($maxwidth/$resizedwidth));
                                        $resizedwidth=$maxwidth;
                                }
                                $image.=" height=\"$resizedheight\"  width=\"$resizedwidth\" ";
}
                        $image.=">";
} else {
$image=translate_inline("Avatar not validated yet");
}
//rawoutput("<table><tr><td valign='top'>");
//rawoutput("</td><td valign='right'>$image</td></tr>");

$pics='';
foreach ($args as $creature) {
if ($creature['image']!='') {
$name=$creature['image'];
$pic=true;
} else {
$name="modules/addmonsterpics/".$creature['creaturename']." Lv".$creature['creaturelevel'].".jpg";
$pic=file_exists($name);

}

if ($pic==true) $pics.="<IMG SRC=\"$name\" ALT='$name'>";
}
//output_notl("`c".$pics."`c`n`n",true);
//rawoutput("<tr><td valign='left'>$pics</td></tr></table>");


rawoutput("<table border='2'><tr align='center' valign='top><td height='100'>$image</td><td valign='middle'>vs.</td><td height='100'>$pics</td></tr></table>");

break;

... the touareg would be my avatar, the other image would be a sample for the creature...

I have tried to put the images in a table, in a single row, but i don't know why the images get one under another and still do not get resized or constraint to the cell limits (100 pixels)...

please help.

thank you very much.

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 318
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Battle avatars
« Reply #13 on: September 14, 2008, 10:30:00 pm »
If something does not work, usually the worst thing to do is "merge" other stuff in beyond recognition...

Reverse all your stuff back to the original file you mentioned last post, then DEBUG (!) and check where the problem is.

If you put output() stuff in there, all will be non-floating... what floating is, see a CSS reference...
Block objects take a full line if not put in a table or formatted properly.

Think about the code and the variables - DEBUG it, you need to know how to do that... use debug() to display variable values.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Battle avatars
« Reply #14 on: September 15, 2008, 09:25:40 am »
I have (re)added the debug image code... that's all the debug message that is shown....

Please note that I have also activated the debug output and php notices output and all other superuser staff for the admin...

I have eventually managed to align images in a row, also vertically....

I have no problem with the monsterpics resizing, cause that's the admin issue to post only fitting pics... the avatar image though is a problem when players get their personal urls to larger pictures like the one shown below... the avatar picture cannot be let as it is...

this is what i got so far:

Code: [Select]
case "battle":

debug($image);
debug($pics);
if (get_module_pref("validated")==1 && get_module_pref("user_seeavatar")==1) {
$image="<img align='left' src='".get_module_pref("avatar")."' ";
if (get_module_setting("restrictsize")==1) {
                                $maxwidth = get_module_setting("maxwidth");
                                $maxheight = get_module_setting("maxheight");
                                $pic_size = @getimagesize($picname);
                                $pic_width = $pic_size[0];
                                $pic_height = $pic_size[1];
                                $resizedwidth=$pic_width;
                                $resizedheight=$pic_height;
                                if ($pic_height > $maxheight) {
                                        $resizedheight=$maxheight;
                                        $resizedwidth=round($pic_width*($maxheight/$pic_height));
                                }
                                if ($resizedwidth > $maxwidth) {
                                        $resizedheight=round($resizedheight*($maxwidth/$resizedwidth));
                                        $resizedwidth=$maxwidth;
                                }
                                $image.=" height=\"$resizedheight\"  width=\"$resizedwidth\" ";
}
                        $image.=">";
} else {
$image=translate_inline("Avatar not validated yet");
}
//rawoutput("<table><tr><td valign='top'>");
//rawoutput("</td><td valign='right'>$image</td></tr>");

$pics='';
foreach ($args as $creature) {
if ($creature['image']!='') {
$name=$creature['image'];
$pic=true;
} else {
$name="modules/addmonsterpics/".$creature['creaturename']." Lv".$creature['creaturelevel'].".jpg";
$pic=file_exists($name);

}

if ($pic==true) $pics.="<IMG SRC=\"$name\" ALT='$name'>";
}
//output_notl("`c".$pics."`c`n`n",true);
//rawoutput("<tr><td valign='left'>$pics</td></tr></table>");

//rawoutput("<table border='2'><tr align='center' valign='top><td height='100'>$image</td><td valign='middle'>vs.</td><td height='100'>$pics</td></tr></table>");

rawoutput("
<table width='300' border='1' align='center'>
  <tr align='center'>
    <td width='100' height='100'>$image</td>
    <td>vs.</td>
    <td width='100' height='100'>$pics</td>
  </tr>
</table>
");

break;

The snapshot is attached below.

The merging modules reffer only to the upper battle hook and nothing more... I would have rather had a separate battle-images module that should do the require checks to avatar and addmonster modules... but that's out of my range...

Please help, what do I have to correct within the upper battle hook, so that the player's avatar should be shown resized (I would dare to ask also resizing for the monsterpics, but, as i said, that is not an urgency, as it can be handled manually by the admin)...

Thank you very much.
« Last Edit: September 15, 2008, 09:42:28 am by Alchemion »