skin changes when dieing o_o
#1

hello there...


i recently made the skin save when you log out of the server...

but now the only problem i have is that when i die...my skin changes to the cop skin when i spawn back

anyways...just to shed alittle light, The cop skin is on the FIRST slot on the class selection screen...(if that helps)

heres my code:


this one is to the "LOGIN dialog"

when you login you automaticly spawn with the skin you had last time


Quote:

if(dialogid == LOG)
{

new string[128];
new name[MAX_PLAYER_NAME];

{
new file[128];
new PlayerName[24];
new giveplayerid;
if(strlen(inputtext) == 0)
{
GetPlayerName(playerid, PlayerName, sizeof PlayerName);
format(string, sizeof string, "We have detected that your account is registered \n\nPlease login to your account", PlayerName);
ShowPlayerDialog(playerid, LOG, DIALOG_STYLE_INPUT, "Account", string, "Login", "Cancel.");
return 0;
}
GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"/USERS/%s.ini",name);
if(fexist(file))
{
new password = dini_Int(file, "Password");
if(udb_hash(inputtext) != password)
{
SendClientMessage(playerid, COLOR_ERROR, "Incorrect password");
format(string, sizeof string, "We have detected that your account is registered \n\nPlease login to your account", name);
ShowPlayerDialog(playerid, LOG, DIALOG_STYLE_INPUT, "Account", string, "Login", "Cancel.");
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

}
else
{
IsLogged[playerid] = 1;

SpawnPlayer(playerid);
SetPlayerScore(playerid, dini_Int(file,"Score"));
GivePlayerMoney(playerid, dini_Int(file,"Money"));
PlayerInfo[giveplayerid][AdminLevel] = dini_Int(file,"AdminLevel");
gTeam[playerid] = dini_Int(file,"Team");
SetPlayerSkin(playerid, dini_Int(file, "Skin"));


SendClientMessage(playerid, COLOR_GREEN, "You have successfully logged into your account");
}
}
}
}

return 1;
}


and this one saves your info such as skin,money etc when you disconnect


Quote:

public OnPlayerDisconnect(playerid, reason)
{
new pName[24];
new str[128];
new giveplayerid;
GetPlayerName(playerid, pName, 24);

switch(reason)
{
case 0: format(str, 128, "%s has left the server. (Timeout)", pName);
case 1: format(str, 128, "%s has left the server. (Leaving)", pName);
case 2: format(str, 128, "%s has left the server. (Kicked)", pName);
}
SendClientMessageToAll(0xAFAFAFAA, str);

new file[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"/USERS/%s.ini",name);

if(fexist(file))
{
dini_IntSet(file,"Score", GetPlayerScore(playerid));
dini_IntSet(file,"Money", GetPlayerMoney(playerid));
dini_IntSet(file,"AdminLevel", PlayerInfo[giveplayerid][AdminLevel]);
dini_IntSet(file,"Team", gTeam[playerid]);
new skin=GetPlayerSkin(playerid);
dini_IntSet(file, "Skin", skin);


}

IsLogged[playerid] = 0;
KillTimer(TimeTimer);



return 1;
}


everything save perfectly...it just when i get killed ingame and then when i spawn back...u spawn with the cop skin...


thats the only problem i have...so please...if u can solve this for me ill give you a gigantic cookie throgh FEDEX
Reply
#2

did you try to set the skin after a player spawned?
Код:
public OnPlayerSpawn(playerid)
{
	SetPlayerSkin(playerid, dini_Int(file, "Skin"));
	//... blablabl
	return 1;
}
Reply
#3

yes i have but that leads to another problem...

say if i want to spawn with a different skin "for example if i spawn as army"

then when i spawn...i spawn with the same civilian skin.

so yea
Reply
#4

this will be a work-around, coz the OnPlayerSpawn usually dosnt resets the skin:
Код:
public OnPlayerRequestClass(playerid, classid)
{
	//...
	SetPVarInt(playerid,"Skin",classid);
	//...
	return 1;
}
oops, i posted the DINI thing. i doubt that you are using the same filename...
Код:
public OnPlayerSpawn(playerid)
{
	SetPlayerSkin(playerid,GetPVarInt(playerid,"Skin"));
	//...
	return 1;
}
Reply
#5

ok same way works with dini?


ima try this thx alot mate
Reply
#6

yes, it works, but DINI is horribly slow, but very handy for modifying just 1 or 2 values, and: yw
Reply
#7

er...now i got a new problem :S

now when i spawn...i spawn with cj skin (id 0)

and the weird part is i never added that skin in my ongamemodint

anyways heres the new code...


Quote:

public OnPlayerSpawn(playerid)
{

SetPlayerInterior(playerid,0);
SetPlayerToTeamColor(playerid);
Spawned[playerid] =1;



new file[128];
SetPlayerSkin(playerid, dini_Int(file, "Skin"));





return 1;
}

Quote:

public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid,-2667.1704,1430.0757,906.4609);
SetPlayerCameraPos(playerid, -2667.1614,1427.8644,906.4609);
SetPlayerCameraLookAt(playerid, -2667.1704,1430.0757,906.4609);
SetPlayerFacingAngle(playerid,181.662;
SetPlayerInterior(playerid,3);
SetPlayerTeamFromClass(playerid, classid);

new file[128], string[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"/USERS/%s.ini",name);


if (IsLogged[playerid] == 0)
{
if(!fexist(file))
{
format(string, sizeof string, "We have detected that your account is NOT registered \n\nPlease register your account", name);
ShowPlayerDialog(playerid, REG, DIALOG_STYLE_INPUT, "Account", string, "Register", "Cancel.");
}
if(fexist(file))
{
format(string, sizeof string, "We have detected that your account is registered \n\nPlease login to your account", name);
ShowPlayerDialog(playerid, LOG, DIALOG_STYLE_INPUT, "Account", string, "Login", "Cancel.");
}
return 1;
}


if(!fexist(file))
{
dini_IntSet(file, "Skin", classid);
}





switch (classid) {

case 0,1,2,3,4,5:

{

GameTextForPlayer(playerid, "~b~POLICE OFFICER~n~~w~CITY OFFICER", 3000, 5);

}

case 6:

{

GameTextForPlayer(playerid, "~b~S.W.A.T.", 3000, 5);

}
case 7:

{

GameTextForPlayer(playerid, "~b~FBI", 3000, 5);

}

case 8,9,10:

{

GameTextForPlayer(playerid, "~b~ARMY OFFICER~n~", 3000, 5);

}

case 11,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42 ,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,7 6,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106 ,108,110,112,114,116,118,120,122,124,126,128,130,1 32,134,136,138,140,142,144,146,148,150,152,154,156 ,158,160,162,164,166,168,170,172,174,176,178,180,1 82,184,186,188,189:

{

GameTextForPlayer(playerid, "~w~CIVILIAN~b~", 3000, 5);

}

}

return 1;
}


sorry man
Reply
#8

this causes the skin 0 (CJ):
Код:
	new file[128];
	SetPlayerSkin(playerid, dini_Int(file, "Skin"));
the file[] is created, its an empty string, so when you try to read data out of a file thats not existing, you will get 0 back.
maybe this small snippet will help you find the right way..
Код:
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid,name,sizeof(name));
	new filename[64];
	format(filename,sizeof(filename),"%s.txt",name);

	if(!dini_Exists(filename)) // this one is not really important, it just creates a file when its not already there
	{
		dini_Create(filename);
		return 1;
	}

	SetPVarInt(TargetID,"Skin",dini_Int(filename,"Skin"));
Reply
#9

thx mate

but heres what i did to fix this

i added:

new pid =GetPlayerSkin(playerid);
SetPlayerSkin(playerid,pid);

under onplayerspawn and now it dosent happen anymore

and i know the fix above dosent make sense but it worked

thx man!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)