Permanant Group Changer

Dastgir

Core Developer
Messages
3,805
Points
0
Discord
Dastgir#1460
IRC Nickname
Dastgir
Github
dastgirp
Emulator
Client Version
2019-02-28 RE
thumb-11b5c7b20283da7618f8cd3fcfca03cd-adjgroup2.png


File Name: Permanant Group Changer

File Submitter: Dastgir

File Submitted: 22 Jul 2014

File Category: Utility

This is a command "@adjgroup2" From which you can give a character new GroupID, no matter he is online or offline.

The New Group is changed permanently.

Usage:

Code:
@adjgroup2 <GroupID> <PlayerName>
If PlayerName contains Spaces, Just put it with spaces, without Quotes.

Click here to download this file

 
Last edited by a moderator:
As it's currently written, this won't function completely for a couple of reasons.

.@p_name$ = .@atcmd_parameters$[1]; 

This only pulls the second position of the index. If you syntax is @adjgroup2 99 Player B, the script will only read it as @adjgroup2 99 Player. The biggest problem with this is that if there are two players online named Player A and Player B, the script might unintentionally change Player A's group; you won't immediately know for sure, since your variable .@p_name$ will only store "Player".

 
A proper way to determine the player's name would be to store additional values past index 1. When you type @adjgroup2 99 Player B, the following values are stored:

.@atcmd_command$ = "@adjgroup2";.@atcmd_parameters$[0] = "99";.@atcmd_parameters$[1] = "Player";.@atcmd_parameters$[2] = "B";.@atcmd_numparameters = 3;

Using this information, you can collect the additional player information by copying the array values and imploding them, separated by spaces:

for (.@i = 1; .@i < .@atcmd_numparameters; .@i++) { .@name_data$[.@j++] = .@atcmd_parameters$[.@i];}.@p_name$ = implode(.@name_data$, " "); 

Now .@p_name$ will properly store the name Player B, or whatever name you send that has spaces in it.
 

.@account_id = getcharid(3, .@p_name$); 

The problem here is that getcharid() will only return a value if the player is online and can be attached to the script (this would have been a problem with .@p_name$ anyway, since it was incorrectly storing player names);  if Player B is offline, .@account_id will have a value of 0. Normally, this would be fine, since you added a check to determine whether or not a player exists on the map server; however, it seems you're trying to update the account regardless of whether or not a player is online. A more efficient way of collecting a player's account ID would be to query the database using their (now properly stored) player name.

.@account_id = query_sql("SELECT `account_id` FROM `char` WHERE `name` = '"+ .@p_name$ +"'"); 

Using the function query_sql() will return the value found; if the player truly does not exist at all, the function will return 0. In that case, you can replace this check with a simpler one:

.@exist = query_sql("SELECT `group_id` FROM `login` WHERE `account_id`="+.@account_id, .@g_id); if (!.@exist){ message strcharinfo(0), .@p_name$ +" Does not Exist."; end; }
Code:
		if (!.@account_id){			message strcharinfo(0), .@p_name$ +" does not exist.";			end;		}		query_sql "SELECT `group_id` FROM `login` WHERE `account_id` = '"+ .@account_id +"'", .@g_id;
With these changes made, the rest of the script and checks will run just fine.

Here's a debug script and some screenshots:

- script str_test -1,{ OnInit: bindatcmd "test", strnpcinfo(3) +"::OnCommand", 99, 99; OnCommand: // Collect string data for (.@i = 0; .@i < .@atcmd_numparameters; .@i++) { .@str_data$[.@j++] = .@atcmd_parameters$[.@i]; } .@string$ = implode(.@str_data$, " "); // Updated method .@string2$ = .@atcmd_parameters$[0]; // Current method message strcharinfo(0), "Updated : "+ .@string$; // Updated output message strcharinfo(0), "Current : "+ .@string2$; // Current output end;}


ReSRFNp.jpg


b37eykN.jpg
 
Last edited by a moderator:
@Mumbles,

Updated the script.(I really have overlooked the Quotes Part)

 
Back
Top