PHP код:
/*
* Example: house doors
* © SA-MP Community
*/
#define MAX_HOUSES (1000)
enum E_HOUSES {
bool: LOCKDOOR,
OWNERID,
ENTER_INTERIORID,
ENTER_WORLDID,
EXIT_INTERIORID,
EXIT_WORLDID,
Float: EXIT_X,
Float: EXIT_Y,
Float: EXIT_Z,
Float: ENTER_X,
Float: ENTER_Y,
Float: ENTER_Z
}
new houses[MAX_HOUSES][E_HOUSES];
enum E_P_INFO {
HOUSEID,
}
new p_info[MAX_PLAYERS][E_P_INFO];
/*
* native SetPlayerHouseID(playerid, houseid);
* native GetPlayerHouseID(playerid);
* native SetHouseLock(houseid, bool:onlock);
* native IsHouseLocked(houseid);
* native SetHousePosEnter(houseid, Float:x, Float:y, Float:z, interiorid, worldid);
* native SetHousePosExit(houseid, Float:x, Float:y, Float:z, interiorid, worldid);
*/
#define SetPlayerHouseID(%1,%2) p_info[%1][HOUSEID]=%1
#define GetPlayerHouseID(%1) p_info[%1][HOUSEID]
#define SetHouseLock(%1,%2) houses[%1][LOCKDOOR]=%2
#define IsHouseLocked(%1) (houses[%1][LOCKDOOR])
#define SetHousePosEnter(%1,%2,%3,%4,%5,%6) houses[%1][ENTER_X]=%2; houses[%1][ENTER_Y]=%3; houses[%1][ENTER_Z]=%4; houses[%1][ENTER_INTERIORID]=%5; houses[%1][ENTER_WORLDID]=%6
#define SetHousePosExit(%1,%2,%3,%4,%5,%6) houses[%1][EXIT_X]=%2; houses[%1][EXIT_Y]=%3; houses[%1][EXIT_Z]=%4; houses[%1][EXIT_INTERIORID]=%5; houses[%1][EXIT_WORLDID]=%6
public OnGameModeInit() {
// <- Here will be your houses from a database loader
// His write yourself: SQLite or MySQL
// NOTE: On loading used array 'houses'
return true;
}
CMD:lock(playerid, params[]) {
#pragma unused params
new houseid = GetPlayerHouseID(playerid);
if (houseid) {
SetHouseLock(houseid, true);
} else {
SendClientMessange(playerid, -1, "You not inside house");
}
return true;
}
CMD:unlock(playerid, params[]) {
#pragma unused params
new houseid = GetPlayerHouseID(playerid);
if (houseid) {
SetHouseLock(houseid, false);
} else {
SendClientMessange(playerid, -1, "You not inside house");
}
return true;
}
CMD:enter(playerid, params[]) {
#pragma unused params
for (new i; i < MAX_HOUSES; i++) {
if (IsPlayerInRangeOfPoint(playerid, 2.0, houses[i][ENTER_X], houses[i][ENTER_Y], houses[i][ENTER_Z])) {
if (!IsHouseLocked(i)) {
SetPlayerHouseID(playerid, i+1);
houses[i][EXIT_INTERIORID] = GetPlayerInterior(playerid);
houses[i][EXIT_WORLDID] = GetPlayerVirtualWorld(playerid);
SetPlayerPos(playerid, houses[i][EXIT_X], houses[i][EXIT_Y], houses[i][EXIT_Z]);
SetPlayerInterior(playerid, houses[i][ENTER_INTERIORID]);
SetPlayerVertualWorld(playerid, houses[i][ENTER_WORLDID]);
SendClientMessange(playerid, -1, "You entered in house");
break;
} else {
SendClientMessange(playerid, -1, "House is closed.");
break;
}
}
}
return true;
}
CMD:exit(playerid, params[]) {
#pragma unused params
for (new i; i < MAX_HOUSES; i++) {
if (IsPlayerInRangeOfPoint(playerid, 2.0, houses[i][EXIT_X], houses[i][EXIT_Y], houses[i][EXIT_Z])) {
SetPlayerHouseID(playerid, 0);
SetPlayerPos(playerid, houses[i][ENTER_X], houses[i][ENTER_Y], houses[i][ENTER_Z]);
SetPlayerInterior(playerid, houses[i][EXIT_INTERIORID]);
SetPlayerVertualWorld(playerid, houses[i][EXIT_WORLDID]);
SendClientMessange(playerid, -1, "You exited of house");
break;
}
}
return true;
}
CMD:makeexit(playerid, params[]) {
new
houseid
;
if (sscanf(params, "i", houseid)) {
format(msg, sizeof(msg), "Invalid cmd. Use: /makeexit [houseid:0-%d]", houseid, MAX_HOUSES-1);
SendClientMessange(playerid, -1, msg);
return true;
}
new
Float: x,
Float: y,
Float: z
;
GetPlayerPos(playerid, x, y, z);
SetHousePosExit(houseid, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
new
msg[128]
;
format(msg, sizeof(msg), "You maked <exit> house id %d", houseid);
SendClientMessange(playerid, -1, msg);
return true;
}
CMD:makeenter(playerid, params[]) {
new
houseid
;
if (sscanf(params, "i", houseid)) {
format(msg, sizeof(msg), "Invalid cmd. Use: /makeenter [houseid:0-%d]", houseid, MAX_HOUSES-1);
SendClientMessange(playerid, -1, msg);
return true;
}
new
Float: x,
Float: y,
Float: z
;
GetPlayerPos(playerid, x, y, z);
SetHousePosEnter(houseid, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
new
msg[128]
;
format(msg, sizeof(msg), "You maked <enter> house id %d", houseid);
SendClientMessange(playerid, -1, msg);
return true;
}