pawn Код:
#include <a_samp>
#include <a_mysql>
#include <string>
#include <streamer>
#include <a_zones>
#define mysql_host "localhost" // MySQL host. Default set.
#define mysql_user "root" // MySQL user. Default set
#define mysql_password " " // Password. Default is set.
#define mysql_database " " // MySQL Database. (Change)
#define ALTCOMMAND:%1->%2; \
COMMAND:%1(playerid, params[]) \
return cmd_%2(playerid, params);
#define HouseLoop(%1) for(new %1 = 0; %1 <sizeof(House); %1++)
enum iHouse
{
hID,
Float:outX, // Exterior
Float:outY, // Exterior
Float:outZ, // Exterior
Float:intX, // Interior
Float:intY, // Interior
Float:intZ, // Interior
intVW, // Interior
intINT, // Interior
Text3D:outLabel, // House Exterior label
owner[ 250 ], // House owner - displays on Label
sellprice, // If > than 0 it will be classed as on sale!
}
new House[][iHouse] = {
{0, 0.0,0.0,0.0, 0.0,0.0,0.0, 1},
{1, 0.0,0.0,0.0, 0.0,0.0,0.0, 2},
{2, 0.0,0.0,0.0, 0.0,0.0,0.0, 3},
{3, 0.0,0.0,0.0, 0.0,0.0,0.0, 4},
{4, 0.0,0.0,0.0, 0.0,0.0,0.0, 5},
{5, 0.0,0.0,0.0, 0.0,0.0,0.0, 6},
{6, 0.0,0.0,0.0, 0.0,0.0,0.0, 7},
{7, 0.0,0.0,0.0, 0.0,0.0,0.0, 8},
{8, 0.0,0.0,0.0, 0.0,0.0,0.0, 9},
{9, 0.0,0.0,0.0, 0.0,0.0,0.0, 10},
{10, 0.0,0.0,0.0, 0.0,0.0,0.0, 11},
{11, 0.0,0.0,0.0, 0.0,0.0,0.0, 12},
{12, 0.0,0.0,0.0, 0.0,0.0,0.0, 13},
{13, 0.0,0.0,0.0, 0.0,0.0,0.0, 14},
{14, 0.0,0.0,0.0, 0.0,0.0,0.0, 15},
{15, 0.0,0.0,0.0, 0.0,0.0,0.0, 16},
{16, 0.0,0.0,0.0, 0.0,0.0,0.0, 17},
{17, 0.0,0.0,0.0, 0.0,0.0,0.0, 18},
{18, 0.0,0.0,0.0, 0.0,0.0,0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0, 50}
};
forward mysql_start();
public mysql_start()
{
mysql_debug(1);
if(mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password))
{
print("[MYSQL] Connection successful!");
}
else
{
print("[MYSQL] There was an error connecting to the MYSQL server");
}
return 1;
}
public OnFilterScriptInit()
{
mysql_start();
/* mysql_query("CREATE TABLE IF NOT EXISTS HouseInfo (\
hID INT(150) UNSIGNED NOT NULL DEFAULT 0,\
outX float NOT NULL DEFAULT '0',\
outY float NOT NULL DEFAULT '0',\
outZ float NOT NULL DEFAULT '0',\
intX float NOT NULL DEFAULT '0',\
intY float NOT NULL DEFAULT '0',\
intZ float NOT NULL DEFAULT '0',\
intINT INT(25) UNSIGNED NOT NULL DEFAULT 0,\
intVW INT(25) UNSIGNED NOT NULL DEFAULT 0,\
sellprice INT(225) UNSIGNED NOT NULL DEFAULT 0,\
owner VARCHAR(225) NOT NULL DEFAULT 'Noone')");*/
LoadHouse();
new avayable, tmps[250], string[250];
HouseLoop(h)
{
if(House[h][sellprice] >= 1) { avayable = House[h][sellprice]; }
else { avayable = 0; }
new zone[60];
GetZone(House[h][outX],House[h][outY],House[h][outZ], zone);
format(tmps, 256, "{FF0000}[ {FFDAB9}%d, %s{FF0000}]\n{FFDAB9}Owner: {FF0000}%s", h, zone, House[h][owner]);
format(string, sizeof(string), "\n{FFDAB9}For Sale: {FF0000}$%s", House[h][sellprice]);
if(avayable) { strcat(tmps, string); }
House[h][outLabel] = CreateDynamic3DTextLabel(tmps, -1, House[h][outX], House[h][outY], House[h][outZ]+0.3, 20.0);
}
return 1;
}
public OnFilterScriptExit()
{
HouseLoop(h)
{
SaveHouses(h);
}
mysql_close();
return 1;
}
/*
From other people....
*/
stock myStrcpy(dest[], src[])
{
new i = 0;
while ((dest[i] = src[i])) i++;
}
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 IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0')
{
return 0;
}
}
return 1;
}
/*
Finish
*/
main()
{
print("\n---------------------------------------");
print(" Player house System by your boy GiGi!");
print("---------------------------------------\n");
}
public OnPlayerSpawn(playerid)
{
HouseLoop(h)
{
new owner1[24], pname[24];
GetPlayerName(playerid, pname, sizeof(pname));
format(owner1, sizeof(owner1),"%s",pname);
myStrcpy(owner1, House[h][owner]);
if(strcmp(pname,owner1,false)==0)
{
SetPlayerVirtualWorld(playerid, House[h][intVW]);
SetPlayerInterior(playerid, House[h][intINT]);
SetPlayerPos(playerid, House[h][intX], House[h][intY], House[h][intZ]);
}
else
{
SetPlayerVirtualWorld(playerid, 0);
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid,2771.63770, -1616.57593, 10.88870); // Some random spawn from Grand Lanrc :S
}
}
return 1;
}
stock HouseExitOrEnter(playerid)
{
HouseLoop(h)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, House[h][intX], House[h][intY], House[h][intZ]))
{
new playerINT = GetPlayerInterior(playerid), playerVW = GetPlayerVirtualWorld(playerid);
if(playerINT == House[h][intINT])
{
if(playerVW == House[h][intVW])
{
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerPos(playerid, House[h][outX], House[h][outY], House[h][outZ]);
}
}
}
if(IsPlayerInRangeOfPoint(playerid, 5.0, House[h][outX], House[h][outY], House[h][outZ]))
{
new playerINT = GetPlayerInterior(playerid), playerVW = GetPlayerVirtualWorld(playerid);
if(playerINT == 0)
{
if(playerVW == 0)
{
SetPlayerInterior(playerid, House[h][intINT]);
SetPlayerVirtualWorld(playerid, House[h][intVW]);
SetPlayerPos(playerid, House[h][intX], House[h][intY], House[h][intZ]);
}
}
}
}
return 1;
}
stock SaveHouses(h) // Saved every variable sepratly. - More simple.
{
new query[750];
format(query, sizeof(query), "UPDATE `HouseInfo` SET `outX`='%f' WHERE `hID`=%d", House[h][outX], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `outY`='%f' WHERE `hID`=%d", House[h][outY], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `outZ`='%f' WHERE `hID`=%d", House[h][outZ], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intX`='%f' WHERE `hID`=%d", House[h][intX], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intY`='%f' WHERE `hID`=%d", House[h][intY], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intZ`='%f' WHERE `hID`=%d", House[h][intZ], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intVW`='%d' WHERE `hID`=%d", House[h][intVW], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intINT`='%d' WHERE `hID`=%d", House[h][intINT], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `owner`='%s' WHERE `hID`=%d", House[h][owner], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `sellprice`='%d' WHERE `hID`=%d", House[h][sellprice], h);
mysql_query(query);
return 1;
}
stock LoadHouse() //FAILED!
{
HouseLoop(h)
{
new query[250];
format(query, sizeof(query),"SELECT * FROM `HouseInfo` WHERE `hID`=%d", h);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(rows == 1)
{
ReloadHouse(h);
}
if(!rows)
{
format(query,sizeof(query),"INSERT INTO `HouseInfo` (hID) VALUES (%d);", h);
mysql_query(query);
//==============================================================================
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intX`='0.0' WHERE `hID`=%d", House[h][intX], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intY`='0.0' WHERE `hID`=%d", House[h][intY], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intZ`='0.0' WHERE `hID`=%d", House[h][intZ], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `outX`='%f' WHERE `hID`=%d", House[h][intX], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `outY`='%f' WHERE `hID`=%d", House[h][intY], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `outZ`='%f' WHERE `hID`=%d", House[h][intZ], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intVW`='%d' WHERE `hID`=%d", House[h][intVW], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `intINT`='%d' WHERE `hID`=%d", House[h][intINT], h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `owner`='None' WHERE `hID`=%d", h);
mysql_query(query);
format(query, sizeof(query), "UPDATE `HouseInfo` SET `sellprice`='%d' WHERE `hID`=%d", House[h][sellprice], h);
mysql_query(query);
ReloadHouse(h);
}
mysql_free_result();
}
}
stock ReloadHouse(i) //FAILED!
{
DestroyDynamic3DTextLabel(House[i][outLabel]);
new query[300], savingstring[20];
format(query, sizeof(query), "SELECT * FROM `HouseInfo` WHERE `hID`=%d", i);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(savingstring, "hID");
House[i][hID] = strval(savingstring);
mysql_fetch_field_row(savingstring, "outX");
House[i][outX] = strval(savingstring);
mysql_fetch_field_row(savingstring, "outY");
House[i][outY] = strval(savingstring);
mysql_fetch_field_row(savingstring, "outZ");
House[i][outZ] = strval(savingstring);
mysql_fetch_field_row(savingstring, "intX");
House[i][intX] = strval(savingstring);
mysql_fetch_field_row(savingstring, "intY");
House[i][intY] = strval(savingstring);
mysql_fetch_field_row(savingstring, "intZ");
House[i][intZ] = strval(savingstring);
mysql_fetch_field_row(savingstring, "intVW");
House[i][intVW] = strval(savingstring);
mysql_fetch_field_row(savingstring, "intINT");
House[i][intINT] = strval(savingstring);
mysql_fetch_field_row(savingstring, "owner");
strmid(House[i][owner], savingstring, 0, strlen(savingstring), 50);
mysql_fetch_field_row(savingstring, "sellprice");
House[i][sellprice] = strval(savingstring);
}
mysql_free_result();
new avayable, string[250], tmps[100];
if(House[i][sellprice] >= 1) { avayable = House[i][sellprice]; }
else { avayable = 0; }
new zone[60];
GetZone(House[i][outX],House[i][outY],House[i][outZ], zone);
format(tmps, 256, "{FF0000}[ {FFDAB9}%d, %s{FF0000}]\n{FFDAB9}Owner: {FF0000}%s", i, zone, House[i][owner]);
format(string, sizeof(string), "\n{FFDAB9}For Sale: {FF0000}$%s", House[i][sellprice]);
if(avayable) { strcat(tmps, string); }
House[i][outLabel] = CreateDynamic3DTextLabel(tmps, -1, House[i][outX], House[i][outY], House[i][outZ]+0.3, 20.0);
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & 16 && !IsPlayerInAnyVehicle(playerid))
{
HouseExitOrEnter(playerid);
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new idx;
new cmd[256];
new query[250];
new where[150];
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/move", true) == 0)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not a RCON admin");
new iHouse1;
new Float:ok[3];
GetPlayerPos(playerid, ok[0], ok[1], ok[2]);
format(query, sizeof(query), "UPDATE HouseInfo SET outX=%f, outY=%f, outZ=%f WHERE hID=%d", ok[0], ok[1], ok[2], iHouse1);
mysql_query(query);
format(where, sizeof(where),"[House] %d house has been moved to the coords: %f,%f,%f",ok[0],ok[1],ok[2]);
SendClientMessage(playerid, -1, where);
ReloadHouse(iHouse1);
}
if(strcmp(cmd, "/setinterior", true) == 0)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not a RCON admin");
new iHouse1;
new Float:ok[3];
GetPlayerPos(playerid, ok[0], ok[1], ok[2]);
new playerint = GetPlayerInterior(playerid), playervw = GetPlayerVirtualWorld(playerid);
format(query, sizeof(query), "UPDATE HouseInfo SET intX=%f, intY=%f, intZ=%f, intINT=%d, intVW=%d WHERE hID=%d", ok[0], ok[1], ok[2], playerint, playervw, iHouse1);
mysql_query(query);
format(where, sizeof(where),"[House] %d interior has been set to the coords: %f,%f,%f",ok[0],ok[1],ok[2]);
SendClientMessage(playerid, -1, where);
ReloadHouse(iHouse1);
}
if(strcmp(cmd, "/reloadall", true) == 0)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not a RCON admin");
HouseLoop(i)
{
ReloadHouse(i);
}
return 1;
}
return 0;
}