PDA

View Full Version : Dini issue


Ananisiki
19/03/2014, 04:42 PM
~~~~~~~~~~

MP2
19/03/2014, 04:55 PM
Stop using dini. It's old and VERY inefficient. Use y_ini.

Ananisiki
20/03/2014, 05:05 AM
My gm is dini so thats why i use dini...

MythicalMarauder
20/03/2014, 07:17 AM
You can change dini to y_ini..

VishvaJeet
20/03/2014, 07:29 AM
enum PlayerStats
{
FavSkin
}
pStats[MAX_PLAYERS][PlayerStats];



public OnPlayerConnect(playerid)
{
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));

if(!dini_Exists(file))
{
dini_Create(file);
dini_IntSet(file, "FavSkin", 300);
return 1;
}
if(dini_Exists(file))
{
if(dini_Int(file, "FavSkin") < 300)
pStats[playerid][FavSkin] = dini_Int(file, "FavSkin");
return 1;
}
}

public OnPlayerSpawn(playerid)
{
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));
if(dini_Exists(file))
{
SetPlayerSkin(playerid, pStats[playerid][FavSkin]);
}
return 1;
}

CMD:favouriteskin(playerid, params[])
{
#pragma unused params
if(Dead[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "You Cannot Use This Command When Dead.");
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));
dini_IntSet(file, "FavSkin", GetPlayerSkin(playerid));
pStats[playerid][FavSkin] = GetPlayerSkin(playerid);
SendClientMessage(playerid, COLOR_PINK, "You Have Successfully Saved Your Skin.");
return 1;
}

Ananisiki
20/03/2014, 11:55 AM
Still crashing.....

Sascha
20/03/2014, 12:11 PM
enum PlayerStats
{
FavSkin
}
pStats[MAX_PLAYERS][PlayerStats];



should be

enum PlayerStats
{
FavSkin
}
new pStats[MAX_PLAYERS][PlayerStats];

VishvaJeet
20/03/2014, 12:49 PM
oh yes i forgot to add new

Ananisiki
20/03/2014, 01:01 PM
Already had that

Macronix
20/03/2014, 01:29 PM
Here, this works like a charm:

enum PlayerStats
{
FavSkin
}
new pStats[MAX_PLAYERS][PlayerStats];


public OnPlayerConnect(playerid)
{
new file[256];
format(file, sizeof(file), "Stats/%s.ini", PlayerName(playerid));

if(!dini_Exists(file))
{
dini_Create(file);
dini_IntSet(file, "FavSkin", 0);
}
else
{
pStats[playerid][FavSkin] = dini_Int(file, "FavSkin");
}
return 1;
}


public OnPlayerSpawn(playerid)
{
SetPlayerSkin(playerid, pStats[playerid][FavSkin]);
return 1;
}



//Command:
if (strcmp("/favouriteskin", cmdtext, true, 10) == 0)
{
new file[256];
format(file, sizeof(file), "Stats/%s.ini", PlayerName(playerid));
dini_IntSet(file, "FavSkin", 2);
SetPlayerSkin(playerid, 2);
SendClientMessage(playerid, -1, "You Have Successfully Saved Your Skin.");
return 1;
}

Ananisiki
20/03/2014, 01:46 PM
But that sets the player skin to 2, what i want is that if he types /favouriteskin, it will save his current skin into a txt file,

and if he disconnects and come back he'll spawn with it

Macronix
20/03/2014, 01:47 PM
Well... then you just change the 2 with GetPlayerSkin(playerid) ? Lol^^ This was only for test purposes...


//Command:
if (strcmp("/favouriteskin", cmdtext, true, 10) == 0)
{
new file[256];
format(file, sizeof(file), "Stats/%s.ini", PlayerName(playerid));
dini_IntSet(file, "FavSkin", GetPlayerSkin(playerid));
SendClientMessage(playerid, -1, "You Have Successfully Saved Your Skin.");
return 1;
}

Ananisiki
20/03/2014, 01:54 PM
well, if i dont have a favourite skin set, i spawn with the cj skin..

Macronix
20/03/2014, 02:16 PM
Yes, thats right, because when you connect it writes FavSkin = 0, so the normal skin is CJ ;)

Ananisiki
21/03/2014, 08:01 AM
So how could i fix this??

Hanuman
21/03/2014, 08:20 AM
paste this code under OnPlayerSpawn

new file[256];
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));
if(dini_Exists(file))
{
SetPlayerSkin(playerid,(dUserINT(PlayerName).("FavSkin")) );
}

Ananisiki
21/03/2014, 07:05 PM
That gave alot of errors....

Macronix
21/03/2014, 09:05 PM
You need a skin to start with.. because on OnPlayerConnect you always have CJ as skin because you need to select one first.

CroM256
21/03/2014, 09:17 PM
dini_IntSet(file, "FavSkin", 0);
Instead of '0' type skin ID which you want to give every player who didn't choose skin yet.

Hanuman
22/03/2014, 01:47 AM
That gave alot of errors....

which line is giving u error?

Ananisiki
22/03/2014, 06:52 AM
Oh well, i have like 15 skins to choose between, that one he picks he will spawn with it

CroM256
22/03/2014, 07:12 AM
Add them on OnGameModeInit with AddPlayerClass and let him choose his favourite one.

Ananisiki
22/03/2014, 07:14 AM
What do you mean?
If you can't help to solve my problem, please don't reply just to count your posts up

Hanuman
22/03/2014, 08:21 AM
enum PlayerStats
{
FavSkin,
FavSkinEnable
}

public OnPlayerConnect(playerid)
{
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));

if(!dini_Exists(file))
{
dini_Create(file);
dini_IntSet(file, "FavSkin", 0);
dini_IntSet(file, "FavSkinEnable", 0);
return 1;
}
if(dini_Exists(file))
{
pStats[playerid][FavSkin] = dini_Int(file, "FavSkin");
return 1;
}

public OnPlayerSpawn(playerid)
{
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));
if(dini_Exists(file))
{
if(pStats[playerid][FavSkinEnable] == 1)
{
SetPlayerSkin(playerid, dini_Int(file, "FavSkin"));
}
}
return 1;
}

CMD:favouriteskin(playerid, params[])
{
#pragma unused params
if(Dead[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "You Cannot Use This Command When Dead.");
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));
dini_IntSet(file, "FavSkinEnable", 1);
dini_IntSet(file, "FavSkin", GetPlayerSkin(playerid));
SendClientMessage(playerid, COLOR_PINK, "You Have Successfully Saved Your Skin.");
return 1;
}

Simple Paste these codes!

Put dini_IntSet(file, "FavSkinEnable", 0); below every dini_IntSet(file, "FavSkin", 0);

Ananisiki
22/03/2014, 08:35 AM
It saves the skin in the file but it doesnt set it on spawn....

Hanuman
22/03/2014, 08:40 AM
pStats[playerid][FavSkinEnable] = dini_Int(file,"FavSkinEnable");

Paste this in OnGamemodeInit();
with my codes that i have gave u!

EDIT:wait

Ananisiki
22/03/2014, 08:49 AM
Hmm??

Hanuman
22/03/2014, 08:54 AM
srry! Now put this under OnplayerConnect (After he login) with my codes that i have gave u!

pStats[playerid][FavSkinEnable] = dini_Int(file,"FavSkinEnable");

OR

Add this in my codes

public OnPlayerConnect(playerid)
{
new file[256];
format(file, sizeof file, "Stats/%s.ini", PlayerName(playerid));

if(!dini_Exists(file))
{
dini_Create(file);
dini_IntSet(file, "FavSkin", 0);
dini_IntSet(file, "FavSkinEnable", 0);
return 1;
}
if(dini_Exists(file))
{
pStats[playerid][FavSkin] = dini_Int(file, "FavSkin");
pStats[playerid][FavSkinEnable] = dini_Int(file,"FavSkinEnable");
return 1;
}
return 1;
}

Ananisiki
22/03/2014, 09:09 AM
Seems to work, thanks but if the players stats file gets deleted and he connects, his skin sets to 0

Hanuman
22/03/2014, 09:13 AM
Yea man then his whole data will get remove. So it is not a problem!

Finally ur pproblem got solved!
So I am genius! Am I right Ladies? :cool: ;)


Just kidding.

Ananisiki
22/03/2014, 09:18 AM
thanks man +rep =)