[Tutorial] How to make a register system - DIALOG
#41

This should work:

pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#include <a_samp>
//#include <strtok>
#include <dini>
#include <dudb>
#pragma unused ret_memcpy
#define SERVER_USER_FILE "cslogin/users/%s.ini"
#define COLOR_RED 0xFFF0000FF
#define COLOR_BLUE 0x0000BBAA
#define COLOR_YELLOW 0xFFFF00AA


#if defined FILTERSCRIPT

new NewPlayer[MAX_PLAYERS];
public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
enum pInfo
{
 pAdminLevel,
 pScore,
 pCash,
};
new PlayerInfo [MAX_PLAYERS] [pInfo];
new gPlayerLogged[MAX_PLAYERS];

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYERS],file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),SERVER_USER_FILE,name);
    if(!dini_Exists(file))
    {
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Welcome You are not registered!","You are not registered\nplease register now!","Register","Cancel");
    }
    if(dini_Exists(file))
    {
        ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYERS],file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),SERVER_USER_FILE,name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid] [pAdminLevel]);
        dini_IntSet(file,"Score",PlayerInfo[playerid] [pScore]);
        dini_IntSet(file,"Cash",PlayerInfo[playerid] [pCash]);
    }
    gPlayerLogged[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(NewPlayer[playerid] == 1)
    {
        GivePlayerMoney(playerid,100);
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(response)
        {
            new name[MAX_PLAYER_NAME], file[128], string[128];
            GetPlayerName(playerid, name, sizeof(name));
            format(file, sizeof(file), SERVER_USER_FILE, name);
            if(!strlen(inputtext))return ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Welcome You are not registered!","You are not registered\nplease register now!","Register","Cancel");
            {
                dini_Create(file);
                dini_IntSet(file,"Password",udb_hash(inputtext));
                dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][pAdminLevel] = 0);
                dini_IntSet(file,"Score",PlayerInfo[playerid][pScore] = 0);
                dini_IntSet(file,"Cash",PlayerInfo[playerid][pCash] = 100);
                format(string,sizeof(string),"[LoginSys]: You succesfully registered the name %s with password %s, you have been auto logged in.",name,inputtext);
                SendClientMessage(playerid, COLOR_YELLOW, string);
                gPlayerLogged[playerid] = 1;
                NewPlayer[playerid] = 1;
            }
        else
        {
            Kick(playerid);
        }
    }
    if(dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if(!strlen(inputtext))return ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
        new tmp;
        tmp = dini_Int(file,"Password");
        if(udb_hash(inputtext) != tmp)
        {
            SendClientMessage(playerid,COLOR_RED,"Sorry Wrong Password!");
            ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
        }
        else
        {
            PlayerInfo[playerid] [pAdminLevel] = dini_Int(file,"AdminLevel");
            SetPlayerScore(playerid,PlayerInfo[playerid] [pScore]);
            GivePlayerMoney(playerid,dini_Int(file,"Cash"));
            SendClientMessage(playerid,COLOR_BLUE,"[LoginSys]: Successfully Logged In!");
            NewPlayer[playerid] = 0;
            gPlayerLogged[playerid] = 1;
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
EDIT: I created a new variable "NewPlayer[MAX_PLAYERS]" so that when the player spawns, if they are new, they will get $100 because only putting it in dini will not help. I did not remove the unwanted callbacks because i don't know if this is the 1st stage of developing your GM. Good Luck.
Reply
#42

I have a weird problem. I did everything exactly as you said and I got an error:
Quote:

C:\Users\Kreso\Desktop\SAMP Server\pawno\include\dudb.inc(172) : error 010: invalid function or declaration
C:\Users\Kreso\Desktop\SAMP Server\pawno\include\dudb.inc(173) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.

I even copy-pasted your code in an empty pawno script and same thing happens. Can you help me a bit?

btw, script has 127 lines.
Reply
#43

Post the lines that has the errors.
Reply
#44

Quote:
Originally Posted by Tee
View Post
This should work:

pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#include <a_samp>
//#include <strtok>
#include <dini>
#include <dudb>
#pragma unused ret_memcpy
#define SERVER_USER_FILE "cslogin/users/%s.ini"
#define COLOR_RED 0xFFF0000FF
#define COLOR_BLUE 0x0000BBAA
#define COLOR_YELLOW 0xFFFF00AA


#if defined FILTERSCRIPT

new NewPlayer[MAX_PLAYERS];
public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
enum pInfo
{
 pAdminLevel,
 pScore,
 pCash,
};
new PlayerInfo [MAX_PLAYERS] [pInfo];
new gPlayerLogged[MAX_PLAYERS];

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYERS],file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),SERVER_USER_FILE,name);
    if(!dini_Exists(file))
    {
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Welcome You are not registered!","You are not registered\nplease register now!","Register","Cancel");
    }
    if(dini_Exists(file))
    {
        ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYERS],file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),SERVER_USER_FILE,name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid] [pAdminLevel]);
        dini_IntSet(file,"Score",PlayerInfo[playerid] [pScore]);
        dini_IntSet(file,"Cash",PlayerInfo[playerid] [pCash]);
    }
    gPlayerLogged[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(NewPlayer[playerid] == 1)
    {
        GivePlayerMoney(playerid,100);
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(response)
        {
            new name[MAX_PLAYER_NAME], file[128], string[128];
            GetPlayerName(playerid, name, sizeof(name));
            format(file, sizeof(file), SERVER_USER_FILE, name);
            if(!strlen(inputtext))return ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Welcome You are not registered!","You are not registered\nplease register now!","Register","Cancel");
            {
                dini_Create(file);
                dini_IntSet(file,"Password",udb_hash(inputtext));
                dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][pAdminLevel] = 0);
                dini_IntSet(file,"Score",PlayerInfo[playerid][pScore] = 0);
                dini_IntSet(file,"Cash",PlayerInfo[playerid][pCash] = 100);
                format(string,sizeof(string),"[LoginSys]: You succesfully registered the name %s with password %s, you have been auto logged in.",name,inputtext);
                SendClientMessage(playerid, COLOR_YELLOW, string);
                gPlayerLogged[playerid] = 1;
                NewPlayer[playerid] = 1;
            }
        else
        {
            Kick(playerid);
        }
    }
    if(dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if(!strlen(inputtext))return ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
        new tmp;
        tmp = dini_Int(file,"Password");
        if(udb_hash(inputtext) != tmp)
        {
            SendClientMessage(playerid,COLOR_RED,"Sorry Wrong Password!");
            ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
        }
        else
        {
            PlayerInfo[playerid] [pAdminLevel] = dini_Int(file,"AdminLevel");
            SetPlayerScore(playerid,PlayerInfo[playerid] [pScore]);
            GivePlayerMoney(playerid,dini_Int(file,"Cash"));
            SendClientMessage(playerid,COLOR_BLUE,"[LoginSys]: Successfully Logged In!");
            NewPlayer[playerid] = 0;
            gPlayerLogged[playerid] = 1;
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
EDIT: I created a new variable "NewPlayer[MAX_PLAYERS]" so that when the player spawns, if they are new, they will get $100 because only putting it in dini will not help. I did not remove the unwanted callbacks because i don't know if this is the 1st stage of developing your GM. Good Luck.
You can use my enum and store that NewPlayer thing inside, also create a boolean, no need to waste memory on a small variable >.> thanks anyway.
Reply
#45

True. I did not recognize that.
Reply
#46

I register, then i restart game it ask to register again.
I've created folder named ''myserver'', but in that folder saves nothing. + in that folder is no ''player info files''.
Please help me!

-Tutorial is great, Thanks for sharing.
Reply
#47

^ perhaps you misplaced something, check the filterscript version.
Reply
#48

^ I don't know what i fixed, but i just replaced everything from filterscript and now its work. Thanks for solution.
Reply
#49

All though I allready have a login system this is a very good tutorial Well done.

Just one little thing.
You should put more detail in on what this does. Mention that the folder has to be inside scriptfiles and you can rename the "myserver" to what ever you want, So newbies dont think it has to be called myserver and so they know where the file saves. But apart from that its all good
Code:
#define SERVER_USER_FILE "myserver/%s.ini"
Reply
#50

I like that, good yob men ;
Reply
#51

D:\Documents and Settings\Emrah\Desktop\Red County RP\gamemodes\RC.pwn(7) : fatal error 100: cannot read from file: "dini"

What is problem ?
Reply
#52

when i compile it an error come which is :-

fatal error 100: cannot read from file: "dini"


how can i fix it plz replay
Reply
#53

well, yes perhaps to make a kick cmd: add

pawn Code:
Kick(strval(params));
IF you're using DCMD or ZCMD.
Reply
#54

But if you're not using both?
Reply
#55

Quote:
Originally Posted by Lorenc_
View Post
Create an if statement to the variable : E_ADMIN or AdminLevel

if(PlayerInfo[playerid][AdminLevel] > LEVEL)
{
CODE
}
Oh and it says the 'AdminLevel' is undefined when I compiled it.

Quote:

error 017: undefined symbol "AdminLevel"

How do I define it?

EDIT: Okay, I managed to get it. I think. Used pAdminLevel instead of AdminLevel.
Reply
#56

I suggest you to update the tutorial to one of the new file systems, like Y_Ini, etc. Or even databases with SQLite or MySQL.
We should let Dini die, along with the GodFather script.
Reply
#57

Quote:
Originally Posted by Mean
View Post
I suggest you to update the tutorial to one of the new file systems, like Y_Ini, etc. Or even databases with SQLite or MySQL.
We should let Dini die, along with the GodFather script.
Very true although, i just dont think it'll be worth me giving a SQLite tutorial. I mean i like SQLite and use it all the time.
Reply
#58

Why do I get this error?

Code:
C:\Users\Gaetan\Desktop\SERVER\gamemodes\Test123.pwn(125) : error 017: undefined symbol "gPlayerLogged"
C:\Users\Gaetan\Desktop\SERVER\gamemodes\Test123.pwn(125) : warning 215: expression has no effect
C:\Users\Gaetan\Desktop\SERVER\gamemodes\Test123.pwn(125) : error 001: expected token: ";", but found "]"
C:\Users\Gaetan\Desktop\SERVER\gamemodes\Test123.pwn(125) : error 029: invalid expression, assumed zero
C:\Users\Gaetan\Desktop\SERVER\gamemodes\Test123.pwn(125) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#59

new gPlayerLogged[MAX_PLAYERS];

Add that at the top of your script then it should work.
Reply
#60

Code:
C:\Documents and Settings\Korisnik\Desktop\G.R.P\gamemodes\RCRP.pwn(409) : warning 219: local variable "tmp" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
how to fix this?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)