Raised This Month: $32 Target: $400
 8% 

[CS:GO] Trying to make a script to change player's name, when they join


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kazafka
Junior Member
Join Date: Dec 2020
Old 12-20-2020 , 07:52   [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #1

Hello,

I've been trying to make a simple script to change player's name when they join. The problem is, that I recently get this error: error 008: must be a constant expression; assumed zero (line 22nd).

Code:
#include <sourcemod>
#include <sdktools_functions>

// Info na temat plugina - Plugin info
public Plugin:myinfo = {
	name = "CSMaxShot Core",
	author = "Kazafka",
	description = "Dobry plugin, polecam!",
	version = "0.0.3"
}

// Zmiana pseudonimu gracza - Player's alias changing
public OnClientPutInServer(client) {
	char name[MAX_NAME_LENGTH], group[MAX_NAME_LENGTH]
	new target = FindTarget(client, "")
	
	GetClientName(client, name, sizeof(name))
	AdminId aid = GetUserAdmin(target)
	GroupId gid = GetAdminGroup(aid, 0, group, sizeof(group))
	
	if(gid) {
		char group2[MAX_NAME_LENGTH] = StrCat(group, sizeof(group), name) // Here's the error
		SetClientName(client, group2)
	}
}

Last edited by Kazafka; 12-20-2020 at 07:57.
Kazafka is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-20-2020 , 08:30   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #2

StrCat() return int, you probably don't need the array char group2[]. Just use the group array to set the player name. Depending on what you try to achieve.
Assuming 22nd is the error coz i m on mobile phone.

https://sourcemod.dev/#/string/function.StrCat
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
Kazafka
Junior Member
Join Date: Dec 2020
Old 12-20-2020 , 08:36   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #3

Umm, actually I'm going to test this out:
Code:
#include <sourcemod>
#include <sdktools_functions>

// Info na temat plugina - Plugin info
public Plugin:myinfo = {
	name = "CSMaxShot Core",
	author = "Kazafka",
	description = "Dobry plugin, polecam!",
	version = "0.0.3"
}

// Zmiana pseudonimu gracza - Player's alias changing
public OnClientPutInServer(client) {
	char name[MAX_NAME_LENGTH], group[MAX_NAME_LENGTH]
	new target = FindTarget(client, "")
	
	GetClientName(client, name, sizeof(name))
	AdminId aid = GetUserAdmin(target)
	GroupId gid = GetAdminGroup(aid, 0, group, sizeof(group))
	
	StrCat(group, sizeof(group), name)
	
	if(gid) {
		SetClientName(client, group)
	}
}
And yeah, the compiler didn't throw any error but now let's test if it does work in the game lol.

Last edited by Kazafka; 12-20-2020 at 08:42.
Kazafka is offline
Kazafka
Junior Member
Join Date: Dec 2020
Old 12-20-2020 , 08:49   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #4

Quote:
Originally Posted by GsiX View Post
StrCat() return int, you probably don't need the array char group2[]. Just use the group array to set the player name. Depending on what you try to achieve.
Assuming 22nd is the error coz i m on mobile phone.

https://sourcemod.dev/#/string/function.StrCat
Nope, it doesn't change my nickname...
Kazafka is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-20-2020 , 09:28   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #5

i have no clue what i am doing so please do not quote me on this. i am just showing example.

edit: and... polishing and grinding my Polis if you don't mind me.

PHP Code:
#include <sourcemod>
#include <sdktools_functions>

// Info na temat plugina - Plugin info
public Plugin:myinfo = {
    
name "CSMaxShot Core",
    
author "Kazafka",
    
description "Dobry plugin, polecam!",
    
version "0.0.3"
}

// Zmiana pseudonimu gracza - Player's alias changing
public OnClientPostAdminCheckclient ) {
    if( 
client && CheckCommandAccessclient"generic_admin"ADMFLAG_GENERICfalse )) { // to jest filtr

        
char name[MAX_NAME_LENGTH], buffer[MAX_NAME_LENGTH]
        
GetClientNameclientnamesizeofname ))
        
Formatbuffersizeofbuffer ), "GODADMIN-%s"name // Nie wiem, co próbujesz zrobić
        
SetClientNameclientbuffer )
    }

__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 12-20-2020 at 09:31.
GsiX is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-20-2020 , 12:13   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #6

What is wrong with your code:
PHP Code:
public OnClientPutInServer(client) {
    
    
char name[MAX_NAME_LENGTH], group[MAX_NAME_LENGTH];
    
// FindTarget is used in commands (example: sm_ban) to find a target from a a given string.
    // this is useless
    
new target FindTarget(client""// remove this
    
    
GetClientName(clientnamesizeof(name)) // this get the clients name, nothing wrong
    
AdminId aid GetUserAdmin(target// AdminId from target, this is useless, because we don't have a target
    
GroupId gid GetAdminGroup(aid0groupsizeof(group)) // group id from target, this is useless, because we don't have a target
    
    
StrCat(groupsizeof(group), name// this should be included in a "if" statatement.
    
    
if(gid) {
        
SetClientName(clientgroup)
    }

Try this:
PHP Code:

public OnClientPutInServer(client) {
    
    
// get client name
    
char name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));

    
// get admin id
    
AdminId adminId GetUserAdmin(client);
    if (
adminId == INVALID_ADMIN_ID)
    {
        
// this client is not admin
        
return;
    }

    
// get group id
    
if (GetAdminGroup(adminId0groupsizeof(group) == INVALID_GROUP_ID)
    {
        
// this client doesnt have a group
        
return;
    }
    
    if (!
StrEqual(namegrouptrue))
    {
        
// client name is different than his group
        
SetClientName(clientgroup);
    }

__________________
Ilusion9 is offline
Kazafka
Junior Member
Join Date: Dec 2020
Old 12-20-2020 , 14:40   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #7

Quote:
Originally Posted by Ilusion9 View Post
What is wrong with your code:
PHP Code:
public OnClientPutInServer(client) {
    
    
char name[MAX_NAME_LENGTH], group[MAX_NAME_LENGTH];
    
// FindTarget is used in commands (example: sm_ban) to find a target from a a given string.
    // this is useless
    
new target FindTarget(client""// remove this
    
    
GetClientName(clientnamesizeof(name)) // this get the clients name, nothing wrong
    
AdminId aid GetUserAdmin(target// AdminId from target, this is useless, because we don't have a target
    
GroupId gid GetAdminGroup(aid0groupsizeof(group)) // group id from target, this is useless, because we don't have a target
    
    
StrCat(groupsizeof(group), name// this should be included in a "if" statatement.
    
    
if(gid) {
        
SetClientName(clientgroup)
    }

Try this:
PHP Code:

public OnClientPutInServer(client) {
    
    
// get client name
    
char name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));

    
// get admin id
    
AdminId adminId GetUserAdmin(client);
    if (
adminId == INVALID_ADMIN_ID)
    {
        
// this client is not admin
        
return;
    }

    
// get group id
    
if (GetAdminGroup(adminId0groupsizeof(group) == INVALID_GROUP_ID)
    {
        
// this client doesnt have a group
        
return;
    }
    
    if (!
StrEqual(namegrouptrue))
    {
        
// client name is different than his group
        
SetClientName(clientgroup);
    }

Sorry for giving resposne after 2h, but unfortunetely, it doesn't work
Kazafka is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-21-2020 , 06:22   Re: [CS:GO] Trying to make a script to change player's name, when they join
Reply With Quote #8

Because you have to edit my code, you have set a name if client is not admin and if client has no groups. The code works only if client has a group and his name is different than his group. Also, you didn't specified what do you want to do exactly, you just gave us a piece of code.
__________________
Ilusion9 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 23:41.


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