age&gender selection [help]
#6

PHP Code:
#include <a_samp>
#include <YSI\y_ini>
#include <zcmd>
#define spd ShowPlayerDialog
#define max_players 40
enum {
    
d_log,
    
d_reg,
    
d_age,
    
d_gender,
};
enum uEnum{
    
PW,
    
Age,
    
Gender,
};
new 
uInfo[max_players][uEnum];
new 
bool:LoggedIn[max_players];
UserName(pid){
    new 
str[24];
    
GetPlayerName(pid,str,sizeof(str));
    return 
str;
}
UserPath(pid){
    new 
str[60];
    
format(str,sizeof(str),"users/%s.ini",UserName(pid));
    return 
str;
}
udb_hash(buf[]) {
    new 
length=strlen(buf);
    new 
s1 1;
    new 
s2 0;
    new 
n;
    for (
n=0n<lengthn++){
       
s1 = (s1 buf[n]) % 65521;
       
s2 = (s2 s1)     % 65521;
    }
    return (
s2 << 16) + s1;
}
main(){}
public 
OnGameModeInit(){
    for(new 
i20i++)AddPlayerClass(10+i1958.37831343.157215.3746269.14250,0,0,0,0,0);
    return 
1;
}
public 
OnPlayerConnect(playerid){
    
LoggedIn[playerid]=false;
    if(
fexistUserPath(playerid) )){
        
INI_ParseFileUserPath(playerid),"load_user_%s",.bExtra true, .extra playerid );
        
spd(playerid,d_log,DIALOG_STYLE_PASSWORD,"Login","{ffffff}You own account, to login just enter your password.","Login","Kick");
    }else{
        
spd(playerid,d_gender,DIALOG_STYLE_MSGBOX,"Register","{ffffff}Choose your gender.","Male","Female");
    }
    return 
1;
}
public 
OnPlayerRequestClass(playeridclassid){
    if(
LoggedIn[playerid]==false){
        
SendClientMessage(playerid,-1,"You must be logged in!");
        return 
0;
    }
    
SetPlayerPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraLookAt(playerid1958.37831343.157215.3746);
    return 
1;
}
public 
OnPlayerRequestSpawn(playerid){
    if(
LoggedIn[playerid]==false){
        
SendClientMessage(playerid,-1,"You must be logged in!");
        return 
0;
    }
    return 
1;
}
forward load_user_info(pid,name[],value[]);
public 
load_user_info(pid,name[],value[]){
    
INI_Int("pw",uInfo[pid][PW]);
    
INI_Int("age",uInfo[pid][Age]);
    
INI_Int("gender",uInfo[pid][Gender]);
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[]){
    switch(
dialogid){
        case 
d_log:{
            if(!
response)return Kick(playerid);
            if(
uInfo[playerid][PW]!=udb_hash(inputtext))return spd(playerid,d_log,DIALOG_STYLE_PASSWORD,"Login","{FF0000}You entered wrong password!\n{FFFFFF}You own account, to login just enter your password.","Login","Kick");
            
LoggedIn[playerid]=true;
            
SendClientMessage(playerid,-1,"You successfully logged in!");
        }
        case 
d_gender:{
            
uInfo[playerid][Gender]=response;
            
spd(playerid,d_age,DIALOG_STYLE_INPUT,"Register","{ffffff}Enter your character age.","Okey","Kick");
        }
        case 
d_age:{
            if(!
response)return Kick(playerid);
            if(
strval(inputtext)<18||strval(inputtext)>99)return spd(playerid,d_age,DIALOG_STYLE_INPUT,"Register","{ff0000}Age must be between 18 to 99!\n{ffffff}Enter your character age.","Okey","Kick");
            
uInfo[playerid][Age]=strval(inputtext);
            
spd(playerid,d_reg,DIALOG_STYLE_PASSWORD,"Register","{ffffff}Enter your future password.","Register","Kick");
        }
        case 
d_reg:{
            if(!
response)return Kick(playerid);
            if(
strlen(inputtext)<3||strlen(inputtext)>20)return spd(playerid,d_reg,DIALOG_STYLE_MSGBOX,"Register","{ff00000}Pw must contain 3 to 20 characters!\n{ffffff}Enter your future password.","Register","Kick");
            new 
INI:file INI_Open(UserPath(playerid));
            
INI_SetTag(file,"info");
            
INI_WriteInt(file,"pw",udb_hash(inputtext));
            
INI_WriteInt(file,"gender",uInfo[playerid][Gender]);
            
INI_WriteInt(file,"age",uInfo[playerid][Age]);
            
INI_Close(file);
            
LoggedIn[playerid]=true;
            
SendClientMessage(playerid,-1,"You successfully registered your account!");
        }
    }
    return 
1;
}
CMD:stats(pid){    
    new 
str[30];
    
format(str,sizeof(str),"Gender: %s | Age: %d",(uInfo[pid][Gender])?("Male"):("Female"),uInfo[pid][Age]);
    
SendClientMessage(pid,-1,str);
    return 
1;

Reply


Messages In This Thread
age&gender selection [help] - by Lukasz56 - 23.06.2016, 10:52
Re: age&gender selection [help] - by Dayrion - 23.06.2016, 11:13
Re: age&gender selection [help] - by Lukasz56 - 23.06.2016, 11:21
Re: age&gender selection [help] - by EclipseWho - 23.06.2016, 11:22
Re: age&gender selection [help] - by Lukasz56 - 23.06.2016, 11:35
Re: age&gender selection [help] - by CodeStyle175 - 23.06.2016, 11:52
Re: age&gender selection [help] - by PrO.GameR - 23.06.2016, 15:16
Re: age&gender selection [help] - by Dayrion - 23.06.2016, 16:03

Forum Jump:


Users browsing this thread: 1 Guest(s)