Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Dinaminė namų sistema.
- Autorius "Bebras"
- Turėk pagarbos autoriui ir jo darbui - netrink jo vardo.
- */
- /*
- native LoadHouses(Connection_Handler);
- native AddHouse(Connection_Handler,HousePrice,InteriorID,Float:EntranceX,Float:EntranceY,Float:EntranceZ);
- native GetFreeHouseArraySlot();
- native ReloadHouses(Connection_Handler);
- native Houses_OnPlayerKeyStateChange(playerid,newkeys,oldkeys,key,Float:distance=5.0);
- native IsPlayerInRangeOfHouseEntrance(playerid,Float:distance=5.0);
- native IsPlayerInRangeOfHouseExit(playerid,Float:distance=5.0);
- native LockHouse(playerid,houseArrayindex=-1);
- native UnlockHouse(playerid,houseArrayindex=-1);
- native IsHouseLocked(houseArrayIndex);
- native ChangeHouseInterior(Connection_Handler,houseArrayIndex,newInteriorID);
- native DeleteHouse(Connection_Handler,houseArrayIndex);
- native ChangeHouseOwner(Connection_Handler,houseArrayIndex,newowner[]);
- native ChangeHousePrice(Connection_Handler,houseArrayIndex,newprice);
- */
- #if !defined MAX_HOUSES
- #define MAX_HOUSES 100
- #endif
- #if !defined LABEL_COLOR
- #define LABEL_COLOR 0xFFFF00FF
- #endif
- #if !defined isnull
- #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
- #endif
- enum hint {
- Float:XX,
- Float:YY,
- Float:ZZ,
- Inte
- };
- new const HouseInteriors[][hint] = {
- {-750.80,491.00,1371.70,1},
- {2251.85,-1138.16,1050.63,9}
- };
- enum h_info {
- HouseId,
- Owner[MAX_PLAYER_NAME],
- Float:EnX,
- Float:EnY,
- Float:EnZ,
- Inter,
- Float:ExX,
- Float:ExY,
- Float:ExZ,
- Price,
- Locked,
- Text3D:Label
- };
- new Houses[MAX_HOUSES][h_info];
- stock LoadHouses(Connection_Handler)
- {
- mysql_function_query(Connection_Handler,"SELECT * FROM houses",true,"OnHouseLoad","i",Connection_Handler);
- return 1;
- }
- forward OnHouseLoad(Connection_Handler);
- public OnHouseLoad(Connection_Handler)
- {
- new rows,fields,tmp[32],ticks = GetTickCount(),string[62];
- cache_get_data(rows,fields);
- for(new i; i<rows; i++)
- {
- cache_get_row(i,0,tmp,Connection_Handler); Houses[i][HouseId] = strval(tmp);
- cache_get_row(i,1,tmp,Connection_Handler); format(Houses[i][Owner],sizeof(tmp),tmp);
- cache_get_row(i,2,tmp,Connection_Handler); Houses[i][EnX] = floatstr(tmp);
- cache_get_row(i,3,tmp,Connection_Handler); Houses[i][EnY] = floatstr(tmp);
- cache_get_row(i,4,tmp,Connection_Handler); Houses[i][EnZ] = floatstr(tmp);
- cache_get_row(i,5,tmp,Connection_Handler); Houses[i][Inter] = strval(tmp);
- cache_get_row(i,6,tmp,Connection_Handler); Houses[i][ExX] = floatstr(tmp);
- cache_get_row(i,7,tmp,Connection_Handler); Houses[i][ExY] = floatstr(tmp);
- cache_get_row(i,8,tmp,Connection_Handler); Houses[i][ExZ] = floatstr(tmp);
- cache_get_row(i,9,tmp,Connection_Handler); Houses[i][Price] = strval(tmp);
- cache_get_row(i,10,tmp,Connection_Handler); Houses[i][Locked] = strval(tmp);
- printf("OIwner:%s",Houses[i][Owner]);
- if(isnull(Houses[i][Owner])) format(string,sizeof(string),"Namas parduodamas\nKaina:%d",Houses[i][Price]);
- else format(string,sizeof(string),"Savininkas: %s",Houses[i][Owner]);
- Houses[i][Label] = Create3DTextLabel(string,LABEL_COLOR,Houses[i][EnX],Houses[i][EnY],Houses[i][EnZ],25.0,0,1);
- }
- printf("Uzkrauti %d namai. Krovimo trukme: %dMS",rows,GetTickCount() - ticks);
- return 1;
- }
- stock AddHouse(Connection_Handler,HousePrice,InteriorID,Float:EntranceX,Float:EntranceY,Float:EntranceZ)
- {
- new slot = GetFreeHouseArraySlot(),query[150];
- if(slot == -1)
- {
- print("[ERROR]Pasiektas namu limitas. Istrinkite senus arba padidinkite \"MAX_HOUSES\".");
- return 0;
- }
- Houses[slot][Price] = HousePrice;
- Houses[slot][ExX] = HouseInteriors[InteriorID][XX];
- Houses[slot][ExY] = HouseInteriors[InteriorID][YY];
- Houses[slot][ExZ] = HouseInteriors[InteriorID][YY];
- Houses[slot][Inter] = HouseInteriors[InteriorID][Inte];
- Houses[slot][EnX] = EntranceX;
- Houses[slot][EnY] = EntranceY;
- Houses[slot][EnZ] = EntranceZ;
- format(query,sizeof(query),"Namas parduodamas\nKaina:%d",Houses[slot][Price]);
- Houses[slot][Label] = Create3DTextLabel(query,LABEL_COLOR,Houses[slot][EnX],Houses[slot][EnY],Houses[slot][EnZ],15.0,0,1);
- format(query,sizeof(query),"INSERT INTO houses (EnX,EnY,EnZ,Inter,ExX,ExY,ExZ,Price)VALUES(%f,%f,%f,%d,%f,%f,%f,%d)",
- Houses[slot][EnX],Houses[slot][EnY],Houses[slot][EnZ],Houses[slot][Inter],Houses[slot][ExX],
- Houses[slot][ExY],Houses[slot][ExZ],Houses[slot][Price]);
- mysql_function_query(Connection_Handler,query,true,"OnHouseAdd","i",slot);
- return 1;
- }
- forward OnHouseAdd(slot);
- public OnHouseAdd(slot)
- {
- Houses[slot][HouseId] = mysql_insert_id();
- return 1;
- }
- stock ReloadHouses(Connection_Handler)
- {
- for(new i; i<MAX_HOUSES; i++)
- {
- Delete3DTextLabel(Houses[i][Label]);
- LoadHouses(Connection_Handler);
- }
- return 1;
- }
- stock Houses_OnPlayerKeyStateChange(playerid,newkeys,oldkeys,key,Float:distance=5.0)
- {
- if((newkeys & key) && !(oldkeys & key))
- {
- if(IsHouseLocked(GetPlayerHouseId(playerid,distance))) return 0;
- if(IsPlayerInRangeOfHouseEntrance(playerid,distance))
- {
- SetPlayerInterior(playerid,Houses[GetPlayerHouseId(playerid,distance)][Inter]);
- SetPlayerPos(playerid,Houses[GetPlayerHouseId(playerid,distance)][ExX],Houses[GetPlayerHouseId(playerid,distance)][ExY],Houses[GetPlayerHouseId(playerid,distance)][ExZ]);
- SetPlayerVirtualWorld(playerid,Houses[GetPlayerHouseId(playerid,distance)][HouseId]);
- }
- else if(IsPlayerInRangeOfHouseExit(playerid,distance))
- {
- SetPlayerInterior(playerid,0);
- SetPlayerPos(playerid,Houses[GetPlayerHouseId(playerid,distance)][EnX],Houses[GetPlayerHouseId(playerid,distance)][EnY],Houses[GetPlayerHouseId(playerid,distance)][EnZ]);
- SetPlayerVirtualWorld(playerid,0);
- }
- }
- return 1;
- }
- stock LockHouse(playerid,houseArrayindex=-1)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- if(houseArrayindex == -1) houseArrayindex = GetPlayerHouseId(playerid);
- if(isnull(Houses[houseArrayindex][Owner])) return 0;
- else if(strcmp(name,Houses[houseArrayindex][Owner])) return 0;
- if(Houses[houseArrayindex][Locked] == 0)
- {
- Houses[houseArrayindex][Locked] = 1;
- return 1;
- }
- return 0;
- }
- stock UnlockHouse(playerid,houseArrayindex=-1)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- if(houseArrayindex == -1) houseArrayindex = GetPlayerHouseId(playerid);
- if(isnull(Houses[houseArrayindex][Owner])) return 0;
- else if(strcmp(name,Houses[houseArrayindex][Owner])) return 0;
- if(Houses[houseArrayindex][Locked] == 1)
- {
- Houses[houseArrayindex][Locked] = 0;
- return 1;
- }
- return 0;
- }
- stock IsHouseOwned(houseArrayIndex)
- {
- if(isnull(Houses[houseArrayIndex][Owner])) return true;
- return false;
- }
- stock IsHouseLocked(houseArrayIndex)
- {
- if(Houses[houseArrayIndex][Locked] ==1 ) return true;
- else return false;
- }
- stock IsPlayerInRangeOfHouseEntrance(playerid,Float:distance=5.0)
- {
- for(new i; i<MAX_HOUSES; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid,distance,Houses[i][EnX],Houses[i][EnY],Houses[i][EnZ])) return true;
- }
- return false;
- }
- stock IsPlayerInRangeOfHouseExit(playerid,Float:distance=5.0)
- {
- for(new i; i<MAX_HOUSES; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid,distance,Houses[i][ExX],Houses[i][ExY],Houses[i][ExZ])) return true;
- }
- return false;
- }
- stock ChangeHousePrice(Connection_Handler,houseArrayIndex,newprice)
- {
- new query[60];
- Houses[houseArrayIndex][Price] = newprice;
- format(query,sizeof(query),"UPDATE houses SET Price = %d WHERE HouseID=%d",Houses[houseArrayIndex][Price],Houses[houseArrayIndex][HouseId]);
- mysql_function_query(Connection_Handler,query,false,"House_SendQuery","");
- if(!isHouseOwned(houseArrayIndex)) format(query,sizeof(query),"Namas parduodamas\nKaina: %d",Houses[houseArrayIndex][Price]);
- Update3DTextLabelText(Houses[houseArrayIndex][Label],LABEL_COLOR,query);
- return 1;
- }
- stock ChangeHouseOwner(Connection_Handler,houseArrayIndex,newowner[])
- {
- new query[80];
- strins(Houses[houseArrayIndex][Owner],newowner,0,24);
- format(query,sizeof(query),"Savininkas: %s", Houses[houseArrayIndex][Owner]);
- Update3DTextLabelText(Houses[houseArrayIndex][Label],LABEL_COLOR,query);
- format(query,sizeof(query),"UPDATE houses SET Owner ='%s' WHERE HouseID=%d",Houses[houseArrayIndex][Owner],Houses[houseArrayIndex][HouseId]);
- mysql_function_query(Connection_Handler,query,false,"House_SendQuery","");
- return 1;
- }
- stock DeleteHouse(Connection_Handler,houseArrayIndex)
- {
- new query[40];
- Delete3DTextLabel(Houses[houseArrayIndex][Label]);
- format(query,sizeof(query),"DELETE FROM houses WHERE HouseID=%d",Houses[houseArrayIndex][HouseId]);
- mysql_function_query(Connection_Handler,query,false,"House_SendQuery","");
- Houses[houseArrayIndex][HouseId] = 0;
- return 1;
- }
- stock ChangeHouseInterior(Connection_Handler,houseArrayIndex,newInteriorID)
- {
- new query[160];
- Houses[houseArrayIndex][ExX] = HouseInteriors[newInteriorID][XX];
- Houses[houseArrayIndex][ExY] = HouseInteriors[newInteriorID][YY];
- Houses[houseArrayIndex][ExZ] = HouseInteriors[newInteriorID][ZZ];
- Houses[houseArrayIndex][Inter]= HouseInteriors[newInteriorID][Inte];
- format(query,sizeof(query),"UPDATE houses SET ExX=%f,ExY=%f,ExZ=%f,Inter=%d WHERE HouseID=%d",
- HouseInteriors[newInteriorID][XX],HouseInteriors[newInteriorID][YY],
- HouseInteriors[newInteriorID][ZZ],HouseInteriors[newInteriorID][Inte],
- Houses[houseArrayIndex][HouseId]);
- mysql_function_query(Connection_Handler,query,false,"House_SendQuery","");
- return 1;
- }
- stock GetFreeHouseArraySlot()
- {
- for(new i; i<MAX_HOUSES; i++)
- {
- if(Houses[i][HouseId] == 0) return i;
- }
- return -1;
- }
- stock GetPlayerHouseId(playerid,Float:dis=5.0)
- {
- for(new i; i<MAX_HOUSES; i++)
- {
- if(GetPlayerVirtualWorld(playerid) == 0) if(IsPlayerInRangeOfPoint(playerid,dis,Houses[i][EnX],Houses[i][EnY],Houses[i][EnZ])) return i;
- else if(GetPlayerVirtualWorld(playerid) == Houses[i][HouseId]) return i;
- }
- return -1;
- }
- forward House_SendQuery();
- public House_SendQuery()
- {
- return 1;
- }
- public OnQueryError( errorid, error[], callback[], query[], connectionHandle )
- {
- printf("EID: %d | Error: %s | Query: %s", errorid, error, query);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement