Getting Data from a function.. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting Data from a function.. (
/showthread.php?tid=159079)
Getting Data from a function.. - [L3th4l] - 12.07.2010
ye, so i got this :
pawn Код:
stock LoadStaticVehiclesFromFile(const filename[])
{
new File:file_ptr,
line[256],
var_from_line[64],
vehicletype,
Float:SpawnX,
Float:SpawnY,
Float:SpawnZ,
Float:SpawnRot,
Color1,
Color2,
index,
vehicles_loaded;
file_ptr = fopen(filename,filemode:io_read);
if(!file_ptr) return 0;
vehicles_loaded = 0;
VehiclePID = 0;
while(fread(file_ptr,line,256) > 0)
{
index = 0;
index = token_by_delim(line,var_from_line,',',index);
if(index == (-1)) continue;
vehicletype = strval(var_from_line);
if(vehicletype < 400 || vehicletype > 611) continue;
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnX = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnY = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnZ = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnRot = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
Color1 = strval(var_from_line);
index = token_by_delim(line,var_from_line,';',index+1);
Color2 = strval(var_from_line);
AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ+1,SpawnRot,Color1,Color2,(30*60));
vehicles_loaded++;
VehiclePID++;
}
fclose(file_ptr);
printf("Loaded \"%d\" Vehicles From: \"%s\"",vehicles_loaded,filename);
new fstring[128];
format(fstring,sizeof(fstring),"Loaded \"%d\" From \"%s\"",vehicles_loaded,filename);
SendClientMessageToAll(LIGHTBLUE2,fstring);
return vehicles_loaded;
}
yes, its from the include folder that comes with the samp packge, added a line or to there. But you see that it says:VehiclePID. Well thats used for when ever i save a vehicle, it creates a unique id for each vehicle. it increases by 1 as you see.
Ok so, when a player enters the vehicle, i want a msg sent to him saying "vehicle ID: "HERE GOES THE VEHICLEPID" ",VehiclePID);
well ye format it first, so OnPlayerEnterVehicle,How could i get that data be sent to the player with the correct VehiclePID??
On the function i could use IsPlayerInAnyVehicle(playerid) then format it and send the VehiclePID. But i don't know if that works, or how to set it up
Re: Getting Data from a function.. -
Backwardsman97 - 12.07.2010
You could create an array and use it for your vehicles.
pawn Код:
//At the top
new VehID[MAX_VEHICLES];
//Right above VehiclePID++;
VehID[vehicleid] = VehiclePID;
The only problem with that is you need a vehicle id to use for the array index. You could use CreateVehicle instead of AddStaticVehicleEx so you could get the vehicle id. It's up to you.