Код:
// =================[ Includes ]===============
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <mysql>
#pragma tabsize 0
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Mysql vehicle system loaded..");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
print("\n----------------------------------");
print(" Made by BlackRaven ...Real name Mark Andrew...");
print("----------------------------------\n");
}
#endif
// =================[ Defines ]===============
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_RED 0xFF303EFF
#define COLOR_BLUE 0x1C10EFFF
#define COLOR_GREEN 0x0FBF15FF
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_YELLOW2 0xF5DEB3AA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_LIGHTRED 0xFF6347AA
#define COLOR_WHITE 0xFFFFFFAA
#define MYSQL_HOST "127.0.0.1"
#define MYSQL_USER "root"
#define MYSQL_PASS "123"
#define MYSQL_DB "sa-rp"
/*
#define MYSQL_HOST "localhost" // host
#define MYSQL_USER "localhost" // username
#define MYSQL_PASS "" // passport
#define MYSQL_DB "testingblabla" //database
*/
#define MAX_PLAYER_VEHICLES 5
// =================[ Enumerations ]===============
enum vInfo()
{
id,
Model,
Color1,
Color2,
Float:x,
Float:y,
Float:z,
Float:a,
Name[MAX_PLAYER_NAME],
Owner[MAX_PLAYER_NAME],
Lock,
Parked,
Spawned,
Destroyed,
Licenses,
Engine,
type,
}
new vehicleinfo[MAX_VEHICLES][vInfo];
enum pinfo()
{
username[MAX_PLAYER_NAME],
}
new playerinfo[MAX_PLAYERS][pinfo];
// =================[ Global Variables ]===============
new playerkeys[MAX_PLAYERS][5];
new vkey[MAX_PLAYERS];
new key[MAX_VEHICLES];
public OnGameModeInit()
{
mysql_init();
mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB);
SetGameModeText("Mysql Vehicle System v1");
AddPlayerClass(0,344.6826,-1368.5515,14.3819,4.0000,0,0,0,0,0,0);
LoadVehicles();
return 1;
}
public OnGameModeExit()
{
return 1;
}
forward LoadVehicles();
public LoadVehicles()
{
new Query[500];
new fetchVal[100]; //A array to hold the data were going to get
for(new i; i < MAX_VEHICLES; i++) // Makes an loop so all vehicles get loaded.
{
format(Query, sizeof(Query), "SELECT * FROM vehicles WHERE id= %d", i);
mysql_query(Query); // Querys the "Query" Variable.
mysql_store_result(); // Stores the result from Query
if(mysql_num_rows()) // Checks if theres anyrow.
{
if(mysql_fetch_row(Query)) // Splits the row
{
mysql_fetch_field("id", fetchVal);
vehicleinfo[i][id] = strval(fetchVal);
mysql_fetch_field("model", fetchVal);
vehicleinfo[i][Model] = strval(fetchVal);
mysql_fetch_field("color1", fetchVal);
vehicleinfo[i][Color1] = strval(fetchVal);
mysql_fetch_field("color2", fetchVal);
vehicleinfo[i][Color2] = strval(fetchVal);
mysql_fetch_field("x", fetchVal);
vehicleinfo[i][x] = floatstr(fetchVal);
mysql_fetch_field("y", fetchVal);
vehicleinfo[i][y] = floatstr(fetchVal);
mysql_fetch_field("z", fetchVal);
vehicleinfo[i][z] = floatstr(fetchVal);
mysql_fetch_field("a", fetchVal);
vehicleinfo[i][a] = floatstr(fetchVal);
mysql_fetch_field("name", fetchVal);
format(vehicleinfo[i][Name], 50, fetchVal);
mysql_fetch_field("owner", fetchVal);
format(vehicleinfo[i][Owner], 50, fetchVal);
mysql_fetch_field("lock", fetchVal);
vehicleinfo[i][Lock] = strval(fetchVal);
mysql_fetch_field("parked", fetchVal);
vehicleinfo[i][Parked] = strval(fetchVal);
mysql_fetch_field("spawned", fetchVal);
vehicleinfo[i][Spawned] = strval(fetchVal);
mysql_fetch_field("destroyed", fetchVal);
vehicleinfo[i][Destroyed] = strval(fetchVal);
mysql_fetch_field("licenses", fetchVal);
vehicleinfo[i][Licenses] = strval(fetchVal);
mysql_fetch_field("engine", fetchVal);
vehicleinfo[i][Engine] = strval(fetchVal);
mysql_fetch_field("type", fetchVal);
vehicleinfo[i][type] = strval(fetchVal);
printf("type = %d", vehicleinfo[i][type]);
if(vehicleinfo[i][type] != 1)
{
new globalkey;
globalkey = CreateVehicle(vehicleinfo[i][Model],vehicleinfo[i][x],vehicleinfo[i][y],vehicleinfo[i][z],vehicleinfo[i][a],vehicleinfo[i][Color1],vehicleinfo[i][Color2], 60*10000);
SetVehicleZAngle(globalkey, vehicleinfo[i][a]);
printf("query: %s", Query);
printf("name = %s",vehicleinfo[i][Name]);
key[globalkey] = vehicleinfo[i][id];
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(globalkey,engine,lights,alarm,doors,bonnet,boot,objective);
//SetVehicleParamsEx(globalkey,0,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(globalkey,1,lights,alarm,doors,bonnet,boot,objective);
vehicleinfo[i][Engine] = 0;
}
}
}
mysql_free_result(); //Free the result
}
}
stock LoadVehicleID(vehicleid, playerid)
{
new query[1021];
new fetchVal[100];
format(query, sizeof(query), " SELECT * FROM vehicles WHERE id= %d", vehicleid);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
if(mysql_fetch_row(query))
{
mysql_fetch_field("id", fetchVal);
vehicleinfo[vehicleid][id] = strval(fetchVal);
mysql_fetch_field("model", fetchVal);
vehicleinfo[vehicleid][Model] = strval(fetchVal);
mysql_fetch_field("color1", fetchVal);
vehicleinfo[vehicleid][Color1] = strval(fetchVal);
mysql_fetch_field("color2", fetchVal);
vehicleinfo[vehicleid][Color2] = strval(fetchVal);
mysql_fetch_field("x", fetchVal);
vehicleinfo[vehicleid][x] = strval(fetchVal);
mysql_fetch_field("y", fetchVal);
vehicleinfo[vehicleid][y] = strval(fetchVal);
mysql_fetch_field("z", fetchVal);
vehicleinfo[vehicleid][z] = strval(fetchVal);
mysql_fetch_field("a", fetchVal);
vehicleinfo[vehicleid][a] = strval(fetchVal);
mysql_fetch_field("name", fetchVal);
format(vehicleinfo[vehicleid][Name], 50, fetchVal);
mysql_fetch_field("owner", fetchVal);
format(vehicleinfo[vehicleid][Owner], 50, fetchVal);
mysql_fetch_field("lock", fetchVal);
vehicleinfo[vehicleid][Lock] = strval(fetchVal);
mysql_fetch_field("parked", fetchVal);
vehicleinfo[vehicleid][Parked] = strval(fetchVal);
mysql_fetch_field("spawned", fetchVal);
vehicleinfo[vehicleid][Spawned] = strval(fetchVal);
mysql_fetch_field("destroyed", fetchVal);
vehicleinfo[vehicleid][Destroyed] = strval(fetchVal);
mysql_fetch_field("licenses", fetchVal);
vehicleinfo[vehicleid][Licenses] = strval(fetchVal);
mysql_fetch_field("engine", fetchVal);
vehicleinfo[vehicleid][Engine] = strval(fetchVal);
mysql_fetch_field("type", fetchVal);
vehicleinfo[vehicleid][type] = strval(fetchVal);
vkey[playerid] = CreateVehicle(vehicleinfo[vehicleid][Model],vehicleinfo[vehicleid][x],vehicleinfo[vehicleid][y],vehicleinfo[vehicleid][z],vehicleinfo[vehicleid][a],vehicleinfo[vehicleid][Color1],vehicleinfo[vehicleid][Color2], 60*10000);
SetVehicleZAngle(vkey[playerid], vehicleinfo[vehicleid][a]);
printf("result: %d",vkey[playerid]);
key[vkey[playerid]] = vehicleid;
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vkey[playerid],engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vkey[playerid],0,lights,alarm,doors,bonnet,boot,objective);
vehicleinfo[vehicleid][Engine] = 0;
printf("type = %d", vehicleinfo[vehicleid][type]);
}
}
forward LoadPlayerKeys(playerid);
public LoadPlayerKeys(playerid)
{
new query[100], i;
format(query, sizeof(query),"SELECT * FROM vehicles WHERE owner='%s'",playerinfo[playerid][username]);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row(query,"|"))
{
sscanf(query, "p<|>e<i>",playerkeys[playerid][i]);
printf("keys loaded %d",playerkeys[playerid][i]);
printf("%s",query);
i++;
}
}
command(engine, playerid, params[])
{
new engine,lights,alarm,doors,bonnet,boot,objective;
new vid = GetPlayerVehicleID(playerid);
if(IsPlayerInAnyVehicle(playerid))
{
if(IsPlayerInVehicle(playerid,vkey[playerid]))
{
if(vehicleinfo[key[vid]][Engine] == 1)
{
GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vid,0,lights,alarm,doors,bonnet,boot,objective);
vehicleinfo[key[vid]][Engine] = 0;
SendClientMessage(playerid, COLOR_GREEN, "Engine Off.");
}
else
{
GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet,boot,objective);
vehicleinfo[key[vid]][Engine] = 1;
SendClientMessage(playerid, COLOR_GREEN, "Engine On.");
}
}
else
{
SendClientMessage(playerid, COLOR_GREEN, "You don't have the keys of this vehicle.");
}
}
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
if(vehicleinfo[key[vehicleid]][type] == 1)
{
new query[200];
vehicleinfo[key[vehicleid]][Destroyed] ++;
vehicleinfo[key[vehicleid]][Licenses] --;
DestroyVehicle(vehicleid);
if(vehicleinfo[key[vehicleid]][Licenses] == 0)
{
format(query, sizeof(query),"DELETE FROM vehicles WHERE id = %d", key[vehicleid]);
mysql_query(query);
if(IsPlayerConnected(ReturnUser(vehicleinfo[key[vehicleid]][Owner])))
{
SendClientMessage(ReturnUser(vehicleinfo[key[vehicleid]][Owner]), COLOR_GREEN,"Your vehicles is Destroyed for ever!");
vkey[ReturnUser(vehicleinfo[key[vehicleid]][Owner])] = 0;
LoadPlayerKeys(ReturnUser(vehicleinfo[key[vehicleid]][Owner]));
}
}
else
{
if(IsPlayerConnected(ReturnUser(vehicleinfo[key[vehicleid]][Owner])))
{
SendClientMessage(ReturnUser(vehicleinfo[key[vehicleid]][Owner]), COLOR_GREEN,"You car as been destroyed");
}
format(query, sizeof(query),"UPDATE vehicles SET destroyed = %d , licenses = %d WHERE id = %d",vehicleinfo[key[vehicleid]][Destroyed],vehicleinfo[key[vehicleid]][Licenses], key[vehicleid]);
mysql_query(query);
vkey[ReturnUser(vehicleinfo[key[vehicleid]][Owner])] = 0;
}
}
return 1;
}
command(v, playerid, params[])
{
new string[256];
new x_v[256];
new idx;
new x_vehicles[256];
x_v = strtok(params, idx);
if(!strlen(x_v))
{
SendClientMessage(playerid, COLOR_GREEN, "|__________________ Vehicle Options __________________|");
SendClientMessage(playerid, COLOR_WHITE, "INFO: /v [name]");
SendClientMessage(playerid, COLOR_YELLOW2, "OPTIONS: Buy List Get Park Setpark");
SendClientMessage(playerid, COLOR_GREEN, "|_____________________________________________________|");
return true;
}
if(strcmp(x_v,"buy",true) == 0)
{
if(playerkeys[playerid][0] > 0 && playerkeys[playerid][1] > 0 && playerkeys[playerid][2] > 0 && playerkeys[playerid][3] > 0 && playerkeys[playerid][4] > 0)
{
SendClientMessage(playerid, COLOR_RED,"You can only own five vehicles");
return 1;
}
x_vehicles = strtok(params, idx);
if(!strlen(x_vehicles))
{
SendClientMessage(playerid,COLOR_WHITE," Vehicles: Landstalker($41.000), Bravura($23.000), Buffalo($55.000), Sentinel($40.000), Limo($92.000)");
SendClientMessage(playerid,COLOR_WHITE," Vehicles: Manana($25.000), Infernus($110.000), Cheetah($100.000), Moonbeam($25.000), Esperanto($34.000)");
SendClientMessage(playerid,COLOR_WHITE," Vehicles: Washington($41.000), Banshee($91.000), Admiral($41.000), Turismo($120.000), Sanchez($40.000)");
SendClientMessage(playerid,COLOR_WHITE," Vehicles: ZR-350($53.000), Comet($81.500), Burrito($50.500), Rancher($85.000), Greenwood($25.000)");
SendClientMessage(playerid,COLOR_WHITE," Vehicles: FCR-900($88.000), Feltzer($50.000), Remington($45.000), Bullet($150.000), Jester($79.000)");
SendClientMessage(playerid,COLOR_WHITE," Vehicles: Sultan($125.000)");
SendClientMessage(playerid, COLOR_GREEN," /v buy [Vehicle Name] ");
SendClientMessage(playerid, COLOR_GREEN,"|________________________________________________________________________________________________________|");
return true;
}
new price,model,name[100];
if(strcmp(x_vehicles,"landstalker",true) == 0) { price = 41000; model = 400; name = "landstalker"; }
else if(strcmp(x_vehicles,"bravura",true) == 0) { price = 23000; model = 401; name = "bravura"; }
else if(strcmp(x_vehicles,"buffalo",true) == 0) { price = 70000; model = 402; name = "buffalo"; }
else if(strcmp(x_vehicles,"sentinel",true) == 0) { price = 40000; model = 405; name = "sentinel"; }
else if(strcmp(x_vehicles,"limo",true) == 0) { price = 92000; model = 409; name = "limo"; }
else if(strcmp(x_vehicles,"manana",true) == 0) { price = 25000; model = 410; name = "manana"; }
else if(strcmp(x_vehicles,"infernus",true) == 0) { price = 350000; model = 411; name = "infernus"; }
else if(strcmp(x_vehicles,"cheetah",true) == 0) { price = 400000; model = 415; name = "cheetah"; }
else if(strcmp(x_vehicles,"moonbeam",true) == 0) { price = 25000; model = 418; name = "moonbeam"; }
else if(strcmp(x_vehicles,"esperanto",true) == 0) { price = 34000; model = 419; name = "esperanto"; }
else if(strcmp(x_vehicles,"washington",true) == 0) { price = 41000; model = 421; name = "washington"; }
else if(strcmp(x_vehicles,"banshee",true) == 0) { price = 91000; model = 429; name = "banshee"; }
else if(strcmp(x_vehicles,"admiral",true) == 0) { price = 41000; model = 445; name = "admiral"; }
else if(strcmp(x_vehicles,"turismo",true) == 0) { price = 500000; model = 451; name = "turismo"; }
else if(strcmp(x_vehicles,"sanchez",true) == 0) { price = 50000; model = 468; name = "sanchez"; }
else if(strcmp(x_vehicles,"zr-350",true) == 0) { price = 53000; model = 477; name = "zr-350"; }
else if(strcmp(x_vehicles,"comet",true) == 0) { price = 81500; model = 480; name = "comet"; }
else if(strcmp(x_vehicles,"burrito",true) == 0) { price = 50500; model = 482; name = "burrito"; }
else if(strcmp(x_vehicles,"rancher",true) == 0) { price = 85000; model = 505; name = "rancher"; }
else if(strcmp(x_vehicles,"greenwood",true) == 0) { price = 40000; model = 492; name = "greenwood"; }
else if(strcmp(x_vehicles,"fcr-900",true) == 0) { price = 100000; model = 521; name = "fcr-900"; }
else if(strcmp(x_vehicles,"feltzer",true) == 0) { price = 50000; model = 533; name = "feltzer"; }
else if(strcmp(x_vehicles,"remington",true) == 0) { price = 45000; model = 534; name = "remington"; }
else if(strcmp(x_vehicles,"bullet",true) == 0) {price = 350000; model = 541; name = "bullet"; }
else if(strcmp(x_vehicles,"jester",true) == 0) { price = 90000; model = 559; name = "jester"; }
else if(strcmp(x_vehicles,"sultan",true) == 0) { price = 200000; model = 560; name = "sultan"; }
else
{
SendClientMessage(playerid, COLOR_RED,"That vehicles doesn't exist");
return 1;
}
if(GetPlayerMoney(playerid) < price)
{
format(string, sizeof(string), "ERROR: You can't afford it ($%d)...", price);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return true;
}
new Float:X,Float:Y,Float:Z,Float:A;
new randOm = random(5);
switch(randOm)
{
case 0: { X = 338.487915; Y = -1340.168579; Z = 14.236722; A = 119.162109; }
case 1: { X = 340.812530; Y = -1345.224609; Z = 14.234894; A = 118.757064; }
case 2: { X = 343.519470; Y = -1350.123413; Z = 14.234891; A = 117.625938; }
case 3: { X = 346.163452; Y = -1354.852050; Z = 14.234894; A = 117.662635; }
case 4: { X = 347.777374; Y = -1357.674682; Z = 14.234870; A = 118.506446; }
}
new vlicenses = 3;
new query[500];
new vtype = 1;
format(query, sizeof(query), "INSERT INTO vehicles (id, model,color1,color2, x, y,z,a,name,owner,licenses,destroyed,type) VALUES (NULL, %d, %d, %d,%f, %f, %f, %f,'%s','%s',%d,%d,%d);",model, 1, 1, X, Y, Z, A,name, playerinfo[playerid][username],vlicenses,0,vtype);
mysql_query(query);
format(string, sizeof(string),"You bought a %s for %d.",name,price);
SendClientMessage(playerid, COLOR_YELLOW2, string);
SendClientMessage(playerid, COLOR_YELLOW2, "To see your new vehicle use /v list");
LoadPlayerKeys(playerid);
}
if(strcmp(x_v,"list",true) == 0)
{
new query[500], i = 1;
format(query, sizeof(query),"SELECT * FROM vehicles WHERE owner='%s'",playerinfo[playerid][username]);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row(query,"|"))
{
sscanf(query, "p<|>e<iiiiffffs[24]s[24]iiiiiii>", vehicleinfo[i]);
format(string, sizeof(string),"id(%d) Name:[%s] Times Destroyed [%d] Licenses [%d] ",i, vehicleinfo[i][Name],vehicleinfo[i][Destroyed],vehicleinfo[i][Licenses]);
printf("query: %s", query);
printf("Licenses: %d", vehicleinfo[i][Licenses]);
SendClientMessage(playerid,COLOR_YELLOW2, string);
i++;
}
}
if(strcmp(x_v,"get",true) == 0)
{
x_vehicles = strtok(params, idx);
if(!strlen(x_vehicles))
{
SendClientMessage(playerid,COLOR_YELLOW2," /v get (id) ");
return true;
}
if(vkey[playerid] > 0)
{
SendClientMessage(playerid, COLOR_RED,"You can only have one vehicle spawned!");
return 1;
}
if(strcmp(x_vehicles,"1",true) == 0)
{
if(playerkeys[playerid][0] == 0)
{
SendClientMessage(playerid, COLOR_RED,"You don't have any vehicle on this slot!");
return 1;
}
LoadVehicleID(playerkeys[playerid][0], playerid);
}
if(strcmp(x_vehicles,"2",true) == 0)
{
if(playerkeys[playerid][1] == 0)
{
SendClientMessage(playerid, COLOR_RED,"You don't have any vehicle on this slot!");
return 1;
}
LoadVehicleID(playerkeys[playerid][1], playerid);
}
if(strcmp(x_vehicles,"3",true) == 0)
{
if(playerkeys[playerid][2] == 0)
{
SendClientMessage(playerid, COLOR_RED,"You don't have any vehicle on this slot!");
return 1;
}
LoadVehicleID(playerkeys[playerid][2], playerid);
}
if(strcmp(x_vehicles,"4",true) == 0)
{
if(playerkeys[playerid][3] == 0)
{
SendClientMessage(playerid, COLOR_RED,"You don't have any vehicle on this slot!");
return 1;
}
LoadVehicleID(playerkeys[playerid][3], playerid);
}
if(strcmp(x_vehicles,"5",true) == 0)
{
if(playerkeys[playerid][4] == 0)
{
SendClientMessage(playerid, COLOR_RED,"You don't have any vehicle on this slot!");
return 1;
}
LoadVehicleID(playerkeys[playerid][4], playerid);
}
}
if(strcmp(x_v,"park",true) == 0)
{
new currentveh;
currentveh = GetPlayerVehicleID(playerid);
if(IsPlayerInAnyVehicle(playerid))
{
if(IsPlayerInVehicle(playerid,vkey[playerid]))
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, vehicleinfo[key[vkey[playerid]]][x],vehicleinfo[key[vkey[playerid]]][y],vehicleinfo[key[vkey[playerid]]][z]))
{
DestroyVehicle(currentveh);
vkey[playerid] = 0;
SendClientMessage(playerid, COLOR_YELLOW2,"Vehicle parked!");
}
else
{
SendClientMessage(playerid, COLOR_RED,"You are not at your vehicle parking place!");
}
}
}
}
if(strcmp(x_v,"setpark",true) == 0)
{
new Float:xx,Float:yy,Float:zz;
if(IsPlayerInVehicle(playerid,vkey[playerid] ))
{
GetVehiclePos(vkey[playerid],xx,yy,zz);
vehicleinfo[key[vkey[playerid]]][x] = xx;
vehicleinfo[key[vkey[playerid]]][y] = yy;
vehicleinfo[key[vkey[playerid]]][z] = zz;
new query[100];
format(query, sizeof(query),"UPDATE vehicles SET x = %f , y = %f , z = %f WHERE id = %d",xx,yy,zz,key[vkey[playerid]]);
mysql_query(query);
SendClientMessage(playerid, COLOR_YELLOW2,"You have changed your vehicle parking place!");
}
}
if(strcmp(x_v,"lock",true) == 0)
{
new pcarid = GetClosestCar(playerid);
if(pcarid == vkey[playerid])
{
if(CheckPlayerDistanceToVehicle(10, playerid, vkey[playerid]))
{
if(vehicleinfo[key[vkey[playerid]]][Lock] == 0)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetVehicleParamsForPlayer(vkey[playerid],i,0,1);
vehicleinfo[key[vkey[playerid]]][Lock] = 1;
GameTextForPlayer(playerid, "Vehicle locked", 3000, 1);
}
}
else
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetVehicleParamsForPlayer(vkey[playerid],i,0,0);
vehicleinfo[key[vkey[playerid]]][Lock] = 0;
GameTextForPlayer(playerid, "Vehicle unlocked", 3000, 1);
}
}
}
}
//
}
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, playerinfo[playerid][username],MAX_PLAYER_NAME);
LoadPlayerKeys(playerid);
vkey[playerid] = 0;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
stock ReturnUser(text[])
{
new pos = 0;
while (text[pos] < 0x21)
{
if(text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if(isNumeric(text[pos]))
{
userid = strval(text[pos]);
if(userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
userid = INVALID_PLAYER_ID;
else return userid;
}
}
new len = strlen(text[pos]);
new count3 = 0;
new pname[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerName(i, pname, sizeof (pname));
if(strcmp(pname, text[pos], true, len) == 0)
{
if(len == strlen(pname)) return i;
else
{
count3++;
userid = i;
}
}
}
}
if(count3 != 1)
{
userid = INVALID_PLAYER_ID;
}
return userid;
}
stock isNumeric(const string[])
{
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++)
{
if ((string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') || (string[i]=='-' && i!=0) || (string[i]=='+' && i!=0))
{
return false;
}
}
if (length==1 && (string[0]=='-' || string[0]=='+')) { return false; }
return true;
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
stock strvalEx( const string[] )
{
if( strlen( string ) >= 50 ) return false;
return strval(string);
}
forward GetClosestCar(playerid);
public GetClosestCar(playerid)
{
if (!IsPlayerConnected(playerid))
{
return -1;
}
new Float:prevdist = 100000.000;
new prevcar;
for (new carid = 0; carid < MAX_VEHICLES; carid++)
{
new Float:dist = GetDistanceToCar(playerid,carid);
if ((dist < prevdist))
{
prevdist = dist;
prevcar = carid;
}
}
return prevcar;
}
forward GetDistanceToCar(playerid,carid);
public GetDistanceToCar(playerid,carid)
{
new Float:dis;
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if (!IsPlayerConnected(playerid)) {
return -1;
}
GetPlayerPos(playerid,x1,y1,z1);
GetVehiclePos(carid,x2,y2,z2);
dis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
return floatround(dis);
}
stock CheckPlayerDistanceToVehicle(Float:radi, playerid, vehicleid)
{
if(IsPlayerConnected(playerid))
{
new Float:PX,Float:PY,Float:PZ,Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,PX,PY,PZ);
GetVehiclePos(vehicleid, X,Y,Z);
new Float:Distance = (X-PX)*(X-PX)+(Y-PY)*(Y-PY)+(Z-PZ)*(Z-PZ);
if(Distance <= radi*radi)
{
return true;
}
}
return false;
}
Now, I want to add a function: sell my car for an another player. My idea:
How can I do? I know this is a problems long-term but I still hope will be a someone help me enthusiasm. Thanks so much, very very and very much!
Respuesta: Add a function (sell my car an another player) for my vehicles system -