Don't Work Program... -
xakey - 17.02.2011
Sorry Bad English....
Teleport Script is a being created
Does not work properly
What is the name of your command to get the coordinates from a text and teleport
I want to move the
Where How do I fix this?
///////////////////////////////////////////////////////////////////
#include <a_samp>
#include <dutils>
#pragma tabsize 0
#define MAX_LIST 2000
enum TPL
{
Float:X,
Float:Y,
Float:Z,
Interior,
NAME[256],
CMD[256]
};
new Tel[MAX_LIST][TPL];
public OnFilterScriptInit()
{
LoadFile();
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
stock LoadFile()
{
//============use to local================
new File:hFile,
tmp[256],
buf[256],
idx,
Float
,
Float:y,
Float:z,
interior,
cnt=0;
hFile = fopen("loadtp.ini",io_read);
if(!hFile) return printf("Not Load File");
//================MAIN===================
print("Load To file : loadtp.ini");
while(fread(hFile,buf,256) > 0) {
idx = 0;
idx = token_by_delim(buf,tmp,',',idx+1);
if(idx == (-1)) continue;
x = floatstr(tmp);
idx = token_by_delim(buf,tmp,',',idx+1);
if(idx == (-1)) continue;
y = floatstr(tmp);
idx = token_by_delim(buf,tmp,',',idx+1);
if(idx == (-1)) continue;
z = floatstr(tmp);
idx = token_by_delim(buf,tmp,',',idx+1);
if(idx == (-1)) continue;
interior = strval(tmp);
idx = token_by_delim(buf,Tel[cnt][NAME],',',idx+1);
if(idx == (-1)) continue;
idx = token_by_delim(buf,Tel[cnt][CMD],'\n',idx+1);
if(idx == (-1)) continue;
Tel[cnt][X] = x;
Tel[cnt][Y] = y;
Tel[cnt][Z] = z;
Tel[cnt][Interior] = interior;
cnt++;
}
fclose(hFile);
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
new cmd[256];
new idx;
cmd = strtok(cmdtext,idx);
if(strcmp(cmd,"/tp",true) == 0){
cmd = strtok(cmdtext,idx);
new cmdname[256];
strmid(cmdname, cmd, 1, strlen(cmd));
for(new i=0;i<MAX_LIST;i++){
if(strcmp(Tel[i][CMD],cmdname,true) == 0){
if(IsPlayerInAnyVehicle(playerid)){
new vehicle = GetPlayerVehicleID(playerid);
SetVehiclePos(vehicle,Tel[i][X],Tel[i][Y],Tel[i][Z]);
LinkVehicleToInterior(vehicle,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]);
SendClientMessage(playerid,0xFFFFFFAA,str);
} else {
SendClientMessage(playerid,0xFFFFFFAA,"No prace");
}
return 1;
}
}
return 0;
}
token_by_delim(const string[], return_str[], delim, start_index)
{
new x=0;
while(string[start_index] != EOS && string[start_index] != delim)
{
return_str[x] = string[start_index];
x++;
start_index++;
}
return_str[x] = EOS;
if(string[start_index] == EOS)
start_index = (-1);
return start_index;
}
///////////////////////////////////////////////////////////////////////////////////
The contents of this file is
2028.285400,1007.138793,10.820312,0,LosSants,lv
-2026.062255,140.259765,28.835937,0,SanFierro,sf
Re: Don't Work Program... -
AK47317 - 17.02.2011
its look fine...
Re: Don't Work Program... -
xakey - 17.02.2011
The teleport cannot be neatly done.
Re: Don't Work Program... -
alpha500delta - 17.02.2011
First: use [pawn ] [/pawn ] without the spaces
Second: Try to use less 256 in your strings
Re: Don't Work Program... -
xakey - 17.02.2011
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;
}