[NEED HELP] with .dini for gangs
#1

Hi all, ive been scripting an FS that im pretty excited about. However, I've run into a small obstacle. I have a File for every gang. 9 in total. is there any way I can set it to were it uses a specific file depending on team?

Ex. if playerteam = 1, the gang file that they use is "GroveStreet"
if playerteam = 2, the gang file that they use is "Ballas"

Now, first of all, IS there a way to do this? Second, if so, can someone PLZ tell me how .

Thnx I.A.
Reply
#2

gteam? or setplayer team?
and are all you file in the same dir? and can i have a example file name
Reply
#3

using an array assigned to each team makes it possible to use the file concerning stuff w/o any if-else or switch-case loop...
Код:
new TeamNameFileAddition[][]=
{
	"team_0_none",//senseless, as team0 wont be adressed, coz each array starts at 0, so just ignore that
	"team_1_Grove",
	"team_2_Ballas"
};
your file callback could start like this:
Код:
new filename[64];
format(filename,sizeof(filename),"TeamDirectory/%s.txt",TeamNameFileAddition[gTeam[playerid]]);
//read or write when you opened the file
Reply
#4

Quote:
Originally Posted by (SF)Noobanatior
gteam? or setplayer team?
and are all you file in the same dir? and can i have a example file name
I use SetPlayerTeam. There all in the same directory(scriptfiles/Server. Player files in scriptfiles/user). and "GroveStreet" is on of the names.
Quote:
Originally Posted by Babul
using an array assigned to each team makes it possible to use the file concerning stuff w/o any if-else or switch-case loop...
Код:
new TeamNameFileAddition[][]=
{
	"team_0_none",//senseless, as team0 wont be adressed, coz each array starts at 0, so just ignore that
	"team_1_Grove",
	"team_2_Ballas"
};
your file callback could start like this:
Код:
new filename[64];
format(filename,sizeof(filename),"TeamDirectory/%s.txt",TeamNameFileAddition[gTeam[playerid]]);
//read or write when you opened the file
nd im not quite sure i understand what that is. What exactly does TeamNameFileAddtion do?
Reply
#5

oh, i should have named them "TeamFileName" maybe? its simply a string, stored in an array. the team you are using is a variable, turned to a pointer, pointing to the filename array. so if you use that function for team 9, then the 10th element of the array wil get used as filename, f.ex:
Код:
new TeamFileName[][]=
{
	"team_0_none",
	"team_1",
	"team_2",
	// and so on...
	"team_9_Ballas" //lets assume the player is in team 9
};
you can use that string as filename by formatting it with
Код:
format(FileName,sizeof(Filename),"Server/%s",TeamFileName[GetPlayerTeam(playerid)]);
..so it will turn into:
Код:
format(FileName,sizeof(Filename),"Server/%s",TeamFileName[9]);
and further:
Код:
format(FileName,sizeof(Filename),"Server/%s","team_9_Ballas");
final result:
Код:
format(FileName,sizeof(Filename),"Server/team_9_Ballas");
..quite faster than using loops, which would look like that ugly piece of spaghetticode:
Код:
new Team=GetPlayerTeam(playerid);
if(Team==1)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_Grove"));
}
else if(Team==2)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_2_Ballas"));
}
else if(Team==3)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_always"));
}
else if(Team==4)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_try"));
}
else if(Team==5)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_to"));
}
else if(Team==6)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_trade"));
}
else if(Team==7)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_RAM"));
}
else if(Team==8)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_for"));
}
else if(Team==9)
{
	SetPlayerTeam(playerid,dini_Int("Server/team_1_speed"));
}
i know, an array is wasting RAM, but we arent in the 80's anymore, so a few KBytes wont make the server run out of memory
btw: the arrayed method runs in linear time, so it wont matter if you are using just 2 or 500 teams.
despite that the "loop-method" for handling 500 teams would use some memory, too, plus: it would need to run thru 499 teams to get the resulting filename for team 499.
in short:
the array TeamFileName[499] will give you the proper filename ("Team_499_Cops") with just 1 call
Reply
#6

k, but idk if u understand the question. I want it to automatically use a specific file for a specific gang, like if i say if(gang[money] > 50000) then it reads the file for that gang. Is that what u jus described?
Reply
#7

yep, the stuff scripted around is up to you. this concept is simple, once you got used to it.

edit: the array[] represents the team- and file name that you could use for ingame messages aswell.
Reply
#8

ok, so for team_0_none, etc, i wud replace that with my file names?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)