Nu sunteti conectat. Conectati-va sau inregistrati-va

Vezi subiectul anterior Vezi subiectul urmator In jos Mesaj [Pagina 1 din 1]

1 Sistem de vehicule y_ini & y_cmd la data de Dum Mar 11, 2018 11:00 pm

Pitiku

avatar

Salut , in acest tutorial va voi arata cum sa creati un sistem de masini folosind y_ini si y_cmd.

Avem nevoie de urmatorul plugin
Y_INI: [Trebuie sa fiti inscris si conectat pentru a vedea acest link]


Pentru inceput adaugam la inceputul gamemode-ului:
Cod:

enum vInfo 
{
 vID,
 vModel, 
 Float:vLoc[4], 
 vColor1, 
 vColor2, 
 vRespawn,
 vOwner[MAX_PLAYER_NAME],
 bool:vLocked 
}
new VehicleInfo[MAX_VEHICLES][vInfo]; 
new bool:vCreated[MAX_VEHICLES]; 

La sfarsitul gamemode-ului adaugam:
Cod:

stock VehicleValid(vehicleID)
{
 for(new i = 0; i < MAX_VEHICLES; i++) 
 {
 if((vCreated[i]) && (VehicleInfo[i][vID] == vehicleID)) return i; 
 }
 return -1; 
}
stock VehicleEngine(vehicleID, bool:toggle) 
{
 new vehicleid = VehicleInfo[vehicleID][vID]; 
 new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, toggle, lights, alarm, doors, bonnet, boot, objective);
}
stock VehicleLock(vehicleID, bool:toggle) 
{
 new vehicleid = VehicleInfo[vehicleID][vID]; 
 new engine, lights, alarm, doors, bonnet, boot, objective; 
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective); 
SetVehicleParamsEx(vehicleid, engine, lights, alarm, toggle, bonnet, boot, objective); 
}
stock VehiclePath(vehicleID) 
{
 new strPath[64];
 format(strPath, sizeof(strPath), "/vehicle/%d.ini"); 
 return strPath; 
}  
stock VehicleGetFreeSlot() 
{
 for(new i = 0; i < MAX_VEHICLES; i++) 
 {
 if(!vCreated[i]) return i;
 }
 
 return -1; 
}
stock VehicleCreate(vehicleModel, Float:vehicleLoc[4], vehicleColor1, vehicleColor2, vehicleRespawn, vehicleOwner[], bool:vehicleLocked)
{
 new vehicleid = VehicleGetFreeSlot();
 VehicleInfo[vehicleid][vModel] = vehicleModel;
 VehicleInfo[vehicleid][vLoc] = vehicleLoc; 
 VehicleInfo[vehicleid][vColor1] = vehicleColor1; 
 VehicleInfo[vehicleid][vColor2] = vehicleColor2; 
 VehicleInfo[vehicleid][vRespawn] = vehicleRespawn; 
 format(VehicleInfo[vehicleid][vOwner], MAX_PLAYER_NAME, vehicleOwner); 
 VehicleInfo[vehicleid][vLocked] = vehicleLocked; 
 VehicleInfo[vehicleid][vID] = CreateVehicle(vehicleModel, vehicleLoc[0], vehicleLoc[1], vehicleLoc[2], vehicleLoc[3], vehicleColor1, vehicleColor2,
 vehicleRespawn);
 vCreated[vehicleid] = true; 
 VehicleLock(vehicleid, VehicleInfo[vehicleid][vLocked]); 
 
 return vehicleid; 
}
stock VehicleGet(vehicleID)
{
 GetVehiclePos(VehicleInfo[vehicleID][vID], VehicleInfo[vehicleID][vLoc][0], VehicleInfo[vehicleID][vLoc][1], VehicleInfo[vehicleID][vLoc][2]);
 GetVehicleZAngle(VehicleInfo[vehicleID][vID], VehicleInfo[vehicleID][vLoc][3]);
}
stock VehicleLoad(vehicleID, file[])
{
 INI_ParseFile(file, "LoadVehicleData", .bExtra = true, .extra = vehicleID); 
 VehicleCreate(VehicleInfo[vehicleID][vModel],
 VehicleInfo[vehicleID][vLoc], VehicleInfo[vehicleID][vColor1], VehicleInfo[vehicleID][vColor2], VehicleInfo[vehicleID][vRespawn],
 VehicleInfo[vehicleID][vOwner], VehicleInfo[vehicleID][vLocked]); 
}
forward public LoadVehicleData(vehicleID, name[], value[]);
public LoadVehicleData(vehicleID, name[], value[]) 
{
 new strLoc[8]; 
 INI_Int("model", VehicleInfo[vehicleID][vModel]);
 for(new i = 0; i < 4; i++) format(strLoc, sizeof(strLoc), "Loc%d", i), INI_Float(strLoc, VehicleInfo[vehicleID][vLoc][i]);
 INI_Int("color1", VehicleInfo[vehicleID][vColor1]); 
 INI_Int("color2", VehicleInfo[vehicleID][vColor2]);
 INI_Int("respawn", VehicleInfo[vehicleID][vRespawn]);
 INI_String("owner", VehicleInfo[vehicleID][vOwner], MAX_PLAYER_NAME);
 VehicleInfo[vehicleID][vLocked] = INI_Int("locked") == 1 ? true : false;
 return 1;
}
stock VehicleSave(vehicleID)
{
 new INI:dFile = INI_Open(VehiclePath(vehicleID));
 INI_WriteInt(dFile, "model", VehicleInfo[vehicleID][vModel]);
 for(new i = 0; i < 4; i++) format(strLoc, sizeof(strLoc), "Loc%d", i), INI_Float(dFile, strLoc, VehicleInfo[vehicleID][vLoc][i]);
 INI_WriteInt(dFile, "color1", VehicleInfo[vehicleID][vColor1]);
 INI_WriteInt(dFile, "color2", VehicleInfo[vehicleID][vColor2]);
 INI_WriteInt(dFile, "respawn", VehicleInfo[vehicleID][vRespawn]);
 INI_WriteString(dFile, "owner", VehicleInfo[vehicleID][vOwner]);
 INI_WriteInt(dFile, "locked", VehicleInfo[vehicleID][vLocked] ? 1 : 0);
 INI_Close(dFile);
}
stock VehicleLoadAll()
{
 new index = 0; 
 while(fexist(VehiclePath(index))) 
 {
 VehicleLoad(index, VehiclePath(index)); 
 }
 printf("Vehicles Loaded: %d", index); 
}
stock VehicleSaveAll()
{
 new index = 0; 
 for(new i = 0; i < MAX_VEHICLES; i++)
 {
 if(vCreated[i]) 
 {
 VehicleGet(index); 
 VehicleSave(index); 
 index++;
 }
 }
 
 printf("Vehicles Saved: %d", index);
}


Adaugam in OnGameModeInit si in OnGameModeExit urmatoarele coduri:
Cod:

public OnGameModeInit()
{
 VehicleLoadAll(); 

 return 1;
}

public OnGameModeExit()
{
 VehicleSaveAll(); 
 
 return 1;
}


Acestea sunt comenzile:
Cod:

new bool:engine; 
YCMD:engine(playerid, params[], help)
{
 if(help) return SendClientMessage(playerid, -1, "Allows to toggle the vehicle engine."); 
 new vehicleid = VehicleID(GetPlayerVehicleID(playerid)); 
 if((IsPlayerInAnyVehicle(playerid)) && (vehicleid != -1)) 
 {
 engine = !engine;
 VehicleEngine(vehicleid, engine); 
 }
 return 1;
}
YCMD:createvehicle(playerid, params[], help) 
{
 if(help) return SendClientMessage(playerid, -1, "Allows to create a dynamic vehicle."); 
 new vehModel, vehColor1, vehColor2, vehRespawnTime; 
 if(sscanf(params, "iiii", vehModel, vehColor1, vehColor2, vehRespawnTime)) 
 return SendClientMessage(playerid, -1, "USAGE: /createvehicle [Vehicle Model] [Color 1] [Color 2] [Respawn Time]"); 
 new Float:pLoc[4]; 
 new strPlayerName[MAX_PLAYER_NAME]; 
 new vehicleid; 
 GetPlayerPos(playerid, pLoc[0], pLoc[1], pLoc[2]);
 GetPlayerFacingAngle(playerid, pLoc[3]);
 GetPlayerName(playerid, strPlayerName, MAX_PLAYER_NAME); 
 vehicleid = VehicleCreate(vehModel, pLoc, vehColor1, vehColor2, vehRespawnTime, strPlayerName, false);
 PutPlayerInVehicle(playerid, vehicleid, 0); 
 return 1;
}

Robotelul cu reclame


Robot reclame
5€= 1 saptamana
10€= 1 luna
15€= 6 luni
Data de inregistrare: 15/02/2013
Reclama ta aici!

Mesaj de scris aici

Vezi subiectul anterior Vezi subiectul urmator Sus Mesaj [Pagina 1 din 1]

Permisiunile acestui forum:
Nu puteti raspunde la subiectele acestui forum