17.02.2011, 15:06
This that rewrites the program is a program.
Though it operates by one respondent reading the file now
How should I do not to come by inputting the command though I load hilts as soon as being written in the second line?
#include <a_samp>
#include <dutils>
#pragma tabsize 0
#define MAX_LIST 256
enum TPL
{
Float:X,
Float:Y,
Float:Z,
Interior,
NAME[256],
CMD[256]
};
new Tel[MAX_LIST][TPL];
public OnFilterScriptInit()
{
ReadFile();
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
new cmd[256],
idx;
cmd = strtok(cmdtext,idx);
if(strcmp(cmd,"/tp",true) == 0)
{
cmd = strtok(cmdtext,idx);
if(!strlen(cmd)) return SendClientMessage(playerid,0xFFFFFFAA,"Usage:/tp [places]");
for(new i=0;i<MAX_LIST;i++)
{
if(strcmp(cmd,Tel[i][CMD],true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid),Tel[i][X],Tel[i][Y],Tel[i][Z]);
LinkVehicleToInterior(GetPlayerVehicleID(playerid) ,Tel[i][Interior]);
SetPlayerInterior(playerid,Tel[i][Interior]);
} else
{
SetPlayerPos(playerid,Tel[i][X],Tel[i][Y],Tel[i][Z]);
SetPlayerInterior(playerid,Tel[i][Interior]);
}
new str[256],name[256];
GetPlayerName(playerid,name,sizeof name);
format(str,sizeof str,"%s has %s to teleport (/%s)",name,Tel[i][NAME],Tel[i][CMD]);
SendClientMessageToAll(0xFFFF00AA,str);
} else {
SendClientMessage(playerid,0xFFFFFFAA,"The place doesn't exist.
");
}
return 1;
}
}
return 0;
}
stock ReadFile()
{
new File:hFile,
tmp[256],
Float,
Float:y,
Float:z,
interior,
i = 0,
line = 0,
Name[256],
Cmd[256];
hFile = fopen("loadtp.ini",io_read);
if(!hFile) return printf("Not open file!!");
tmp[0] = 0;
while(fread(hFile,tmp) > 0){
StripNewLine(tmp);
if(tmp[0] != 0){
x = Float:floatstr(strtok(tmp,i,','));
y = Float:floatstr(strtok(tmp,i,','));
z = Float:floatstr(strtok(tmp,i,','));
interior = strval(strtok(tmp,i,','));
set(Name,strtok(tmp,i,','));
set(Cmd,strtok(tmp,i,','));
if(line < MAX_LIST){
Tel[line][X] = x;
Tel[line][Y] = y;
Tel[line][Z] = z;
Tel[line][Interior] = interior;
Tel[line][NAME] = Name;
Tel[line][CMD] = Cmd;
line++;
printf("Load:%f,%f,%f,%d || Name = %s || CMD = %s",x,y,z,interior,Name,Cmd);
}
}
i = 0;
tmp[0] = 0;
}
printf("Load Number: %d",line);
fclose(hFile);
return 1;
}
Though it operates by one respondent reading the file now
How should I do not to come by inputting the command though I load hilts as soon as being written in the second line?
#include <a_samp>
#include <dutils>
#pragma tabsize 0
#define MAX_LIST 256
enum TPL
{
Float:X,
Float:Y,
Float:Z,
Interior,
NAME[256],
CMD[256]
};
new Tel[MAX_LIST][TPL];
public OnFilterScriptInit()
{
ReadFile();
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
new cmd[256],
idx;
cmd = strtok(cmdtext,idx);
if(strcmp(cmd,"/tp",true) == 0)
{
cmd = strtok(cmdtext,idx);
if(!strlen(cmd)) return SendClientMessage(playerid,0xFFFFFFAA,"Usage:/tp [places]");
for(new i=0;i<MAX_LIST;i++)
{
if(strcmp(cmd,Tel[i][CMD],true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
SetVehiclePos(GetPlayerVehicleID(playerid),Tel[i][X],Tel[i][Y],Tel[i][Z]);
LinkVehicleToInterior(GetPlayerVehicleID(playerid) ,Tel[i][Interior]);
SetPlayerInterior(playerid,Tel[i][Interior]);
} else
{
SetPlayerPos(playerid,Tel[i][X],Tel[i][Y],Tel[i][Z]);
SetPlayerInterior(playerid,Tel[i][Interior]);
}
new str[256],name[256];
GetPlayerName(playerid,name,sizeof name);
format(str,sizeof str,"%s has %s to teleport (/%s)",name,Tel[i][NAME],Tel[i][CMD]);
SendClientMessageToAll(0xFFFF00AA,str);
} else {
SendClientMessage(playerid,0xFFFFFFAA,"The place doesn't exist.
");
}
return 1;
}
}
return 0;
}
stock ReadFile()
{
new File:hFile,
tmp[256],
Float,
Float:y,
Float:z,
interior,
i = 0,
line = 0,
Name[256],
Cmd[256];
hFile = fopen("loadtp.ini",io_read);
if(!hFile) return printf("Not open file!!");
tmp[0] = 0;
while(fread(hFile,tmp) > 0){
StripNewLine(tmp);
if(tmp[0] != 0){
x = Float:floatstr(strtok(tmp,i,','));
y = Float:floatstr(strtok(tmp,i,','));
z = Float:floatstr(strtok(tmp,i,','));
interior = strval(strtok(tmp,i,','));
set(Name,strtok(tmp,i,','));
set(Cmd,strtok(tmp,i,','));
if(line < MAX_LIST){
Tel[line][X] = x;
Tel[line][Y] = y;
Tel[line][Z] = z;
Tel[line][Interior] = interior;
Tel[line][NAME] = Name;
Tel[line][CMD] = Cmd;
line++;
printf("Load:%f,%f,%f,%d || Name = %s || CMD = %s",x,y,z,interior,Name,Cmd);
}
}
i = 0;
tmp[0] = 0;
}
printf("Load Number: %d",line);
fclose(hFile);
return 1;
}