PDA

View Full Version : Change name on admin duty


Scripter12345
03/04/2012, 07:50 PM
How would i make it so when a player does /adminduty that players name changes

Tomer!.$
03/04/2012, 07:53 PM
Usage of SetPlayerName.
If you want me to create the command for you, I'll need more details.

Kindred
03/04/2012, 07:55 PM
Well, first you'd have to add an adminname section in you're player file saving system, or make it so it creates a seperate file for all (or each) admin name. Then you can simply do something like this.


CMD:adminduty(playerid, params[])
{
//Check if player is admin
SetPlayerName(playerid, PlayerInfo[playerid][pAdminName]); // Change PlayerInfo[playerid][pAdminName] to the section where it saves the players admin name.
//Rest of code
return 1;
}

Scripter12345
03/04/2012, 08:05 PM
Well, first you'd have to add an adminname section in you're player file saving system, or make it so it creates a seperate file for all (or each) admin name. Then you can simply do something like this.


CMD:adminduty(playerid, params[])
{
//Check if player is admin
SetPlayerName(playerid, PlayerInfo[playerid][pAdminName]); // Change PlayerInfo[playerid][pAdminName] to the section where it saves the players admin name.
//Rest of code
return 1;
}



Im new to scripting would you be able to describe a little bit better please

Kindred
03/04/2012, 08:15 PM
enum pInfo
{
pAdmin,
pAdminName,
PlayerName,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

Example of a player enumerator ^ ^.

Then, for example, you make it so you /setadminname [name].


CMD:setadminname(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
new string[128], newname[15];
if(sscanf(params, "s", newname)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /setadminanme <name>");
PlayerInfo[playerid][pAdminName] = newname;
format(string, sizeof(string), "You set your admin name to %s", newname);
SendClientMessage(playerid, 0xFFFFFFFF, string);
}
else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not authorized to use this command!");
return 1;
}
CMD:adminduty(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
if(AdminDuty[playerid] == 1)
{
SetPlayerName(playerid, PlayerInfo[playerid][pAdminName]);
}
else
{
SetPlayerName(playerid, PlayerName);
}
}
return 1;
}


Made with sscanf and ZCMD, although AdminDuty is not defined nor is PlayerName getting the players name, should do this yourself, I don't have all day to do so.

Scripter12345
03/04/2012, 09:52 PM
enum pInfo
{
pAdmin,
pAdminName,
PlayerName,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

Example of a player enumerator ^ ^.

Then, for example, you make it so you /setadminname [name].


CMD:setadminname(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
new string[128], newname[15];
if(sscanf(params, "s", newname)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /setadminanme <name>");
PlayerInfo[playerid][pAdminName] = newname;
format(string, sizeof(string), "You set your admin name to %s", newname);
SendClientMessage(playerid, 0xFFFFFFFF, string);
}
else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not authorized to use this command!");
return 1;
}
CMD:adminduty(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 1)
{
if(AdminDuty[playerid] == 1)
{
SetPlayerName(playerid, PlayerInfo[playerid][pAdminName]);
}
else
{
SetPlayerName(playerid, PlayerName);
}
}
return 1;
}


Made with sscanf and ZCMD, although AdminDuty is not defined nor is PlayerName getting the players name, should do this yourself, I don't have all day to do so.


I have one error and this is what it is


error 006: must be assigned to an array


And this is the line it is saying the error is at



PlayerInfo[playerid][pAdminName] = newname;

Scripter12345
03/04/2012, 10:15 PM
Please Help

TzAkS.
03/04/2012, 10:25 PM
What must be assigned to an array

newname = GetPlayerName(playerid);
PlayerInfo[playerid][pAdminName] = newname;
Or
new newname[MAX_PLAYER_NAME];
GetPlayerName(playerid,newname,sizeof(newname));
PlayerInfo[playerid][pAdminName] = newname;

Toreno
03/04/2012, 10:55 PM
Here you go, works as it supposed to.

enum pInfo
{
pAdmin,
AdminName[24],
PlayerName[24],
bool:HasSetAdminName,
OnDuty
}

new PlayerInfo[MAX_PLAYERS][pInfo];

CMD:setadmin(playerid, params[])
{
new
lvl,
a_string[65],
name[MAX_PLAYER_NAME]
;

if(sscanf(params, "i", lvl))
{
return SendClientMessage(playerid, -1, "USAGE: /setadmin [level]");
}

GetPlayerName(playerid, name, MAX_PLAYER_NAME);
PlayerInfo[playerid][PlayerName] = name;
PlayerInfo[playerid][pAdmin] = lvl;
format(a_string, 65, "You are now admin level %d.", lvl);
SendClientMessage(playerid, -1, a_string);

return 1;
}

CMD:setadminname(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1)
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

new
adminname[24],
a_string[65]
;

if(sscanf(params, "s[24]", adminname))
{
return SendClientMessage(playerid, -1, "USAGE: /setadminanme [name]");
}

PlayerInfo[playerid][AdminName] = adminname;
format(a_string, 65, "Your admin name is %s.", PlayerInfo[playerid][AdminName]);
SendClientMessage(playerid, -1, a_string);
PlayerInfo[playerid][HasSetAdminName] = true;

return 1;
}

CMD:adminduty(playerid, params[])
{
if(!PlayerInfo[playerid][pAdmin])
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

if(PlayerInfo[playerid][OnDuty])
{
SetPlayerName(playerid, PlayerInfo[playerid][PlayerName]);
PlayerInfo[playerid][OnDuty] = false;
}
else
{
if(!PlayerInfo[playerid][HasSetAdminName])
{
return SendClientMessage(playerid, -1, "You haven't set an admin name yet.");
}

SetPlayerName(playerid, PlayerInfo[playerid][AdminName]);
PlayerInfo[playerid][OnDuty] = true;
}

return 1;
}

Scripter12345
03/04/2012, 11:05 PM
Here you go, works as it supposed to.

enum pInfo
{
pAdmin,
AdminName[24],
PlayerName[24],
bool:HasSetAdminName,
OnDuty
}

new PlayerInfo[MAX_PLAYERS][pInfo];

CMD:setadmin(playerid, params[])
{
new
lvl,
a_string[65],
name[MAX_PLAYER_NAME]
;

if(sscanf(params, "i", lvl))
{
return SendClientMessage(playerid, -1, "USAGE: /setadmin [level]");
}

GetPlayerName(playerid, name, MAX_PLAYER_NAME);
PlayerInfo[playerid][PlayerName] = name;
PlayerInfo[playerid][pAdmin] = lvl;
format(a_string, 65, "You are now admin level %d.", lvl);
SendClientMessage(playerid, -1, a_string);

return 1;
}

CMD:setadminname(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 1)
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

new
adminname[24],
a_string[65]
;

if(sscanf(params, "s[24]", adminname))
{
return SendClientMessage(playerid, -1, "USAGE: /setadminanme [name]");
}

PlayerInfo[playerid][AdminName] = adminname;
format(a_string, 65, "Your admin name is %s.", PlayerInfo[playerid][AdminName]);
SendClientMessage(playerid, -1, a_string);
PlayerInfo[playerid][HasSetAdminName] = true;

return 1;
}

CMD:adminduty(playerid, params[])
{
if(!PlayerInfo[playerid][pAdmin])
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

if(PlayerInfo[playerid][OnDuty])
{
SetPlayerName(playerid, PlayerInfo[playerid][PlayerName]);
PlayerInfo[playerid][OnDuty] = false;
}
else
{
if(!PlayerInfo[playerid][HasSetAdminName])
{
return SendClientMessage(playerid, -1, "You haven't set an admin name yet.");
}

SetPlayerName(playerid, PlayerInfo[playerid][AdminName]);
PlayerInfo[playerid][OnDuty] = true;
}

return 1;
}



Is there any way you could make it work with my normal code ?

Toreno
03/04/2012, 11:08 PM
Do you mean strtok?

Scripter12345
03/04/2012, 11:11 PM
Im sorry, I am new to scripting i dont quite understand what "strtok" is


Is it possible to make it work with my normal code


Please Help

Scripter12345
03/04/2012, 11:30 PM
Nothing is working ?!?!?! Please help!


I will REP ! Please

Toreno
03/04/2012, 11:41 PM
If you mean the normal one, it must be strtok, anyway;

enum pInfo
{
pAdmin,
AdminName[24],
PlayerName[24],
bool:HasSetAdminName,
OnDuty
}

new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerCommandText( playerid, cmdtext[] )
{
new
cmd[20],
tmp[128],
idx
;

cmd = strtok(cmdtext, idx);

if(!strcmp(cmd, "/setadmin", true))
{
new
a_string[65],
name[MAX_PLAYER_NAME]
;

tmp = strtok(cmdtext, idx);

if(!strlen(tmp))
{
return SendClientMessage(playerid, -1, "USAGE: /setadmin [level]");
}

GetPlayerName(playerid, name, MAX_PLAYER_NAME);
PlayerInfo[playerid][PlayerName] = name;
PlayerInfo[playerid][pAdmin] = strval(tmp);
format(a_string, 65, "You are now admin level %d.", strval(tmp));
SendClientMessage(playerid, -1, a_string);

return 1;
}

if(!strcmp(cmd, "/setadminname", true))
{
if(PlayerInfo[playerid][pAdmin] < 1)
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

new
a_string[65]
;

tmp = strtok(cmdtext, idx);

if(!strlen(tmp))
{
return SendClientMessage(playerid, -1, "USAGE: /setadmin [level]");
}

strmid(PlayerInfo[playerid][AdminName], tmp, 0, 24);
format(a_string, 65, "Your admin name is %s.", PlayerInfo[playerid][AdminName]);
SendClientMessage(playerid, -1, a_string);
PlayerInfo[playerid][HasSetAdminName] = true;

return 1;
}

if(!strcmp(cmd, "/adminduty", true))
{
if(!PlayerInfo[playerid][pAdmin])
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

if(PlayerInfo[playerid][OnDuty])
{
SetPlayerName(playerid, PlayerInfo[playerid][PlayerName]);
PlayerInfo[playerid][OnDuty] = false;
}
else
{
if(!PlayerInfo[playerid][HasSetAdminName])
{
return SendClientMessage(playerid, -1, "You haven't set an admin name yet.");
}

SetPlayerName(playerid, PlayerInfo[playerid][AdminName]);
PlayerInfo[playerid][OnDuty] = true;
}

return 1;
}

return 0;
}

Scripter12345
03/04/2012, 11:44 PM
If you mean the normal one, it must be strtok, anyway;

enum pInfo
{
pAdmin,
AdminName[24],
PlayerName[24],
bool:HasSetAdminName,
OnDuty
}

new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerCommandText( playerid, cmdtext[] )
{
new
cmd[20],
tmp[128],
idx
;

cmd = strtok(cmdtext, idx);

if(!strcmp(cmd, "/setadmin", true))
{
new
a_string[65],
name[MAX_PLAYER_NAME]
;

tmp = strtok(cmdtext, idx);

if(!strlen(tmp))
{
return SendClientMessage(playerid, -1, "USAGE: /setadmin [level]");
}

GetPlayerName(playerid, name, MAX_PLAYER_NAME);
PlayerInfo[playerid][PlayerName] = name;
PlayerInfo[playerid][pAdmin] = strval(tmp);
format(a_string, 65, "You are now admin level %d.", strval(tmp));
SendClientMessage(playerid, -1, a_string);

return 1;
}

if(!strcmp(cmd, "/setadminname", true))
{
if(PlayerInfo[playerid][pAdmin] < 1)
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

new
a_string[65]
;

tmp = strtok(cmdtext, idx);

if(!strlen(tmp))
{
return SendClientMessage(playerid, -1, "USAGE: /setadmin [level]");
}

strmid(PlayerInfo[playerid][AdminName], tmp, 0, 24);
format(a_string, 65, "Your admin name is %s.", PlayerInfo[playerid][AdminName]);
SendClientMessage(playerid, -1, a_string);
PlayerInfo[playerid][HasSetAdminName] = true;

return 1;
}

if(!strcmp(cmd, "/adminduty", true))
{
if(!PlayerInfo[playerid][pAdmin])
{
return SendClientMessage(playerid, -1, "You are not an admin.");
}

if(PlayerInfo[playerid][OnDuty])
{
SetPlayerName(playerid, PlayerInfo[playerid][PlayerName]);
PlayerInfo[playerid][OnDuty] = false;
}
else
{
if(!PlayerInfo[playerid][HasSetAdminName])
{
return SendClientMessage(playerid, -1, "You haven't set an admin name yet.");
}

SetPlayerName(playerid, PlayerInfo[playerid][AdminName]);
PlayerInfo[playerid][OnDuty] = true;
}

return 1;
}

return 0;
}



Im using ZCMD

Toreno
03/04/2012, 11:46 PM
What is normal code? I just made you a whole script for zcmd, and converted it to strtok.
What ELSE do you want?

Scripter12345
03/04/2012, 11:47 PM
What is normal code? I just made you a whole script for zcmd, and converted it to strtok.
What ELSE do you want?


Im going to private message you