[HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready)
#1

DUDB was released to have an easy to handle library to save and load data about users.

Even the commands are really damned simple, but still some guys around here, which just copy and paste and can't get it to work then. If you can't add a own command, if you don't know how to call functions (I don't mean Copy n' Paste, I mean know what each line of your source does!) - then please stop reading, get somebody to pay and create the source for you. Its a pitty to see guys not beeing able to code anything and then complaining about not beeing able to cut and paste this. Sorry guys, but this makes somebody angry who thought that this library is really easy as hell.

Example implementation wich saves money (the result of the howto is this script)
o DNick : http://forum.sa-mp.com/index.php?topic=4799

How to add "Position Saving?" - Read the second how to.
How to add "Save kills/death?" - Read the third how to.
How to use "myfolder/name.sav folder structure?" - Read the third how to.

I won't stick at the slow command handling in all default gamemodes, I will use the fast command processor here. So if you are not able to convert your OnPlayerCommandText-Code to the fast command processor-structure, stop and just don't use saving data.

I suggest you read the following text ones to understand how it works. Don't forget to create a folder called 'scriptfiles' in your samp directory to enable file access for the server.

We will develop a simple filterscript with all these features, so you can use this stub-file.

pawn Код:
#include <a_samp>
// for the samp stuff
#include <dutils>
// for the functions dini and dudb need
#include <dudb>
// for the userdatabase, get dudb version 2.0 for this.
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define COLOR_SYSTEM 0xEFEFF7AA

stock SystemMsg(playerid,msg[]) {
 if ((IsPlayerConnected(playerid))&&(strlen(msg)>0)) {
   SendClientMessage(playerid,COLOR_SYSTEM,msg);
 }
 return 1;
}

public OnPlayerCommandText(playerid,cmdtext[]) {
 return false;
}

public OnPlayerConnect(playerid) {
 return false;
}

/*
 * This function will be useful when we need the playername
 * © by DracoBlue 2006
 */

stock PlayerName(playerid) {
 new name[255];
 GetPlayerName(playerid, name, 255);
 return name;
}
We will use SystemMsg for things the system sends. The dcmd-macro is what we use for the fast command processing later.

First of all we need a login/register method.

Nothing easier then this.

pawn Код:
/*
 * /register password
 *
 */

 dcmd_register(playerid,params[]) {

  // The command shouldn't work if we already are authed
  if (PLAYERLIST_authed[playerid]) return SystemMsg(playerid,"Already authed.");

  // The command shouldn't work if an account with this
  // nick already exists
  if (udb_Exists(PlayerName(playerid))) return SystemMsg(playerid,"Account already exists, please use '/login password'.");

  // Did he forgot the password?
  if (strlen(params)==0) return SystemMsg(playerid,"Correct usage: '/register password'");

  // We save the money to the accstate
  if (udb_Create(PlayerName(playerid),params)) return SystemMsg(playerid,"Account successfully created. Login with '/login password' now.");
  return true;

 }
Thats it? Yes thats it!

Want to see the /login?

pawn Код:
/*
 * /login password
 *
 */

 dcmd_login(playerid,params[]) {

  // The command shouldn't work if we already are authed
  if (PLAYERLIST_authed[playerid]) return SystemMsg(playerid,"Already authed.");

  // The command shouldn't work if an account with this
  // nick does not exists
  if (!udb_Exists(PlayerName(playerid))) return SystemMsg(playerid,"Account doesn't exist, please use '/register password'.");

  // Did he forgot the password?
  if (strlen(params)==0) return SystemMsg(playerid,"Correct usage: '/login password'");

  if (udb_CheckLogin(PlayerName(playerid),params)) {
   // Login was correct

   // Following thing is the same like the missing SetPlayerCommand
   GivePlayerMoney(playerid,dUserINT(PlayerName(playerid)).("money")-GetPlayerMoney(playerid));

   PLAYERLIST_authed[playerid]=true;

   return SystemMsg(playerid,"Successfully authed!");
  }
  // Login was incorrect
  return SystemMsg(playerid,"Login failed!");
 }
Of course we need to put a
pawn Код:
new PLAYERLIST_authed[MAX_PLAYERS];
at the beginning, because this will see if the player is authed or not.

We want to set this PLAYERLIST_authed for the player to false, if he enters the game.
pawn Код:
public OnPlayerConnect(playerid) {
 PLAYERLIST_authed[playerid]=false;
 return false;
}
Now we need to register the two commands and we are ready to use the filterscript!
pawn Код:
public OnPlayerCommandText(playerid,cmdtext[]) {
 dcmd(login,5,cmdtext); // because login has 5 characters
 dcmd(register,8,cmdtext); // because register has 8 characters
 return false;
}
One thing is missing, we need to save the money if the player leaves the server.
pawn Код:
public OnPlayerDisconnect(playerid) {
 if (PLAYERLIST_authed[playerid]) {
  // Was loggedin, so save the data!
  dUserSetINT(PlayerName(playerid)).("money",GetPlayerMoney(playerid));
 }
 PLAYERLIST_authed[playerid]=false;
 return false;
}
Thats it.
Reply


Messages In This Thread
[HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by DracoBlue - 31.07.2006, 16:44
Re: [HowTo] Using dudb to save money/stats/whatever - by HoboCop - 31.07.2006, 17:53
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 31.07.2006, 17:57
Re: [HowTo] Using dudb to save money/stats/whatever - by HoboCop - 31.07.2006, 18:12
Re: [HowTo] Using dudb to save money/stats/whatever - by GunLord - 31.07.2006, 18:30
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 31.07.2006, 18:35
Re: [HowTo] Using dudb to save money/stats/whatever - by Roka - 31.07.2006, 18:43
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 01.08.2006, 08:30
Re: [HowTo] Using dudb to save money/stats/whatever - by axelpx - 05.08.2006, 18:36
Re: [HowTo] Using dudb to save money/stats/whatever - by axelpx - 06.08.2006, 09:06
Re: [HowTo] Using dudb to save money/stats/whatever - by axelpx - 06.08.2006, 13:38
Re: [HowTo] Using dudb to save money/stats/whatever - by MadMax - 06.08.2006, 17:27
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 06.08.2006, 17:48
Re: [HowTo] Using dudb to save money/stats/whatever - by Seraphis - 06.08.2006, 20:30
Re: [HowTo] Using dudb to save money/stats/whatever - by Seraphis - 06.08.2006, 20:58
Re: [HowTo] Using dudb to save money/stats/whatever - by Seraphis - 07.08.2006, 03:07
Re: [HowTo] Using dudb to save money/stats/whatever - by smrtak - 08.08.2006, 19:33
Re: [HowTo] Using dudb to save money/stats/whatever - by RMD-06 - 09.08.2006, 04:27
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 09.08.2006, 05:38
Re: [HowTo] Using dudb to save money/stats/whatever - by Ren - 13.08.2006, 09:04
Re: [HowTo] Using dudb to save money/stats/whatever - by Neo_plus - 15.08.2006, 16:37
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 15.08.2006, 17:34
Re: [HowTo] Using dudb to save money/stats/whatever - by Ren - 16.08.2006, 06:42
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 16.08.2006, 21:06
Re: [HowTo] Using dudb to save money/stats/whatever - by smrtak - 17.08.2006, 00:21
Re: [HowTo] Using dudb to save money/stats/whatever - by Ren - 17.08.2006, 01:14
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 17.08.2006, 08:33
Re: [HowTo] Using dudb to save money/stats/whatever - by Ren - 17.08.2006, 08:59
Re: [HowTo] Using dudb to save money/stats/whatever - by smrtak - 17.08.2006, 12:17
Re: [HowTo] Using dudb to save money/stats/whatever - by Mevo - 17.08.2006, 15:13
Re: [HowTo] Using dudb to save money/stats/whatever - by itsme - 17.08.2006, 23:32
Re: [HowTo] Using dudb to save money/stats/whatever - by Mevo - 18.08.2006, 13:08
Re: [HowTo] Using dudb to save money/stats/whatever - by itsme - 18.08.2006, 14:40
Re: [HowTo] Using dudb to save money/stats/whatever - by Mevo - 18.08.2006, 15:03
Re: [HowTo] Using dudb to save money/stats/whatever - by itsme - 18.08.2006, 15:57
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 18.08.2006, 20:02
Re: [HowTo] Using dudb to save money/stats/whatever - by itsme - 18.08.2006, 20:50
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 18.08.2006, 21:06
Re: [HowTo] Using dudb to save money/stats/whatever - by Ren - 19.08.2006, 09:03
Re: [HowTo] Using dudb to save money/stats/whatever - by Mevo - 19.08.2006, 10:21
can i ?? - by egunu - 20.08.2006, 01:47
Re: [HowTo] Using dudb to save money/stats/whatever - by Ren - 20.08.2006, 02:26
Re: [HowTo] Using dudb to save money/stats/whatever - by DracoBlue - 20.08.2006, 17:05
where should i input these scripts? - by egunu - 21.08.2006, 02:15
Re: [HowTo] Using dudb to save money/stats/whatever - by bb1000 - 18.09.2006, 00:31
Re: [HowTo] Using dudb to save money/stats/whatever - by bb1000 - 18.09.2006, 02:37
Re: [HowTo] Using dudb to save money/stats/whatever - by bb1000 - 18.09.2006, 03:00
Re: [HowTo] Using dudb to save money/stats/whatever - by bb1000 - 18.09.2006, 04:10
Re: [HowTo] Using dudb to save money/stats/whatever - by bb1000 - 18.09.2006, 04:23
Re: [HowTo] Using dudb to save money/stats/whatever - by bb1000 - 18.09.2006, 04:56
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Sacky - 12.12.2006, 09:04
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Neo_plus - 12.12.2006, 09:33
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Nitroglycerine - 12.12.2006, 10:28
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Neo_plus - 12.12.2006, 10:30
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by [NR]Luke - 12.12.2006, 16:07
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Neo_plus - 13.12.2006, 09:48
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by [NR]Luke - 13.12.2006, 17:53
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Nitroglycerine - 13.12.2006, 19:57
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by [NR]Luke - 13.12.2006, 20:12
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Neo_plus - 14.12.2006, 06:39
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Donny_k - 14.12.2006, 09:28
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Neo_plus - 15.12.2006, 06:40
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by WSAD_RealNapster - 03.01.2007, 15:32
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Webghost - 03.01.2007, 16:39
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by [NR]Luke - 03.01.2007, 18:16
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by WSAD_RealNapster - 04.01.2007, 15:51
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 05.01.2007, 12:29
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by fandos - 19.01.2007, 01:29
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Pixels^ - 19.01.2007, 01:33
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by [xA]Ramjet - 19.01.2007, 01:39
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Claude_Speed - 30.01.2007, 16:41
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Claude_Speed - 30.01.2007, 17:15
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by yom - 30.01.2007, 19:54
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by dracar - 31.01.2007, 03:07
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 31.01.2007, 09:09
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Delit - 02.02.2007, 10:38
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Tommy_Vercetty - 05.02.2007, 13:49
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 05.02.2007, 13:54
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by Tommy_Vercetty - 05.02.2007, 13:55
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 05.02.2007, 13:57
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by El Burro - 16.06.2007, 11:18
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by miokie - 16.06.2007, 12:50
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 16.06.2007, 13:23
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by miokie - 16.06.2007, 13:27
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 16.06.2007, 13:31
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by miokie - 16.06.2007, 14:14
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by n0ah - 16.06.2007, 16:42
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by miokie - 17.06.2007, 11:40
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by DracoBlue - 17.06.2007, 12:04
Re: [HowTo] Using dudb 2.0 to save money/stats/whatever - by miokie - 17.06.2007, 14:03
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by arnutisz - 29.01.2008, 18:09
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by spl1fter - 19.02.2008, 13:34
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by PyroAnger - 09.03.2008, 18:29
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by El0vric - 10.03.2008, 15:08
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by ZequeZ - 21.03.2008, 19:09
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by darktom - 25.03.2008, 11:34
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by DracoBlue - 25.03.2008, 11:37
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by darktom - 25.03.2008, 12:34
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by whooper - 10.04.2008, 10:47
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 10.04.2008, 12:24
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by whooper - 10.04.2008, 14:13
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 10.04.2008, 14:31
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by whooper - 10.04.2008, 14:45
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 10.04.2008, 15:16
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by whooper - 10.04.2008, 17:17
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 10.04.2008, 17:41
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by whooper - 10.04.2008, 17:46
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Francis[French] - 10.04.2008, 19:33
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by whooper - 10.04.2008, 20:36
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 11.04.2008, 09:55
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by JaYmE - 11.04.2008, 19:45
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Francis[French] - 12.04.2008, 01:01
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by JaYmE - 12.04.2008, 01:16
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 12.04.2008, 10:57
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by JaYmE - 13.04.2008, 07:57
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 19.04.2008, 16:01
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Zh3r0 - 30.04.2008, 18:51
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 30.04.2008, 19:40
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Zh3r0 - 01.05.2008, 06:13
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by lea_VA - 04.05.2008, 20:14
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by arnutisz - 17.02.2009, 16:00
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Nero_3D - 17.02.2009, 20:02
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by iBored1x1 - 18.02.2009, 01:59
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by arnutisz - 18.02.2009, 16:22
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by JaYmE - 18.02.2009, 23:33
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by arnutisz - 19.02.2009, 18:40
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Flo_White - 28.02.2009, 21:56
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by JaYmE - 01.03.2009, 02:04
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by DracoBlue - 01.03.2009, 08:41
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Flo_White - 01.03.2009, 11:49
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by BMUK - 10.03.2010, 07:58
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Oxside - 10.03.2010, 08:02
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by BMUK - 10.03.2010, 08:13
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by CJ101 - 10.03.2010, 09:38
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by BMUK - 10.03.2010, 09:48
Re: [HowTo] Using dudb to save money/stats/whatever - by Micko9 - 12.03.2010, 17:39
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by ivanorezac - 29.03.2010, 21:54
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by ruckfules99 - 06.04.2010, 20:02
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by DracoBlue - 06.04.2010, 20:23
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by ruckfules99 - 06.04.2010, 21:32
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Micko9 - 09.04.2010, 07:11
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Grim_ - 09.04.2010, 07:12
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by [WF]Demon - 11.04.2010, 17:48
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by ruckfules99 - 11.04.2010, 17:54
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by M4S7ERMIND - 11.04.2010, 18:06
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by [WF]Demon - 21.04.2010, 21:44
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by DracoBlue - 22.04.2010, 06:44
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by [WF]Demon - 22.04.2010, 07:52
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by DracoBlue - 22.04.2010, 08:02
Re: [HowTo] Using dudb 2.4 to save money/stats/whatever (0.2#Ready) - by Kyle - 28.04.2010, 06:39

Forum Jump:


Users browsing this thread: 1 Guest(s)