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

Team switch using database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ahimel
New Member
Join Date: Apr 2018
Old 06-14-2018 , 14:52   Team switch using database
Reply With Quote #1

Hello guys, I am begginer at scripting so I have problem for few weeks and I just give up
Code just doesn't work. I don't know.
The thing is that if in database User with steamid have player6-player10 he have to go to CT else to T
Code:
void SQL_CheckSPOT(client)
{
	char[] Query = new char[150];
	decl String:steamID64[18]; 
	GetClientAuthId(client, AuthId_SteamID64, steamID64, sizeof(steamID64)); 	
	
	FormatEx(Query, 150, "SELECT `player_spot` FROM `users` WHERE `steamid_64` = '%s'",steamID64);
	DBResultSet sQuery = SQL_Query(DB, Query);
	
	SQL_CheckSPOT_Callback(DB,sQuery,client);
	
}

public void SQL_CheckSPOT_Callback(Database db, DBResultSet results,  client)
{
	char res[12];
	while (results.FetchRow())
	{
		SQL_FetchString(results, 0, res, sizeof(res));
	}
	
    decl String:buffer[32];
    Format(buffer, sizeof(buffer), "%d", GetSteamAccountID(client));

    // Force the player on a team 1-5T
    if (StrContains("player1", res) <= 0 || StrContains("player2", res) <= 0 || StrContains("player3", res) <= 0 || StrContains("player4", res) <= 0 || StrContains("player5", res) <= 0) {
        LogMessage("Putting on TEAMA");
        CS_SwitchTeam(client, 1);
    } else {
        LogMessage("Putting on TEAMB");
        CS_SwitchTeam(client, 2);
    }
    return Plugin_Continue;	
}
Thanks for help

Last edited by Ahimel; 06-14-2018 at 14:53. Reason: Correct
Ahimel is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 06-14-2018 , 20:04   Re: Team switch using database
Reply With Quote #2

You need to change each of the <= 0 to != 1. You could also simply use one StrContains and check if the string player exists. You also can't return Plugin_Continue to a void function.

Last edited by ThatKidWhoGames; 06-14-2018 at 20:06.
ThatKidWhoGames is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 06-15-2018 , 14:22   Re: Team switch using database
Reply With Quote #3

Quote:
Originally Posted by Ahimel View Post
Code:
void SQL_CheckSPOT(client)
{
	char[] Query = new char[150];
	decl String:steamID64[18]; 
	GetClientAuthId(client, AuthId_SteamID64, steamID64, sizeof(steamID64));
This one is seriously bad, -

Do the SteamID checking properly, as explained in this post.

Doing otherwise will produce unexpected results...


Quote:
Originally Posted by ThatKidWhoGames View Post
You need to change each of the <= 0 to != 1. You could also simply use one StrContains and check if the string player exists. You also can't return Plugin_Continue to a void function.
I believe you mean to do "!= -1", with your advice:

Quote:
Originally Posted by https://sm.alliedmods.net/new-api/string/StrContains
Return Value

-1 on failure (no match found). Any other value indicates a position in the string where the match starts.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].

Last edited by DarkDeviL; 06-15-2018 at 14:23.
DarkDeviL is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 06-15-2018 , 21:31   Re: Team switch using database
Reply With Quote #4

That's what I meant, thanks!
ThatKidWhoGames is offline
Ahimel
New Member
Join Date: Apr 2018
Old 07-08-2018 , 17:42  
Reply With Quote #5

Hello guys, I am beginner at scripting so I need your help. I need plugin which checks in database if steamid64 'player_spot' = 'player5 to player10' connect to CT , else to T


Thanks for help.

Hello guys, I am dealing with this problem for long long time and no one fixed it. So please help me guys.
Code:
Code:
void SQL_CheckSPOT(client)
{
	char[] Query = new char[150];
	decl String:steamID64[18]; 
	GetClientAuthId(client, AuthId_SteamID64, steamID64, sizeof(steamID64)); 	
	
	FormatEx(Query, 150, "SELECT `player_spot` FROM `users` WHERE `steamid_64` = '%s'",steamID64);
	DBResultSet sQuery = SQL_Query(DB, Query);
	
	SQL_CheckSPOT_Callback(DB,sQuery,client);
	
}

public void SQL_CheckSPOT_Callback(Database db, DBResultSet results,  client)
{
	char res[12];
	while (results.FetchRow())
	{
		SQL_FetchString(results, 0, res, sizeof(res));
	}
	
    decl String:buffer[32];
    Format(buffer, sizeof(buffer), "%d", GetSteamAccountID(client));
	PrintToServer("RES: %s      Id: %s",res,client);
    // Force the player on a team 1-5T
    if (strcmp("player1", res) != 0 || strcmp("player2", res) != 0 || strcmp("player3", res) != 0 || strcmp("player4", res) != 0 || strcmp("player5", res) != 0){
    	CS_SwitchTeam(client, CS_TEAM_CT);
    	PrintToServer("RES: %s      Id: %s",res,client);
    }else{
	  CS_SwitchTeam(client, CS_TEAM_T);	
    }	
}



public Action Join_Team(client, const char[] command, args)
{
	SQL_CheckSPOT(client);

	decl String:steamID64[18]; 
	GetClientAuthId(client, AuthId_SteamID64, steamID64, sizeof(steamID64)); 
	char team[5];
	GetCmdArg(1, team, sizeof(team));
	
	if (CurrentRound == WARMUP)
	{
		PrintHintText(client, "<font color='#0087af'><b><u>%N</u></b></font><font color='#87ff87'>%d/%d Players Ready</font><br><font color='#af5fff'>Type !ready to ready up.</font>", client, ReadyPlayers, GetConVarInt(RequiredReadyPlayers));
		}
	return Plugin_Stop;
}
Thanks for help

Last edited by DarkDeviL; 07-10-2018 at 08:30.
Ahimel is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 07-08-2018 , 18:31   Re: Need plugin which uses Database for force join
Reply With Quote #6

Quote:
Originally Posted by Ahimel View Post
Hello guys, I am beginner at scripting so I need your help. I need plugin which checks in database if steamid64 'player_spot' = 'player5 to player10' connect to CT , else to T


Thanks for help.
It sounds like a request, where you want the full code to be made by somenoe else and provided in a working state to you, as such, I have moved your post into Plugin/Gameplay Ideas and Requests .


People tend to be active on the forums that they are interested in, so if they are interested in assisting you with your code when you have issues (Scripting section), they may not necessarily be interested in providing full code (which would belong to "Plugin/Gameplay Ideas and Requests "), and the other way around.

I therefore suggest you pay more attention in the future, and post them only in the most relevant section of the board, and not just the first section you see. This way will bring the best and most useful responses..


Edit 2018-07-10 141 CEST: I have now merged all your threads (cross posts about the same issue), do NOT cross post the same thing towards multiple threads, and do not bump. If no one responds, there are usually things you can do better in your explanation, such as explaining how the code reacts when you use it, including all error output it produces, etc.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].

Last edited by DarkDeviL; 07-10-2018 at 08:33.
DarkDeviL is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-11-2018 , 06:06   Re: Team switch using database
Reply With Quote #7

"char[] Query = new char[150];"

Is it only me, why index a query string?
mug1wara is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-12-2018 , 06:20   Re: Team switch using database
Reply With Quote #8

Quote:
Originally Posted by mug1wara View Post
"char[] Query = new char[150];"

Is it only me, why index a query string?
Serious?

Arrays need a length, which includes char arrays.
__________________
Neuro Toxin is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-12-2018 , 08:05   Re: Team switch using database
Reply With Quote #9

It was kinda new to me though, never done it and works the way I want it to work.

Atleast I understand why ^^

EDIT:

@Neuro Toxin

"char[] Query[150];"

Query is an array.
150 is a size...

Only difference is that "char[] Query = new char[150];"'s size may be dynamic.

It wouldn't matter that much in querying.

Last edited by mug1wara; 07-25-2018 at 17:52.
mug1wara 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 16:01.


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