Raised This Month: $12 Target: $400
 3% 

Solved Add XP/skill to players name


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-17-2019 , 23:14   Re: Can't figure this out :)
Reply With Quote #11

formatex returns the size of the string formatted, you don't really need this value for anything but it's common practice for string manipulating functions to return the length of the string..many natives in amx-x do this.

My function definitely works, but it only takes care of adding the skill to the name in a string. You must actually set it as the players name.

After calling SetSkillInName(), do this:
PHP Code:
set_user_infoid "name" szName ); 
__________________
Bugsy is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-18-2019 , 08:57   Re: Can't figure this out :)
Reply With Quote #12

Quote:
Originally Posted by Bugsy View Post
formatex returns the size of the string formatted, you don't really need this value for anything but it's common practice for string manipulating functions to return the length of the string..many natives in amx-x do this.

My function definitely works, but it only takes care of adding the skill to the name in a string. You must actually set it as the players name.

After calling SetSkillInName(), do this:
PHP Code:
set_user_infoid "name" szName ); 
Works indeed, I've tried to tinker with the iSetPos variable but it just doesn't remove the [ (Float skill here ) ]. It either adds another one on top , so for an example: your_name [ yourskill] -> next round - > your_name [yourskill] [yourskill].

I tried to look at another example of string manipulation using strlen as seen in GATHER PUG PLUGIN (Credits to alghtryer) : There it is - line 270

I understood how it works, so it basically gets the length of the string, it does "strlen ( szNewName - 1) so it basically starts from the end of the string, he removes the int number of characters that he sets and then declares the end of the string, so basically he does : your_name [skill] = your_name -1 so he starts from your_name =< here, detects if the first character is "]" and then does -5 ( [ ] and whatever the numbers are ), then sets the player's name upon spawn, then it sets the user's skill points BACK AGAIN. I tried this concept but it didn't work for me, at least maybe I did something wrong, so I gave up on that. Now I've got this:

PHP Code:
new bool:FirstSpawn[32] = true// Detect player's first spawn, upon connect (NOT LIVE) do not show the player's skill.

public SetSkillInNameid szOutput[] , maxchars // Credit: Bugsy
{
    new 
iNameLen szSkill10 ] , iSkillLen iSetPos Float:fSkill;
    
    
iNameLen get_user_nameid szOutput maxchars );
    
get_user_skillid fSkill );
    
iSkillLen formatexszSkill charsmaxszSkill ) , "%0.2f" fSkill );

    if ( ( 
iNameLen iSkillLen ) > 31 )
    {
        
iSetPos iNameLen - ( iSkillLen );
    }
    else
    {
        
iSetPos iNameLen;
    }
    return 
formatexszOutputiSetPos ] , maxchars iSetPos " [%s]" szSkill );
}

public 
FwdPlayerSpawnPostid )
{
    new 
szName[32] , players[MAX_PLAYERS] , num user;
    
get_playersplayers num );
    for ( new 
ii<num i++ ) 
    {
        if( 
is_user_alive id ) ) //check if user's alive
        
{
        
user players];
        if( 
FirstSpawnuser ] == true // if it's the user's first spawn I break the initial if loop. (dunno if it works)
        
{
        
FirstSpawnuser ] = false// setting the user's first spawn to false so I can start executing the code below in the next round.
        
break;
        }
        
SetSkillInNameid szName[user] , charsmaxszName ) );
        
set_user_infoid "name" szName[user] );
        }
    }


And if I tinker with the iSetPos variable I just cause more ruckus since the player's length of the names always varies.
__________________

Last edited by deprale; 01-18-2019 at 09:14. Reason: NEATER INDENTING (MORE UNDERSTANDABLE hopefully)
deprale is offline
shauli
Member
Join Date: Jun 2018
Old 01-18-2019 , 10:36   Re: Can't figure this out :)
Reply With Quote #13

Try this one maybe:
PHP Code:
formatNameidstring[ ], len )
{
    new 
pos get_user_nameidstringlen ), temp posskill;
    
get_user_skillidskill );

    if( 
stringpos ] == ']' )
        while( 
pos && string[ --pos ] != '[' ) { }
    
    if( 
pos != && pos != temp )
        return 
formatexstringpos ], len pos"[%d]"skill );
    else
        return 
formatexstringlen"%.22s [%d]"stringskill );
}

public 
FwdPlayerSpawnPostid )
{
    new 
szName32 ];
    
formatNameidszNamecharsmaxszName ) );

    
set_user_infoid "name"szName );

shauli is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-18-2019 , 11:40   Re: Can't figure this out :)
Reply With Quote #14

Quote:
Originally Posted by shauli View Post
Try this one maybe:
PHP Code:
formatNameidstring[ ], len )
{
    new 
pos get_user_nameidstringlen ), temp posskill;
    
get_user_skillidskill );

    if( 
stringpos ] == ']' )
        while( 
pos && string[ --pos ] != '[' ) { }
    
    if( 
pos != && pos != temp )
        return 
formatexstringpos ], len pos"[%d]"skill );
    else
        return 
formatexstringlen"%.22s [%d]"stringskill );
}

public 
FwdPlayerSpawnPostid )
{
    new 
szName32 ];
    
formatNameidszNamecharsmaxszName ) );

    
set_user_infoid "name"szName );

Nope, my name gets printed like this:
My_name [123812731231] (random numbers).
__________________
deprale is offline
pokezao
Member
Join Date: Oct 2014
Old 01-18-2019 , 12:15   Re: Can't figure this out :)
Reply With Quote #15

Try like %0.2f instead of %d, because the 'skill' value is a Float.
pokezao is offline
shauli
Member
Join Date: Jun 2018
Old 01-18-2019 , 12:20   Re: Can't figure this out :)
Reply With Quote #16

Quote:
Originally Posted by deprale View Post
Nope, my name gets printed like this:
My_name [123812731231] (random numbers).
pokezao is right, it's probably a Float value. I wasn't sure because you used integer and Bugsy used Float. Anyway, try this:
PHP Code:
formatNameidstring[ ], len 

    new 
pos get_user_nameidstringlen ), temp posFloat:skill
    
get_user_skillidskill ); 

    if( 
stringpos ] == ']' 
        while( 
pos && string[ --pos ] != '[' ) { } 
     
    if( 
pos != && pos != temp 
        return 
formatexstringpos ], len pos"[%.2f]"skill ); 
    else 
        return 
formatexstringlen"%.22s [%.2f]"stringskill ); 


public 
FwdPlayerSpawnPostid 

    new 
szName32 ]; 
    
formatNameidszNamecharsmaxszName ) ); 

    
set_user_infoid "name"szName ); 

shauli is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-18-2019 , 13:26   Re: Can't figure this out :)
Reply With Quote #17

I tried using float as well.
I'm gonna try it again anyway, maybe I did something wrong!

(Gonna edit this in a few mins, thanks for the help)

EDIT: It works, huge thanks to everyone who helped me! Thanks for allocating your own free time to lend me a hand!
Shauli's method was overall the easiest to understand, part of it being very simple and compact code, I do appreciate everyone else's input as well as I learned some new things today!

Another small question: How would I go around the fact that it also displays the skill the player has when he types something in the chat? What If I wanted it to be only "visually" active in the scoreboard so it doesn't actually mess with csstats_sql players names?

I had a look at xPaw's "Scoreboard Title" plugin created way back in 2010 and it looked to be possible since he changed just the "hostname" visually, but in fact the original hostname rests the same.

Something similar has already been requested, I've searched for quite a bit the forums and found some leads in "CSPUGmod" and "GATHER PUG" plugins, but the most useful piece of info that I came across This reply from GuskiS suggests that he did succeed in creating something similar, I understood how the code works, but seems like he said that it doesn't work (it leads to nothing), then again another user has posted below that set_user_info actually doesn't change the player's name (which is true), it's only server-side after all, so how come does it affect csstats_sql displaying top15?

2nd EDIT: Apparently some people have [0.00] for some reason. They're always different people on each map change
ALSO: it causes a lot of problems with my database cause for every new namechange it generates a new row
__________________

Last edited by deprale; 01-18-2019 at 16:12.
deprale is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-18-2019 , 16:57   Re: Can't figure this out :)
Reply With Quote #18

New question new thread.

Also dont over complicate everything.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-18-2019 at 16:58.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-19-2019 , 04:55   Re: Can't figure this out :)
Reply With Quote #19

I really doubt you can change only the name in the scoreboard. However, it's easy to fix the db issue: when saving, get the name and remove [skill] from the string.
For chat, I think you can do the same thing.
__________________
HamletEagle is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-19-2019 , 08:47   Re: Can't figure this out :)
Reply With Quote #20

Thanks everyone for the support!

Thanks for the tip HamletEagle, I'll study the plugin better and see what I can do!


P.S: I marked the thread as solved.
__________________

Last edited by deprale; 01-19-2019 at 08:47. Reason: Marked as solved!
deprale is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode