SA-MP Forums Archive
[A-System] Random code for login help. - 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: [A-System] Random code for login help. (/showthread.php?tid=576844)



[A-System] Random code for login help. - NoDi522 - 07.06.2015

Hey guys. I made random code number for admin login, and the problem is that randomator generates just one number instead of 5 field.

CODE:

PHP код:
new randomkod random(9);
format(poruka,sizeof(poruka),"{FFFFFF}Cestitamo. Postavljani ste na administracijsku poziciju levela: "COLOR_WG"%d.{FFFFFF}\nTitulu vam je dodjelio vlasnik"COLOR_ZUTA" %s.\n{FFFFFF} Zelimo vam svu srecu u nasem ADMIN teamu.\n\n"COLOR_CRVENA"[VAZNO]:{FFFFFF}\nDolje navedeni kod zapisite/zapamtite jer cete prilikom logiranja morati to upisati.\n%d%d%d%d%d",level,name2,KOD);
            
strcat(statut,poruka);
PlayerInfo[id][pKod] = format(KOD,sizeof(KOD),"%d%d%d%d%d",randomkod,randomkod,randomkod,randomkod,randomkod); 
Should i use "KOD" five times at the end ?


Re: [A-System] Random code for login help. - shadowdog - 07.06.2015

Quote:
Originally Posted by NoDi522
Посмотреть сообщение
Hey guys. I made random code number for admin login, and the problem is that randomator generates just one number instead of 5 field.

CODE:

PHP код:
new randomkod random(9);
format(poruka,sizeof(poruka),"{FFFFFF}Cestitamo. Postavljani ste na administracijsku poziciju levela: "COLOR_WG"%d.{FFFFFF}\nTitulu vam je dodjelio vlasnik"COLOR_ZUTA" %s.\n{FFFFFF} Zelimo vam svu srecu u nasem ADMIN teamu.\n\n"COLOR_CRVENA"[VAZNO]:{FFFFFF}\nDolje navedeni kod zapisite/zapamtite jer cete prilikom logiranja morati to upisati.\n%d%d%d%d%d",level,name2,KOD);
            
strcat(statut,poruka);
PlayerInfo[id][pKod] = format(KOD,sizeof(KOD),"%d%d%d%d%d",randomkod,randomkod,randomkod,randomkod,randomkod); 
Should i use "KOD" five times at the end ?
You are using the same random for all kods, you should make a different random for every single one.

PHP код:
format(poruka,sizeof(poruka),"{FFFFFF}Cestitamo. Postavljani ste na administracijsku poziciju levela: "COLOR_WG"%d.{FFFFFF}\nTitulu vam je dodjelio vlasnik"COLOR_ZUTA" %s.\n{FFFFFF} Zelimo vam svu srecu u nasem ADMIN teamu.\n\n"COLOR_CRVENA"[VAZNO]:{FFFFFF}\nDolje navedeni kod zapisite/zapamtite jer cete prilikom logiranja morati to upisati.\n%d%d%d%d%d",level,name2,KOD);
            
strcat(statut,poruka);
PlayerInfo[id][pKod] = format(KOD,sizeof(KOD),"%d%d%d%d%d",random(9),random(9),random(9),random(9),random(9)); 



Re: [A-System] Random code for login help. - NoDi522 - 07.06.2015

Hm nothing changed i just got one field.
Here's my code:

PHP код:
CMD:makeadmin(playerid,params[])
{
    new 
KOD[256],id,level,msg[128],msg3[256],name[MAX_PLAYER_NAME],name2[MAX_PLAYER_NAME];
    if(!
IsPlayerConnected(playerid)) return SendClientMessage(playerid0xFF0000"{F81414}Greska:{FFFFFF} Niste ulogirani na server.");
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid0xFF0000"{F81414}Greska:{FFFFFF} Nemate dozvolu za tu komandu.");
    if(
sscanf(params,"ud",id,level)) return SendClientMessage(playerid,-1,""COLOR_CRVENA"Syntax |{FFFFFF} /makeadmin [ID/Ime] [Level]");
    if(
level 5) return SendClientMessage(playerid0xFF0000,"{F81414}Greska:{FFFFFF} Maximalan level admin za dodijelu je{00C0FF} 5.");
    
GetPlayerName(id,name,sizeof(name));
    
GetPlayerName(playerid,name2,sizeof(name2));
    
    new 
poruka[512],statut[64];
    new 
randomkod random(9);
    
    
format(poruka,sizeof(poruka),"{FFFFFF}Cestitamo. Postavljani ste na administracijsku poziciju levela: "COLOR_WG"%d.{FFFFFF}\nTitulu vam je dodjelio vlasnik"COLOR_ZUTA" %s.\n{FFFFFF} Zelimo vam svu srecu u nasem ADMIN teamu.\n\n"COLOR_CRVENA"[VAZNO]:{FFFFFF}\nDolje navedeni kod zapisite/zapamtite jer cete prilikom logiranja morati to upisati.\n%d%d%d%d%d",level,name2,random(9),random(9),random(9),random(9),random(9));
     
strcat(statut,poruka);
    
ShowPlayerDialog(id,DIALOG_ADMIN_CONG,DIALOG_STYLE_MSGBOX,""COLOR_ZUTA"AdminTeam",poruka,"Uredu","");
    
/* Proredak */
    
format(msg,sizeof(msg),""COLOR_WG"WG:{FFFFFF} Postavili ste admina igracu{FFF1AF} %s {FFFFFF}na levelu:{FFF1AF} %d"name,level);
    
SendClientMessage(playerid,0xFFFFFF,msg);
    
format(msg3,sizeof(msg3),""COLOR_CRVENA"[ ACC ]:{FFFFFF} %s je postavio admina %s na levelu"COLOR_WG" %d",name2,name,level);
    
SendAdminMessage(-1,msg3);
            
    
PlayerInfo[id][pAdministrator] = level;
    
PlayerInfo[id][pKod] = format(KOD,sizeof(KOD),"%d%d%d%d%d",random(9),random(9),random(9),random(9),random(9));
    new 
INI:File INI_Open(UserPath(id));
    
INI_SetTag(File,"data");
    
INI_WriteInt(File,"Administrator",PlayerInfo[id][pAdministrator]);
    
INI_WriteInt(File,"Kod",PlayerInfo[id][pKod]);
    
INI_Close(File);
    return 
1;




Re: [A-System] Random code for login help. - Vince - 07.06.2015

If you want a random 5 digit number you don't have to call random 5 times ... That's just silly. Simply use random(100000) to generate a number between 0 and 99999. Then display using "%05d". And since "Kod" (whatever that may mean) appears to be an integer, all you need is:
pawn Код:
PlayerInfo[id][pKod] = random(100000)



Re: [A-System] Random code for login help. - NoDi522 - 07.06.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
If you want a random 5 digit number you don't have to call random 5 times ... That's just silly. Simply use random(100000) to generate a number between 0 and 99999. Then display using "%05d". And since "Kod" (whatever that may mean) appears to be an integer, all you need is:
pawn Код:
PlayerInfo[id][pKod] = random(100000)
Thank you.


Re: [A-System] Random code for login help. - JaydenJason - 07.06.2015

nono, using that random it could give out 1 as "kod" as well, try using this;

Код:
RandomEx(min, max) // By ******
{
    return random(max - min) + min;
}

PlayerInfo[id][pKod] = RandomEx(10000, 99999);