SA-MP Forums Archive
help +rep - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: help +rep (/showthread.php?tid=638044)



help +rep - [SU]Spartan - 25.07.2017

Код:
CMD:setname(playerid,params[]){
	if(admin[playerid]<4) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFFF}You need admin level 4 to use this command");
	new id,name[28], text[500], newpw[500];
	if(sscanf(params,"uss",id,name,newpw)) return SendClientMessage(playerid,COLOR_RED,"USAGE:{FFFFFF}/setname [id] [name] [password]");
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFFF}Player not connected");
        new pw[129];
        WP_Hash(pw,sizeof(pw),newpw);
        if(!dini_Exists(Account(name)))
        {
        SetPlayerName(id,name);
		dini_Create(Account(id));
        dini_Set(Account(id),"password",pw);
        dini_IntSet(Account(id),"money",0);
        dini_IntSet(Account(id),"color",GetPlayerColor(playerid));
        dini_IntSet(Account(id),"score",0);
        dini_IntSet(Account(id),"admin",0);
  }
      else if(dini_Exists(Account(name)))
	  {
	  }
return 1;
}
errors on if(dini_Exists(Account(name)))
and if(!dini_Exists(Account(name))) please help

EDIT errors show only when I put (name) if I put (id) it's fine but i need name


Re: help +rep - Stormfire - 25.07.2017

Код:
CMD:setname(playerid,params[]){
	if(admin[playerid]<4) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFFF}You need admin level 4 to use this command");
       GetPlayerName(id, name, MAX_PLAYER_NAME);
	new id,name[28], text[500], newpw[500];
	if(sscanf(params,"uss",id,name,newpw)) return SendClientMessage(playerid,COLOR_RED,"USAGE:{FFFFFF}/setname [id] [name] [password]");
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFFF}Player not connected");
        new pw[129];
        WP_Hash(pw,sizeof(pw),newpw);
        if(!dini_Exists(Account(name)))
        {
        SetPlayerName(id,name);
		dini_Create(Account(id));
        dini_Set(Account(id),"password",pw);
        dini_IntSet(Account(id),"money",0);
        dini_IntSet(Account(id),"color",GetPlayerColor(playerid));
        dini_IntSet(Account(id),"score",0);
        dini_IntSet(Account(id),"admin",0);
  }
      else if(dini_Exists(Account(name)))
	  {
	  }
return 1;
}
try this


Re: help +rep - [SU]Spartan - 25.07.2017

CMDetname(playerid,params[]){
new id ,name[28], text[500], newpw[500];
if(admin[playerid]<4) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFF F}You need admin level 4 to use this command");
GetPlayerName(id, name, MAX_PLAYER_NAME);

if(sscanf(params,"uss",id,name,newpw)) return SendClientMessage(playerid,COLOR_RED,"USAGE:{FFFFF F}/setname [id] [name] [password]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFF F}Player not connected");
new pw[129];
WP_Hash(pw,sizeof(pw),newpw);

if(!dini_Exists(Account(name)))
{
SetPlayerName(id,name);
dini_Create(Account(id));
dini_Set(Account(id),"password",pw);
dini_IntSet(Account(id),"money",0);
dini_IntSet(Account(id),"color",GetPlayerColor(pla yerid));
dini_IntSet(Account(id),"score",0);
dini_IntSet(Account(id),"admin",0);
}
else if(dini_Exists(Account(name)))
{
}
return 1;}

the bold ones have error
C:\Users\John\Desktop\ESDS 0.3.7 NEW 2\gamemodes\ESDS.pwn(5645) : error 035: argument type mismatch (argument 1)
C:\Users\John\Desktop\ESDS 0.3.7 NEW 2\gamemodes\ESDS.pwn(5655) : error 035: argument type mismatch (argument 1)


Re: help +rep - Kane - 25.07.2017

Been a while since I've touched DINI but that isn't how it's done.

You need to format and check the file location to see if it exists. For example:

PHP код:
new fileName[90]; 
format(fileNamesizeof(fileName), "Accounts/%s.ini"name);
if(
dini_Exists(fileName))
{
   continue...
}
else
{
   continue...

Curious, why're you checking if their file exists?

The only way to be on the server is if they're registered n their file exists, right?


Re: help +rep - [SU]Spartan - 26.07.2017

because if it exists, it should not allow the admin to use this command because the name would be already taken


Re: help +rep - Sew_Sumi - 26.07.2017

Quote:
Originally Posted by [SU]Spartan
Посмотреть сообщение
because if it exists, it should not allow the admin to use this command because the name would be already taken
You're on the right track there.


Re: help +rep - [SU]Spartan - 26.07.2017

Код:
CMD:setname(playerid,params[]){
	new id ,name[28], newpw[500];

	if(admin[playerid]<4) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFFF}You need admin level 4 to use this command");
    GetPlayerName(id, name, MAX_PLAYER_NAME);

	 new fileName[90];
     format(fileName, sizeof(fileName), "users/%s.ini", name);

	if(sscanf(params,"uss",id,name, newpw)) return SendClientMessage(playerid,COLOR_RED,"USAGE:{FFFFFF}/setname [id] [name] [password]");
	if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"ERROR:{FFFFFF}Player not connected");

 	new pw[129];
 	WP_Hash(pw,sizeof(pw), newpw);

		if(!dini_Exists(fileName))
        {
        SetPlayerName(id,name);
		dini_Create(Account(id));
        dini_Set(Account(id),"password", pw);
        dini_IntSet(Account(id),"money",0);
        dini_IntSet(Account(id),"color",GetPlayerColor(playerid));
        dini_IntSet(Account(id),"score",0);
        dini_IntSet(Account(id),"admin",0);
 		}
	      else if(dini_Exists(fileName))
		  {
		  SCM(pid, -1, "username already taken");
		  }
return 1;}
it works, but, when I do /setname ingame it always says that the username is taken :/ please help me someone


Re: help +rep - Dayrion - 26.07.2017

Format the file's name after you have checked if id is a valid player