Someone Posted January 8, 2013 Share Posted January 8, 2013 (edited) I think it would be better to have the hook player_info adding data to an array or something, than echoing raw HTML. As it is now, your profile stat display is limited to be a 2 column table. http://www.nw-engine.com/wiki/index.php/Player_info.php This also reminds me of DisplayAvatar(); I changed it to take a second argument, so I can have the avatar HTML loaded before displaying. function DisplayAvatar ($user, $return = false) .... if(!$return){ echo "<img src='index.php?p=avatar&display=$uid'>"; } else { return "<img src='index.php?p=avatar&display=$uid'>";; } .... Edited January 8, 2013 by Someone Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 8, 2013 Share Posted January 8, 2013 Well, that need to be thought, my idea was that you could therefore do more by echoing or doing other actions than simply adding values into an array. Quote Link to comment Share on other sites More sharing options...
Someone Posted January 8, 2013 Author Share Posted January 8, 2013 I can appreciate the simplicity, but here is a suggestion for increased usability. modules/view_player/content.php (around line 62) global $profileStats; $profileStats = array(); RunHook("player_info.php", 'profileStats'); foreach($profileStats as $k => $v){ echo '<tr><td><b>'.$profileStats[$k]['statName']."</b></td><td>".$profileStats[$k]['statValue'].'</td></tr>'; } echo "</table>"; modules/avatar/player_info.php Its the only module using the player_info hook, so no worries about compatibility. This requires the change to DisplayAvatar mentioned above. <?php if (file_exists("$baseDir/modules/avatar/images/" . ($_GET["id"] + 0) . ".png")) { $profileStats[] = array( 'statName' => str_replace(" ", " ", Translate("Avatar")), 'statValue' => DisplayAvatar($_GET["id"], true) ); } The array $profileStats will look like: Array ( [0] => Array ( [statName] => Avatar [statValue] => <img src='index.php?p=avatar&display=2&token=194bc652595a0ffc3435092589eb5d65'> ) [1] => Array ( [statName] => Test Stat Name [statValue] => Test Stat Value ) ) Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 8, 2013 Share Posted January 8, 2013 But what would be the advantage? Quote Link to comment Share on other sites More sharing options...
gmoore Posted January 8, 2013 Share Posted January 8, 2013 I am not reading this properly, but I don't get what we need from this. 1331 help me understand! Greg Quote Link to comment Share on other sites More sharing options...
Someone Posted January 8, 2013 Author Share Posted January 8, 2013 (edited) As it is now, if you are to use the hook, you are limited to having a table with 2 columns to display the data. This way you can choose how to present the data however you like. Be it a 4 column table or no table at all. Its up to each game owner how to present the data in their player profile page. EDIT: My point is, I dont think anyone , ever, will use the hook player_stats as it is now in a game. ANd if it is to be changed, its best to have it done before modules rely on the format of the hook. Does this look good? [ATTACH=CONFIG]843[/ATTACH] Edited January 8, 2013 by Someone Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 9, 2013 Share Posted January 9, 2013 Here I have to agree, if you're expecting other modules to use the hook, it should return just the data. That allows other modules to use the data, without having to live with having some table tags, that may or may not even be within a table in a different module. (Only applies to player_info: But on another note, if I didn't want the the table markup and just an populated img tag, I'd just use the displayAvatar function and bypass the 'hook'.) Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 9, 2013 Share Posted January 9, 2013 I see, so your concern is that if for example somebody use a 4 column design the hooks will fails and present a 2 column design. Now I starts to understand. I will look into it. Quote Link to comment Share on other sites More sharing options...
Someone Posted January 9, 2013 Author Share Posted January 9, 2013 (edited) Djkanna explained it very well. And yes, as for just displaying the avatar I would not use the hook. Its the only module that comes with NWE that uses the hook, so changed the sample file to make it faster for Alain to look into. When speaking of avatars, perhaps there should be away to get the avatar url only, without the image HTML tag. Added to modules/avatar/lib.php function GetAvatarUrl ($user) { global $baseDir; $uid = FindUser($user); if ($uid == null) return; if (file_exists("$baseDir/modules/avatar/images/$user.png")){ return "index.php?p=avatar&display=$uid"; } else { return null; } } Why? What if you want a class/id added to the avatar image Or want width/height in the attributes. I know that I am not dependent on having this in that file, I can add it myself through another module lib or a number of other ways. But I see a potential where several module makers have their own version of that function included for that purpose. Edited January 9, 2013 by Someone forgot to return null if no avatar found Quote Link to comment Share on other sites More sharing options...
Djkanna Posted January 10, 2013 Share Posted January 10, 2013 (edited) Djkanna explained it very well. And yes, as for just displaying the avatar I would not use the hook. Its the only module that comes with NWE that uses the hook, so changed the sample file to make it faster for Alain to look into. When speaking of avatars, perhaps there should be away to get the avatar url only, without the image HTML tag. Added to modules/avatar/lib.php function GetAvatarUrl ($user) { global $baseDir; $uid = FindUser($user); if ($uid == null) return; if (file_exists("$baseDir/modules/avatar/images/$user.png")){ return "index.php?p=avatar&display=$uid"; } else { return null; } } Why? What if you want a class/id added to the avatar image Or want width/height in the attributes. I know that I am not dependent on having this in that file, I can add it myself through another module lib or a number of other ways. But I see a potential where several module makers have their own version of that function included for that purpose. I also agree with this, this is what I would call more of a hook, as a module developer, getting markup and data back isn't always what you want, so as an engine, I think it should only provide the data, and let the module using the data itself determine the markup. -2cents. edit: Unless of course, the data required was expected to return markup too, for example DisplayAvatarImg() one would expect to get a populated img tag in return. Could simplify it a little. function GetAvatarUrl ( $user ) { global $baseDir; $uid = FindUser ( $user ); if ( $uid != null && file_exists ( "$baseDir/modules/avatar/images/$user.png" ) ) return "index.php?p=avatar&display=$uid"; return; } Edited January 10, 2013 by Djkanna Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 10, 2013 Share Posted January 10, 2013 Should be done, more or less as you wanted it. Update the 2 modules and check it out. Comments welcome. Quote Link to comment Share on other sites More sharing options...
Someone Posted January 10, 2013 Author Share Posted January 10, 2013 function GetAvatarUrl ( $user ) { global $baseDir; $uid = FindUser ( $user ); if ( $uid != null && file_exists ( "$baseDir/modules/avatar/images/$user.png" ) ) return "index.php?p=avatar&display=$uid"; return; } Yup I am happy with the changes. Only missing the function I quoted above... Quote Link to comment Share on other sites More sharing options...
gmoore Posted January 10, 2013 Share Posted January 10, 2013 And did not affect my minimal NWE ... awesome lol (wiping head ... no work to do there) Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 11, 2013 Share Posted January 11, 2013 Added the GetAvatarUrl 1 Quote Link to comment Share on other sites More sharing options...
Someone Posted January 11, 2013 Author Share Posted January 11, 2013 Much appreciated Ill name an NPC after you :) Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 11, 2013 Share Posted January 11, 2013 The use the nick: garg ;-) Quote Link to comment Share on other sites More sharing options...
gmoore Posted January 11, 2013 Share Posted January 11, 2013 I was considering Garg Bertrand. Or you can use it. The guy in the black cloak in that dark alley over there. Greg Quote Link to comment Share on other sites More sharing options...
Someone Posted January 12, 2013 Author Share Posted January 12, 2013 Ooooops Error: Invalid argument supplied for foreach() Error in F:/xampp/htdocs/nwe/modules/view_player/content.php Line 69 Error in F:\xampp\htdocs\nwe\libs\common.php Line 554 Error in F:\xampp\htdocs\nwe\index.php Line 321 I think it breaks if the player profile being viewed does not have an avatar. My admin profile works, btw its showing a nerd again since I updated the module :p (big deal, people should not update directly to live games anyways) Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted January 12, 2013 Share Posted January 12, 2013 Indeed. Thanks for the report. Update the view_player module and it should be up and running. And removed my pict from the avatar. Sorry was to test that this was working and forget it there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.