Help with saving function
#1

Hey, I'd like to make something like this
Код:
function LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Sex",PlayerInfo[playerid][pSex]);
    INI_Int("Age",PlayerInfo[playerid][pAge]);
    INI_Float("Pos_x",PlayerInfo[playerid][pPos_x]);
    INI_Float("Pos_y",PlayerInfo[playerid][pPos_y]);
    INI_Float("Pos_z",PlayerInfo[playerid][pPos_z]);
    INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    INI_Int("Team",PlayerInfo[playerid][pTeam]);
    INI_Int("Accent",PlayerInfo[playerid][pAccent]);
    INI_Int("Account_Locked",PlayerInfo[playerid][pAccLock]);
    return 1;
}
But for vehicles, a different file so I can save the owner.

There will be vehicles around the map and players will be able to enter them and buy them, is there any good tutorial that will teach me how to make a function like the one above? But for vehicles.

I made this so far
Код:
enum vInfo
{
	vOwner,
	vID,
	vPlate
}
new VehicleInfo[MAX_PLAYERS][vInfo];
Reply
#2

Anyone?
Reply
#3

One way to do it is to save player's name using INI_String and later check it using strcmp.
// oops, dont know why I misunderstood the topic and thought its only to assign one veh to a player, sorry
Reply
#4

Quote:
Originally Posted by Amads
Посмотреть сообщение
One way to do it is to save player's name using INI_String and later check it using strcmp.
// oops, dont know why I misunderstood the topic and thought its only to assign one veh to a player, sorry
I will place vehicles around the map and players will be able to buy them, what I want is to save the owner of the vehicle if someone buy it and I am not sure how to do that
Reply
#5

Just a simple exemple
PHP код:
function LoadVehicles(vehid,name[],value[])
{
    
INI_String("Owner"VehicleInfo[vehid][vOwner], MAX_PLAYER_NAME); 
    
INI_Int("ID",VehicleInfo[veid][vID]);
    
INI_String("Plate"VehicleInfo[vehid][vPlate], 10); 
    return 
1;

Reply
#6

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Just a simple exemple
PHP код:
function LoadVehicles(vehid,name[],value[])
{
    
INI_String("Owner"VehicleInfo[vehid][vOwner], MAX_PLAYER_NAME); 
    
INI_Int("ID",VehicleInfo[veid][vID]);
    
INI_String("Plate"VehicleInfo[vehid][vPlate], 10); 
    return 
1;

Код:
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1009) : error 001: expected token: ")", but found "["
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1009) : warning 215: expression has no effect
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1009) : error 001: expected token: ";", but found "]"
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1009) : error 029: invalid expression, assumed zero
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1009) : fatal error 10
Alright so I think of a different thing, I will make files with vehicles in scriptfiles, but how do I make them load when the server start I really don't know how to make them load...

I mean.. I can use CreateVehicle(x, x,)... load the details from the files, but how do I create more vehicles? Like how to give a random id to every vehicle, example below
vehicle[0] = createvehicle
vehicle[1] = createvehicle
vehicle[2] = createvehicle
vehicle[3] = createvehicle

I want to have like 50+ cars around the map, buyable by players, I want to save them in a file, I can make the file manually and set the owner to noone and the position, but I do not know how to load that file and spawn the vehicles?
Reply
#7

That's the code in general
PHP код:
//Somewhere on your code put this, more likely at the top
#define VEH_PATH "%d.ini" //The path of the file
#define MAXPVEHS 100 //The maximum private vehicles

//This Function will help set a proper name for your data storing file, it will be named according to the vehicle ID the stored data belong
VehPth(vid){
    new 
str[3];
    
format(strsizeof(str), VEH_PATHvid);
    return 
str;
}

//A loop that will go thought all the files and create vehicles, this should be on OnGamemodeInIt/OnFilterScriptInIt
for(i=0;i<MAX_PVEHS;i++){
     
INI_ParseFile(VehPth(i), "VehicleLoad", .bExtra true, .extra i); //This will call the loading function to extract data
     
CreateVehicle(vehicletypeFloat:xFloat:yFloat:zFloat:rotationcolor1color2respawn_delayaddsiren=0);
     
SetVehicleNumberPlate(iVehicleInfo[i][vPlate])
     
//The rest is up to you
}

//Data loading function
LoadVehicles(vehid,name[],value[]) 

    
INI_String("Owner"VehicleInfo[vehid][vOwner], MAX_PLAYER_NAME);  
    
INI_Int("ID",VehicleInfo[veid][vID]); 
    
INI_String("Plate"VehicleInfo[vehid][vPlate], 10);  
    return 
1

Reply
#8

Код:
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(704) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(704) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(704) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(704) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1953) : warning 203: symbol is never used: "LoadVehicles"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Warnings.
Line 704:
Код:
CreateVehicle(vType, vPos_x, vPos_y, vPos_z, vRot, vColor1, vColor2, -1);
Also how can I call LoadVehicles at ongamemodeinit? so they will load?

I tried adding LoadVehicles; there but it will give me an error.
Reply
#9

PHP код:
//To call LoadVehicles function, use this:
INI_ParseFile(VehPth(i), "VehicleLoad", .bExtra true, .extra i); //This will call the loading function to extract data 
Reply
#10

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
PHP код:
//To call LoadVehicles function, use this:
INI_ParseFile(VehPth(i), "VehicleLoad", .bExtra true, .extra i); //This will call the loading function to extract data 
Shouldn't I call it LoadVehicles instead of VehicleLoad? Also do you have any idea why I get the warnings from above?


And I made a file called 1.ini with this content
Код:
[data]
Owner = Noone
Type = 400
Plate = TEST
Pos_x = 1451.7761
Pos_y = -1153.5676
Pos_z = 23.7988
Rot = 0.0000
Color1 = 3
Color2 = 5
RespawnDelay = 5
But the car is not spawning in game, why?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)