SMOKEY_TEK Posted September 17, 2011 Share Posted September 17, 2011 Does anyone know how I would go about getting players names like below: SMOKEY_TEK I see some games have this feature, and I'm really not sure on how to do it other than making the username in phpmyadmin TEXT and doing it that way. Quote Link to comment Share on other sites More sharing options...
Lithium Posted September 17, 2011 Share Posted September 17, 2011 have fun. http://php.net/manual/en/book.image.php Quote Link to comment Share on other sites More sharing options...
H4x0r666 Posted September 17, 2011 Share Posted September 17, 2011 i've done this a couple months back i think.. i did something with an if check (for example let your script check for.. if this player has name color 100 , 110 , 120, 130 etc (in the database) and if as example is 110 than let him make the names in the script that color... ehm hard to explain with the right codes atm but the idea is good, and just insert an table in your database players info place^^ .. maybe if someone does understand all im saying he could help you further now<.< Quote Link to comment Share on other sites More sharing options...
ShadyCoco Posted September 17, 2011 Share Posted September 17, 2011 str replace... add in DB a cName and varchar default 0 and then in header $_sName = mysql_query("SELECT cName from GRPGusers where id = $_SESSION['id']") if(!$_sName = 0) { //str replace here } that might be the long way but, it would work... Quote Link to comment Share on other sites More sharing options...
SMOKEY_TEK Posted September 18, 2011 Author Share Posted September 18, 2011 I found this site that has something really cool.. I'm gonna try and code that in to work with my game.. lawls.. http://www.cssplay.co.uk/mozilla/splittext.html Quote Link to comment Share on other sites More sharing options...
H4x0r666 Posted September 18, 2011 Share Posted September 18, 2011 okay good luck with that ;) if the splittext isnt working than just use ShadyCoco's answer^^ Quote Link to comment Share on other sites More sharing options...
SMOKEY_TEK Posted September 18, 2011 Author Share Posted September 18, 2011 That's the problem, I don't really understand what their saying, lol.. Quote Link to comment Share on other sites More sharing options...
runthis Posted September 18, 2011 Share Posted September 18, 2011 (edited) Are you trying to this automatically or let the user type in bbcode to do it themselves? if you want to do it automatically, it is a very simple and easy code where you can change the colors up top, or make them database variables and let the user change them. Demo: http://www.pure2012.com/testcolor.php [noparse] <? ## edit these $username="SMOKEY_TEK"; $color1="#FF0000"; $color2="#000000"; ## do not edit this $var="{$username}";$math=strlen($var);$flip=1; $x=0; while($math > 0){ if($flip == 1){ $char=substr("$var",$x,1); $name.="<font color='$color1'>$char</font>"; $flip=2; $math=($math - 1); $x++; $flip=2; }else{ $char=substr("$var",$x,1); $name.="<font color='$color2'>$char</font>"; $math=($math - 1); $x++; $flip=1; } } ## show name (style this) //echo "<b>".$name."</b>"; echo $name; ?> [/noparse] your welcome makeweb world, you should click +1 to my rep on this thread :) Edited September 18, 2011 by runthis Quote Link to comment Share on other sites More sharing options...
runthis Posted September 18, 2011 Share Posted September 18, 2011 for $5 i will make it to where it uses the entire rainbow instead of just 2 colors. -Jesse Quote Link to comment Share on other sites More sharing options...
SMOKEY_TEK Posted September 18, 2011 Author Share Posted September 18, 2011 I really do appreciate this runthis.... Cheers dude... Quote Link to comment Share on other sites More sharing options...
SMOKEY_TEK Posted September 19, 2011 Author Share Posted September 19, 2011 (edited) Would you be able to add this to my classes for me? I am trying, but not so successful, lol Please let me know! I can get it to work if I put it in it's own file, but can't figure this out.. So frustrating.. Edited September 19, 2011 by SMOKEY_TEK Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 19, 2011 Share Posted September 19, 2011 http://www.phpro.org/examples/Rainbow-Text.html Quote Link to comment Share on other sites More sharing options...
Djkanna Posted September 19, 2011 Share Posted September 19, 2011 (edited) Are you trying to this automatically or let the user type in bbcode to do it themselves? if you want to do it automatically, it is a very simple and easy code where you can change the colors up top, or make them database variables and let the user change them. Demo: http://www.pure2012.com/testcolor.php [noparse] <? ## edit these $username="SMOKEY_TEK"; $color1="#FF0000"; $color2="#000000"; ## do not edit this $var="{$username}";$math=strlen($var);$flip=1; $x=0; while($math > 0){ if($flip == 1){ $char=substr("$var",$x,1); $name.="<font color='$color1'>$char</font>"; $flip=2; $math=($math - 1); $x++; $flip=2; }else{ $char=substr("$var",$x,1); $name.="<font color='$color2'>$char</font>"; $math=($math - 1); $x++; $flip=1; } } ## show name (style this) //echo "<b>".$name."</b>"; echo $name; ?> [/noparse] your welcome makeweb world, you should click +1 to my rep on this thread :) Over-complicated... <?php $username="SMOKEY_TEK"; $colours = array ( 'even' => '#FF0000', 'odd' => '#000' ); $length = strlen($username); $newName = ''; for ($i = 0; $i < $length; $i++) { $state = (($i+1) % 2 == 0) ? 'even' : 'odd'; $newName .= '<span style="color: '.$colours[$state].'">'.$username[$i].'</span>'; } echo $newName; Would be a simpler method, also much easier to read. Or the link RulerOfZu posted. Or even http://blog.kungf.eu/wp-content/uploads/gradient.class.phps, may be a more suitable option, if you're using it for multiple members. Edited September 19, 2011 by Djkanna Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 19, 2011 Share Posted September 19, 2011 Much better code Djk :D nice link too ;) Quote Link to comment Share on other sites More sharing options...
SMOKEY_TEK Posted September 19, 2011 Author Share Posted September 19, 2011 Over-complicated... <?php $username="SMOKEY_TEK"; $colours = array ( 'even' => '#FF0000', 'odd' => '#000' ); $length = strlen($username); $newName = ''; for ($i = 0; $i < $length; $i++) { $state = (($i+1) % 2 == 0) ? 'even' : 'odd'; $newName .= '<span style="color: '.$colours[$state].'">'.$username[$i].'</span>'; } echo $newName; Would be a simpler method, also much easier to read. I get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/hitmanm1/public_html/spicedup.php on line 6 Line 6 follows: $colours = array ( Quote Link to comment Share on other sites More sharing options...
SMOKEY_TEK Posted September 19, 2011 Author Share Posted September 19, 2011 I got runthis's code to work in my class file now. So again I want to thank each one that helped me accomplish this. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 19, 2011 Share Posted September 19, 2011 I get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/hitmanm1/public_html/spicedup.php on line 6 Line 6 follows: $colours = array ( Nope the code is just fine that is something else wrong with your page. Quote Link to comment Share on other sites More sharing options...
runthis Posted September 19, 2011 Share Posted September 19, 2011 no need to fix what aint broken or will break. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 19, 2011 Share Posted September 19, 2011 Like all coding it can be streamlined and optimized which is what DJK did here. If you cannot accept this maybe you should be doing something else. Quote Link to comment Share on other sites More sharing options...
grant Posted September 20, 2011 Share Posted September 20, 2011 Over-complicated... <?php $username="SMOKEY_TEK"; $colours = array ( 'even' => '#FF0000', 'odd' => '#000' ); $length = strlen($username); $newName = ''; for ($i = 0; $i < $length; $i++) { $state = (($i+1) % 2 == 0) ? 'even' : 'odd'; $newName .= '<span style="color: '.$colours[$state].'">'.$username[$i].'</span>'; } echo $newName; Would be a simpler method, also much easier to read. Or the link RulerOfZu posted. Or even http://blog.kungf.eu/wp-content/uploads/gradient.class.phps, may be a more suitable option, if you're using it for multiple members. Djkanna your the man coded it in my game less than one hour with that code thanks for the post users are happy with the new names Quote Link to comment Share on other sites More sharing options...
runthis Posted September 23, 2011 Share Posted September 23, 2011 (edited) Like all coding it can be streamlined and optimized which is what DJK did here. If you cannot accept this maybe you should be doing something else. says the guy whose main coding expertise (at least what you are advertising) is mccodes. Would be a simpler method, also much easier to read. Why would he need to read it easier, hes plugging into a functions page and never looking at it again except maybe to change the colors. Also, take a closer look, mine is alot easier to read, all you need to know is the name, and colors. Or even http://blog.kungf.eu/wp-content/uploads/gradient.class.phps, may be a more suitable option, if you're using it for multiple members. Both of our scripts would work fine for multiple members. "The while loop 90% of the time is indeed slightly faster (than the for loop)" according to phpbench.com The point is, both scripts work and work at milliseconds away from each other. So whats the big deal. In my own benchmark test against both of our scripts and 1000 users, we were equally as fast 95% of the time and my script doesn't have to use any inline styling, standard html guaranteed to work any and everywhere in any browser/os. Edited September 23, 2011 by runthis Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 23, 2011 Share Posted September 23, 2011 Ive been coding a long time in php, asp, asp.net and have produced custom code and modifications for ecommerce software and if your referring to rulerofzu.com its been developed much further than mccodes which you would expect from a successful game. Those with limited foresight see mccodes as a run of the mill limited base engine. If you take that engine with a goal in mind rewrite and develop further then you have something completely different. I only advertise zu in my sig here as its a game community and I dont need to advertise my other work or projects here as I am not desperate to prove anything. Quote Link to comment Share on other sites More sharing options...
runthis Posted September 23, 2011 Share Posted September 23, 2011 (edited) we could further improve the script by taking out the inline style and adding the colors to the linked stylesheet with a class. We could also shorten all the variables too. Also by removing $newName = ''; not needed to dot-add in php <?php $u = "SMOKEY_TEK"; $l = strlen($u); for ($i = 0; $i < $l; $i++) { $nN .= "<span class='c{$i}'>".$u[$i]."</span>"; } echo $nN; ?> we could improve the script further by making it three lines and removing un-needed white space (like the whitespace surrounding equal signs, ew) . <?php $u="SMOKEY_TEK"; $l=strlen($u); for($i=0; $i < $l; $i++){ $nN.="<span class='c{$i}'>".$u[$i]."</span>"; } echo $nN; ?> I dont need to advertise my other work or projects here as I am not desperate to prove anything. You are the only one in this thread advertising anything, and you further advertise by bringing up your years of technical expertise. just drop it Edited September 23, 2011 by runthis Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 23, 2011 Share Posted September 23, 2011 runthis you could have just pm'd me instead of making the comment you did and starting the issue in the first place. Well done on the optimized code though. Much better instead of a altered version of the code posted on phpfreaks back in 2010 ;) Quote Link to comment Share on other sites More sharing options...
runthis Posted September 23, 2011 Share Posted September 23, 2011 ok im sorry. 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.