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

Solved Add XP/skill to players name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-15-2019 , 17:05   Add XP/skill to players name
Reply With Quote #1

I'm trying to use HamSandwich and hook FwdPlayerSpawnPost (Ham_Spawn) + use This stock

My objective: Set user skill points in their name upon spawning.


I have been trying for the past hour without any results, I have given up!
Please anyone willing to give me some tips, I tried to manually loop through each player and get_user_skill but so far it was a huge failure.
__________________

Last edited by deprale; 02-12-2019 at 14:46. Reason: Solved issue!
deprale is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-15-2019 , 17:54   Re: Can't figure this out :)
Reply With Quote #2

What is the issue? Is the name not updating at all, or is the skill value in the name wrong? Provide your code
__________________
Bugsy is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-15-2019 , 18:20   Re: Can't figure this out :)
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
What is the issue? Is the name not updating at all, or is the skill value in the name wrong? Provide your code
The issue is that I'm trying to implement this but I do not understand the coding in this particular plugin, neither I am that advanced to accomplish this task but I do wish to learn, even if I will achieve this through tips... I am currently half-way through the AMXX tutorials and it's been a breeze because the code is easy (not compact, it is kinda hard-coded as well so it's super easy to understand), it's just that this plugin has given me headaches, whoever wrote this plugin is just amazing!!! I can't seem to grasp how it works even though I tried to - for hours!

Basically should be:
(Your name) + (" [YOUR_POINTS] ")

PHP Code:
//init
public plugin_init()
{
    
RegisterHam(Ham_Spawn"player""FwdPlayerSpawnPost"1)
}

public 
FwdPlayerSpawnPostid )
{    
    if( 
is_user_aliveid ) )
    {
            new 
szName32 ]
            
get_user_infoid"name"szNamecharsmaxszName ) )
            
            new 
iLen strlenszName )
            
            new 
iPos iLen 1
            
            
if( szNameiPos ] == '>' )
            {    
                new 
i
                
for( 17i++ )
                {    
                    if( 
szNameiPos ] == '<' )
                    {    
                        
iLen iPos i
                        szName
iLen ] = EOS
                        
break
                    }
                }
            }
            new 
player_id[32],user_skill;
            
get_user_skill(player_iduser_skill);
            for (new 
ii<numi++)
            {
            
formatszNameiLen ], charsmaxszName ) - iLenszNameiLen-] == ' ' "[%d]" " [%d]"get_user_skill(player_id[], user_skill));   
            
set_user_infoid"name"szName 
            }
    }

This is what I currently have...
So basically the full plugin(which I have stated the source to)
Spoiler


EDIT: I kinda tried to understand the coding but it is just too advanced for me, I mean, the whole plugin, in general, is very neatly coded, it is all well-coded but the problem I encountered is that I got kinda lost when I saw no global variables and it's been a pain in the ... for me to understand most (70%) of the code.

TL;DR - this plugin is just too well-made for me to understand the coding...
__________________

Last edited by deprale; 01-15-2019 at 18:41. Reason: wrong copy pasta
deprale is offline
shauli
Member
Join Date: Jun 2018
Old 01-16-2019 , 05:21   Re: Can't figure this out :)
Reply With Quote #4

Quote:
Originally Posted by deprale View Post
The issue is that I'm trying to implement this but I do not understand the coding in this particular plugin, neither I am that advanced to accomplish this task but I do wish to learn, even if I will achieve this through tips... I am currently half-way through the AMXX tutorials and it's been a breeze because the code is easy (not compact, it is kinda hard-coded as well so it's super easy to understand), it's just that this plugin has given me headaches, whoever wrote this plugin is just amazing!!! I can't seem to grasp how it works even though I tried to - for hours!

Basically should be:
(Your name) + (" [YOUR_POINTS] ")
PHP Code:
public FwdPlayerSpawnPostid )
{    
    if( 
is_user_aliveid ) )
    {
            new 
szName32 ]
            
get_user_infoid"name"szNamecharsmaxszName ) ) //get user name
            
            
new iLen strlenszName //get length of name
            
            
new iPos iLen //last character of the name
            
            
if( szNameiPos ] == '>' //check if the last character is '>' (if it is, he already has a skill tag)
            
{    
                new 
//he has a skill tag, we need to check when the skill tag starts (char '<')
                
for( 17i++ ) //I don't know why 7, probably the skill can't be too big
                
{    
                    if( 
szNameiPos ] == '<' //found the start of the skill tag
                    
{    
                        
iLen iPos i
                        szName
iLen ] = EOS //delete everything from here until the end (terminates the string right here)
                        
break
                    }
                }
            }

            new 
player_id[32],user_skill//deleting the current skill tag completed, now writing a new one.

            //I don't see why you need a for loop here, you already have the player's id (id). 'num' is undefined and 'players_id' is empty. You don't need those anyway.

            
get_user_skill(player_iduser_skill);
            for (new 
ii<numi++)
            {
            
formatszNameiLen ], charsmaxszName ) - iLenszNameiLen-] == ' ' "[%d]" " [%d]"get_user_skill(player_id[], user_skill));
            
set_user_infoid"name"szName 
            }
    }

You can see in the code that your skill tag is formatted as name [SKILL] but the plugin checks for existing tags in the format name <SKILL>.

You don't need the for loop and you need to change < and > to [ and ].
shauli is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-16-2019 , 06:28   Re: Can't figure this out :)
Reply With Quote #5

Quote:
Originally Posted by shauli View Post
PHP Code:
public FwdPlayerSpawnPostid )
{    
    if( 
is_user_aliveid ) )
    {
            new 
szName32 ]
            
get_user_infoid"name"szNamecharsmaxszName ) ) //get user name
            
            
new iLen strlenszName //get length of name
            
            
new iPos iLen //last character of the name
            
            
if( szNameiPos ] == '>' //check if the last character is '>' (if it is, he already has a skill tag)
            
{    
                new 
//he has a skill tag, we need to check when the skill tag starts (char '<')
                
for( 17i++ ) //I don't know why 7, probably the skill can't be too big
                
{    
                    if( 
szNameiPos ] == '<' //found the start of the skill tag
                    
{    
                        
iLen iPos i
                        szName
iLen ] = EOS //delete everything from here until the end (terminates the string right here)
                        
break
                    }
                }
            }

            new 
player_id[32],user_skill//deleting the current skill tag completed, now writing a new one.

            //I don't see why you need a for loop here, you already have the player's id (id). 'num' is undefined and 'players_id' is empty. You don't need those anyway.

            
get_user_skill(player_iduser_skill);
            for (new 
ii<numi++)
            {
            
formatszNameiLen ], charsmaxszName ) - iLenszNameiLen-] == ' ' "[%d]" " [%d]"get_user_skill(player_id[], user_skill));
            
set_user_infoid"name"szName 
            }
    }

You can see in the code that your skill tag is formatted as name [SKILL] but the plugin checks for existing tags in the format name <SKILL>.

You don't need the for loop and you need to change < and > to [ and ].
Thanks for the tips, I'm going to see what I can do after I get home!
__________________
deprale is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-16-2019 , 14:12   Re: Can't figure this out :)
Reply With Quote #6

Its not a good idea to assign points in the players name since their max name length is limited to 32 characters.
PHP Code:
Assign_points_inUserName(idiPointsszReturn[32])
{
   
get_user_name(idszReturn31);
   
szReturn[31] = ']';
   new 
szPoints[7]; num_to_str(iPointsszPoints6);
   
copy(szReturn[24], 6szPoints)
   
szReturn[23] = '[';
   
szReturn[22] = ' ';
   
replace_all(szReturncharsmax(szReturn"^0""")

Try this..
__________________
@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-17-2019 at 16:20.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-17-2019 , 11:38   Re: Can't figure this out :)
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Its not a good idea to assign points in the players name since their max name length is limited to 32 characters.
PHP Code:
Assign_points_inUserName(idiPoints, &szReturn[32])
{
   
get_user_name(idszReturn31);
   
szReturn[31] = ']';
   new 
szPoints[7]; num_to_str(iPointsszPoints6);
   
copy(szReturn[24], 30szPoints)
   
szReturn[23] = '[';
   
szReturn[22] = ' ';
   
replace_all(szReturncharsmax(szReturn"^0""")

Try this..
Natsheh, you do not need to use an ampersand to pass an array by reference. Arrays are always passed by-reference by default. I also tried the code and it is not working for me.

@OP, try this. If a player has a long name, this will trim off just enough to fit the skill value.
PHP Code:
new szName32 ];
SetSkillInNameid szName charsmaxszName ) );

public 
SetSkillInNameid szOutput[] , maxchars )
{
    new 
iNameLen szSkill10 ] , iSkillLen iSetPos Float:fSkill;
    
    
iNameLen get_user_nameid szOutput maxchars );
    
get_user_skillid fSkill );
    
iSkillLen formatexszSkill charsmaxszSkill ) , "%0.2f" fSkill );
    
    
// 5 is to accound for ' [ # ]', without the #, adjust as needed if you change the formatex() format below.
    
if ( ( iNameLen iSkillLen ) > 31 )
    {
        
iSetPos iNameLen - ( iSkillLen );
    }
    else
    {
        
iSetPos iNameLen;
    }
    
    return 
formatexszOutputiSetPos ] , maxchars iSetPos " [ %s ]" szSkill );

__________________

Last edited by Bugsy; 01-17-2019 at 13:42.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-17-2019 , 16:17   Re: Can't figure this out :)
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
Natsheh, you do not need to use an ampersand to pass an array by reference. Arrays are always passed by-reference by default. I also tried the code and it is not working for me.
You're totally right i forgot about that.

And i didn't test the code I'll check what's wrong.

Can you also tell me what it did output ? I can't do tests...
__________________
@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-17-2019 at 16:19.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-17-2019 , 19:17   Re: Can't figure this out :)
Reply With Quote #9

Nothing, just my name and nothing else. I think the below is your problem, it is not doing what you expect.
PHP Code:
replace_all(szReturncharsmax(szReturn), "^0"""
__________________
Bugsy is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-17-2019 , 20:37   Re: Can't figure this out :)
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Natsheh, you do not need to use an ampersand to pass an array by reference. Arrays are always passed by-reference by default. I also tried the code and it is not working for me.

@OP, try this. If a player has a long name, this will trim off just enough to fit the skill value.
PHP Code:
new szName32 ];
SetSkillInNameid szName charsmaxszName ) );

public 
SetSkillInNameid szOutput[] , maxchars )
{
    new 
iNameLen szSkill10 ] , iSkillLen iSetPos Float:fSkill;
    
    
iNameLen get_user_nameid szOutput maxchars );
    
get_user_skillid fSkill );
    
iSkillLen formatexszSkill charsmaxszSkill ) , "%0.2f" fSkill );
    
    
// 5 is to accound for ' [ # ]', without the #, adjust as needed if you change the formatex() format below.
    
if ( ( iNameLen iSkillLen ) > 31 )
    {
        
iSetPos iNameLen - ( iSkillLen );
    }
    else
    {
        
iSetPos iNameLen;
    }
    
    return 
formatexszOutputiSetPos ] , maxchars iSetPos " [ %s ]" szSkill );

I'm about to try this out, I've been tinkering with this for a while. Thanks!
I have a hard time understanding what, or how return formatex works, could you please elaborate? If I'm not asking too much.

also EDIT: Seems to be not working, doesn't do anything at all in fact.
Also, I assume the following:

PHP Code:
new szName32 ];
SetSkillInNameid szName charsmaxszName ) ); 
Is for my Ham_Spawn hook? If yes, it does not work (sadly) - I tried looping through players but it does absolutely nothing.
Also tried to set it as an infinite task and again it does nothing

Debug doesn't show anything abnormal/any errors.

My current Code:

PHP Code:
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 );
    
    
// 5 is to accound for ' [ # ]', without the #, adjust as needed if you change the formatex() format below.
    
if ( ( iNameLen iSkillLen ) > 31 )
    {
        
iSetPos iNameLen - ( iSkillLen );
    }
    else
    {
        
iSetPos iNameLen;
    }
    
    return 
formatexszOutputiSetPos ] , maxchars iSetPos " [ %s ]" szSkill );
}

public 
NameChange(id//Credit: Bugsy
{
    new 
szName32 ];
    
SetSkillInNameid szName charsmaxszName ) );
}

public 
FwdPlayerSpawnPostid )
{    
        new 
players[32] , szName[32] , num;
        
get_playersplayersnum )

        for( new 
inumi++ )
            
SetSkillInNameplayers[i] , szName charsmaxszName ) );


__________________

Last edited by deprale; 01-17-2019 at 22:05.
deprale is offline
Reply



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 17:09.


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