Tuesday, November 16, 2010

SAMP Scripting Tutorial: Login/Register Script

Here is the code

// Include this file
#include 

// OnDialogResponse
switch(dialogid)
{
 case 3:
 {
  if(response==1)
  {
   switch(listitem)
   {
    case 0:
    {
     GetPlayerPos(playerid,x,y,z);
     CreateVehicle(432,x-3.0,y,z,0.0,1,1,300);
    }
    case 1:
    {
     GetPlayerPos(playerid,x,y,z);
     CreateVehicle(407,x-3.0,y,z,0.0,1,3,300);
    }
    case 2:
    {
     GetPlayerPos(playerid,x,y,z);
     CreateVehicle(411,x-3.0,y,z,0.0,1,0,300);
    }
    case 3:
    {
     GetPlayerPos(playerid,x,y,z);
     CreateVehicle(451,x-3.0,y,z,0.0,0,1,300);
    }
    case 4:
    {
     GetPlayerPos(playerid,x,y,z);
     CreateVehicle(406,x-3.0,y,z,0.0,1,1,300);
    }
   }
  }
 }
 case 1:
 {
  if(response==1)
  {
   if(strcmp(ReadPlayer(1,playerid),inputtext,false)!=0)
   {
    SendClientMessage(playerid,WHITE,"Invalid Password!");
    ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login","Welcome! Please Login!","Login","Exit");
   }
   else TogglePlayerSpectating(playerid,0);
  }
  else Kick(playerid);
 }
 case 2:
 {
  if(response==1)
  {
   WritePlayer(inputtext,playerid,true);
   TogglePlayerSpectating(playerid,0);
  }
  else Kick(playerid);
 }
}

// OnPlayerConnect
TogglePlayerSpectating(playerid,1);
new string[256], name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(string,256,"~r~Hello %s !",name);
GameTextForPlayer(playerid,string,10000,6);
format(string,256,"Players/%s.ini",name);
if(fexist(string))
{
 ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login","Welcome! Please Login!","Login","Exit");
}
else
{
 ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Register","Welcome! Please Register!","Register","Exit");
}

// ReadWrite Player Functions
ReadPlayer(line,playerid)
{
 new string[256],name[MAX_PLAYER_NAME];
 new File:player;
 GetPlayerName(playerid,name,sizeof(name));
 format(string,256,"Players/%s.ini",name);
 player = fopen(string, io_read);
 for(new i=1; i<=line; i++)
 {
  fread(player,string);
  if(line==i)
  {fclose(player); return string;}
 }
 return string;
}

WritePlayer(text[],playerid, bool:filestart)
{
 new string[256],name[MAX_PLAYER_NAME];
 new File:player;
 GetPlayerName(playerid,name,sizeof(name));
 format(string,256,"Players/%s.ini",name);
 player = fopen(string, io_append);
 if(filestart)
 {
  fwrite(player,text);
 }
 else
 {
  format(string,256,"\n%s",text);
  fwrite(player,string);
 }
 fclose(player);
}

23 comments:

  1. why i cant do it and were can i find the first one tutorial?

    ReplyDelete
  2. Here's the first tutorial: http://thedarkjoker94.cer33.com/?p=312

    ReplyDelete
  3. It won't work, because he included file.inc, which you don't have...

    ReplyDelete
  4. I don't know why, i've follow all the video then copy paste your script and my script don,t work... can someone help me?

    ReplyDelete
  5. i get 10 of these errors :S
    "\GM.pwn(460) : error 017: undefined symbol "x""
    code:
    "CreateVehicle(406,x-3.0,y,z,0.0,1,1,300);"
    please help

    ReplyDelete
  6. I also get errors when I compiled it.

    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(250) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(251) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(255) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(256) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(260) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(261) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(265) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(266) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(270) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(271) : error 017: undefined symbol "x"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(282) : error 017: undefined symbol "WHITE"
    C:\Users\Michael\Desktop\SAMP Client\gamemodes\RP script.pwn(299) : error 010: invalid function or declaration
    Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


    12 Errors.

    ReplyDelete
  7. on the beginnig of "OnDialogResponse", add the following: "new Float:x,Float:y,Float:z;"

    ReplyDelete
  8. It says "invalid statement; not in switch" and "expression has no effect"

    ReplyDelete
  9. How to fix this? PLS help :(

    D:\samp03e_svr_win32\gamemodes\FAILS.pwn(106) : error 021: symbol already defined: "string"
    D:\samp03e_svr_win32\gamemodes\FAILS.pwn(397) : error 017: undefined symbol "WHITE"
    D:\samp03e_svr_win32\gamemodes\FAILS.pwn(453) : error 010: invalid function or declaration

    ReplyDelete
  10. Can I just copy paste it in PAWNO ?

    ReplyDelete
  11. And my PAWNO is not function! HELP!

    ReplyDelete
  12. i have 2 error
    warning 203: symbol is never used: "ReadPlayer"
    warning 203: symbol is never used: "WritePlayer"

    ReplyDelete
  13. Indonesia

    Terimakasih Banyak Atas Script Mu Itu Thanks Saya Senang Ada Code Yang Kurang Dari Script " SAMP Scripting Tutorial: Login/Register Script "
    Yaitu Kamu Tambahkan #define WHITE 0xFFFFFFFF Baru Gak Ada Yang Eror
    Bukti Nya Saya Test Berhasil
    " Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase "

    Terimaksih Banyak :D

    ReplyDelete
  14. English

    Many Thanks For Your Script Thanks I'm Glad It Was Missing from the Script Code "SAMP Scripting Tutorial: Login / Register Script"
    Ie You add # define WHITE 0xFFFFFFFF New Gak None Error
    His evidence I Test Successful
    "Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase"

    Thank you very much :D

    ReplyDelete
  15. I gett 2 errors,i used the code:

    format(string,256,"Players/%s.ini",name);
    if(fexist(string))

    and got this:

    C:\Users\Paradox\Desktop\Top secret\gamemodes\gamemodsr.pwn(85) : error 017: undefined symbol "string"
    C:\Users\Paradox\Desktop\Top secret\gamemodes\gamemodsr.pwn(86) : error 017: undefined symbol "string"

    WHAT SHOULD I DO???? PLS HELP ME!!!

    ReplyDelete
  16. where i can find Tutorial.pwn?

    ReplyDelete
  17. PLEAS HELP ME!!!!!! I HAVE 1 ERROR

    fatal error 100: cannot read from file: ""

    ReplyDelete
  18. the server always got crashed after i register, and it didnt create the .ini file

    ReplyDelete