Two Small Problems
#1

1) There is no error in this code but when the player connects it says something like:

Welcome
|

Код:
  new Name[MAX_PLAYER_NAME];
  new WelcSTR[56];
  format(WelcSTR, sizeof(WelcSTR), "~y~Welcome ~n~~w~%s", Name);
 	GameTextForPlayer(playerid,WelcSTR,5000,1);
2) How do i change this so the file that is created will be a .TXT in a seperate folder within scriptfiles
Код:
if (!dini_Exists(udb_encode(PlayerName)))
      {
        dini_Create(udb_encode(PlayerName));
I have tried PlayerName.txt but then it just shows errors.
eg, /scriptfiles/users/<PlyaerName>.txt
Reply
#2

You forgot to get the player's name at first.

pawn Код:
new Name[MAX_PLAYER_NAME];
new WelcSTR[56];
GetPlayerName(playerid, Name, sizeof(Name));
format(WelcSTR, sizeof(WelcSTR), "~y~Welcome ~n~~w~%s", Name);
GameTextForPlayer(playerid,WelcSTR,5000,1);
Reply
#3

Stupid mistake. Actually i did have GetPlayerName(playerid, Name, sizeof(Name)); but it was below the gametext. Thats why it wasnt working:
Код:
public OnPlayerConnect(playerid)
{
	ClearVars(playerid);
	SyncCheckpoints(playerid);
	ReqClass[playerid] = 0;
  Logged[playerid] = 0;
  PlayerInJob[playerid] = 0;
  InTutorial[playerid] = 0;
	TutorialPage[playerid] = 0;
  new Name[MAX_PLAYER_NAME];
  new WelcSTR[56];
  format(WelcSTR, sizeof(WelcSTR), "~y~Welcome ~n~~w~%s", Name);
  	GameTextForPlayer(playerid,WelcSTR,5000,1);
	new String[128];
	GetPlayerName(playerid, Name, sizeof(Name));
	format(String, sizeof(String), "%s Has Joined The Server!", Name);
  SendClientMessageToAll(0xAAAAAAAA, String);
  return 1;
}
Anyway, have you any idea for the second problem...
Reply
#4

pawn Код:
if (!dini_Exists(udb_encode(PlayerName)))
{
    new filepath[28];
    format(filepath, 28, "\\Users\\%s.txt", PlayerName)
    dini_Create(filepath);
}
Reply
#5

So now i have this.

Код:
if (!dini_Exists(udb_encode(PlayerName)))
      {
	  new FilePath[28];
	format(FilePath, 28, "\\Truckers\\%s.txt", PlayerName);
	dini_Create(FilePath);
        dini_IntSet(udb_encode(PlayerName), "Password", udb_hash(tmp));
        dini_IntSet(udb_encode(PlayerName), "AdminLevel", 0);
        dini_IntSet(udb_encode(PlayerName), "Money", 2500);
        dini_IntSet(udb_encode(PlayerName), "TruckType", 413);
        dini_IntSet(udb_encode(PlayerName), "JobsDone", 0);
        dini_IntSet(udb_encode(PlayerName), "JobLevel", 1);
        dini_IntSet(udb_encode(PlayerName), "Mission", 1);
        
        TruckerSkin[playerid] = GetPlayerSkin(playerid);
        dini_IntSet(udb_encode(PlayerName), "Skin", TruckerSkin[playerid]);
        
        format(string, sizeof(string), "Account %s Created! You Can Now Login With /login %s", PlayerName, tmp);
        SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
      }
Will i have to change the (PlayerName) to the filepath?

dini_IntSet(udb_encode(PlayerName), "AdminLevel", 0);
dini_IntSet(udb_encode(FilePath "AdminLevel", 0);
Reply
#6

Change 28 to 31 (since truckers is longer than users)
and you shall change udb_encode(PlayerName) to FilePath
Reply
#7

Now it will onl create the file but not write the values.
Here is thw whole command:
pawn Код:
if(strcmp(cmd, "/register", true) == 0)
  {
    if(ReqClass[playerid] != 0)
    {
        SendClientMessage(playerid, COLOUR_RED, "You Can Only Register After The Class Selection!");
        return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
      SendClientMessage(playerid, COLOUR_YELLOW, "USAGE: /register (password)");
            }else{
            if (!dini_Exists(udb_encode(PlayerName)))
      {
                new FilePath[31];
                format(FilePath, 31, "\\Truckers\\%s.txt", PlayerName);
                dini_Create(FilePath);
               
        dini_IntSet(udb_encode(FilePath), "Password", udb_hash(tmp));
        dini_IntSet(udb_encode(FilePath), "AdminLevel", 0);
        dini_IntSet(udb_encode(FilePath), "Money", 2500);
        dini_IntSet(udb_encode(FilePath), "TruckType", 413);
        dini_IntSet(udb_encode(FilePath), "JobsDone", 0);
        dini_IntSet(udb_encode(FilePath), "JobLevel", 1);
        dini_IntSet(udb_encode(FilePath), "Mission", 1);

        TruckerSkin[playerid] = GetPlayerSkin(playerid);
        dini_IntSet(udb_encode(FilePath), "Skin", TruckerSkin[playerid]);

        format(string, sizeof(string), "Account %s Created! You Can Now Login With /login %s", PlayerName, tmp);
        SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
          }else{
        format(string, sizeof(string), "%s Is Already Registered.", PlayerName,tmp);
        SendClientMessage(playerid, COLOUR_RED, string);
      }
    }
    return 1;
  }
Reply
#8

pawn Код:
if(strcmp(cmd, "/register", true) == 0)
{
    if(ReqClass[playerid] != 0)
        return SendClientMessage(playerid, COLOUR_RED, "You Can Only Register After The Class Selection!");
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
        return SendClientMessage(playerid, COLOUR_YELLOW, "USAGE: /register (password)");
    format(string, sizeof(string), "\\Truckers\\%s.txt", PlayerName);
    if(dini_Exists(string))
    {
        format(string, sizeof(string), "%s Is Already Registered.", PlayerName, tmp);
        return SendClientMessage(playerid, COLOUR_RED, string);
    }
    if(!dini_Create(string)) return print("Error: Directory \"\\Trucker\\\" doesnt exist!");       
    dini_IntSet(string, "Password", udb_hash(tmp));
    dini_IntSet(string, "AdminLevel", 0);
    dini_IntSet(string, "Money", 2500);
    dini_IntSet(string, "TruckType", 413);
    dini_IntSet(string, "JobsDone", 0);
    dini_IntSet(string, "JobLevel", 1);
    dini_IntSet(string, "Mission", 1);
    dini_IntSet(string, "Skin", (TruckerSkin[playerid] = GetPlayerSkin(playerid)));
    format(string, sizeof(string), "Account %s Created! You Can Now Login With /login %s", PlayerName, tmp);
    return SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
}
Reply
#9

THANKS, would you be able to do the same with the login command please:

pawn Код:
if(strcmp(cmd, "/login", true) == 0)
    {
    if(ReqClass[playerid] != 0)
    {
        SendClientMessage(playerid, COLOUR_RED, "You Can Only Login After The Class Selection!");
        return 1;
    }
    if(Logged[playerid] == 1)
    {
        SendClientMessage(playerid, COLOUR_RED, "You Are Already Logged In!");
        return 1;
    }

    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid, COLOUR_YELLOW, "USAGE: /login [password]");
    }
    else
    {
    if (dini_Exists(udb_encode(PlayerName)))
    {
        tmp2 = dini_Get(udb_encode(PlayerName), "Password");
        if (udb_hash(tmp) != strval(tmp2))
        {
            SendClientMessage(playerid, COLOUR_RED, "Wrong/Invalid Password!");
        }
        else
        {
            Logged[playerid] = 1;
            Money[playerid] = dini_Int(udb_encode(PlayerName), "Money");
            AdminLevel[playerid] = dini_Int(udb_encode(PlayerName), "AdminLevel");
            TruckType[playerid] = dini_Int(udb_encode(PlayerName), "TruckType");
            JobsDone[playerid] = dini_Int(udb_encode(PlayerName), "JobsDone");
            JobLevel[playerid] = dini_Int(udb_encode(PlayerName), "JobLevel");
            Mission[playerid] = dini_Int(udb_encode(PlayerName), "Mission");
            format(string, sizeof(string), "%s, You Are Now Logged In. You Are Admin Level %d And Have $%d", PlayerName, AdminLevel[playerid], Money[playerid]);
            SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
            new Stats[128];
            format(Stats, sizeof(Stats), "[STATS] Job Level: %d | Truck ID: %d | Jobs Finished: %d | Mission Number: %d", JobLevel[playerid], TruckType[playerid], JobsDone[playerid], Mission[playerid]);
            SendClientMessage(playerid, COLOUR_GREEN, Stats);
            GivePlayerMoney(playerid, Money[playerid]);
            TruckerSkin[playerid] = dini_Int(udb_encode(PlayerName), "Skin");
            SetPlayerSkin(playerid,TruckerSkin[playerid]);
        }
    }
    else
    {
    format(string, sizeof(string), "You Are Not Registered. Type /register [password] To Create An Account!", PlayerName);
    SendClientMessage(playerid, COLOUR_RED, string);
    }
    }
    return 1;
}
Reply
#10

just look at it and try by yourself, you wont learn if someone else do it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)