Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- @autor whitetiiger
- @time 12.07.2016 9:48Uhr
- @table houses
- @version 1.0
- @ext OnFactionFinish()
- */
- #define MAX_FACTION [Hier Maximale Anzahl eintragen]
- enum faction_data
- {
- bool:fdActive,
- fdId,
- fdUser_id,
- Float:fdPosX,
- Float:fdPosY,
- Float:fdPosZ,
- Float:fdPrice,
- }
- new FactionData[MAX_FACTION][faction_data];
- stock LoadAllFaction()
- {
- new query[128];
- format(query, 128, "SELECT * FROM houses");
- mysql_tquery(Handle, query, "OnLoadAllFaction", "");
- return 1;
- }
- forward OnLoadAllFaction();
- public OnLoadAllFaction()
- {
- new rows, fields;
- cache_get_data(rows, fields, Handle);
- for(new i = 0; i < rows; i++)
- {
- new factionid = GetFreeFactionID();
- if(factionid == -1) return -1;
- FactionData[factionid][fdId] = cache_get_field_content_int(i, "id", Handle);
- FactionData[factionid][fdUser_id] = cache_get_field_content_int(i, "user_id", Handle);
- FactionData[factionid][fdPosX] = cache_get_field_content_float(i,"posX",Handle);
- FactionData[factionid][fdPosY] = cache_get_field_content_float(i,"posY",Handle);
- FactionData[factionid][fdPosZ] = cache_get_field_content_float(i,"posZ",Handle);
- FactionData[factionid][fdPrice] = cache_get_field_content_float(i,"price",Handle);
- OnFactionFinish(factionid);
- }
- return 1;
- }
- stock LoadFactionByID(Id)
- {
- new query[128];
- format(query, 128, "SELECT * FROM houses WHERE id = '%d'",Id);
- mysql_tquery(Handle, query, "OnLoadFactionByID", "");
- return 1;
- }
- forward OnLoadFactionByID();
- public OnLoadFactionByID()
- {
- new factionid = GetFreeFactionID();
- if(factionid == -1) return -1;
- FactionData[factionid][fdId] = cache_get_field_content_int(0, "id", Handle);
- FactionData[factionid][fdUser_id] = cache_get_field_content_int(0, "user_id", Handle);
- FactionData[factionid][fdPosX] = cache_get_field_content_float(0,"posX",Handle);
- FactionData[factionid][fdPosY] = cache_get_field_content_float(0,"posY",Handle);
- FactionData[factionid][fdPosZ] = cache_get_field_content_float(0,"posZ",Handle);
- FactionData[factionid][fdPrice] = cache_get_field_content_float(0,"price",Handle);
- OnFactionFinish(factionid);
- return 1;
- }
- stock OnFactionFinish(factionid)
- {
- FactionData[factionid][fdActive] = true;
- return 1;
- }
- stock ReloadFactionByID(factionid)
- {
- DestroyFaction(factionid);
- LoadFactionByID(FactionData[factionid][fdId]);
- return 1;
- }
- stock CreateFaction() Hier Parameter anpassen!
- {
- new factionid = GetFreeFactionID(), Float:Pos[3];
- if(factionid == -1) return -1;
- GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
- new query[128]; Länge anpassen!
- format(query, sizeof(query), "INSERT INTO `houses`(`user_id`, `posX`, `posY`, `posZ`, `price`) VALUES ('%d', '%f', '%f', '%f', '%f')",value);
- mysql_tquery(Handle, query, "OnCreateFaction", "");
- return factionid;
- }
- forward OnCreateFaction();
- public OnCreateFaction()
- {
- LoadFactionByID(cache_insert_id());
- return 1;
- }
- stock SaveFaction(factionid)
- {
- new query[177];
- format(query,sizeof(query),"UPDATE `houses` SET `user_id` = '%d', `posX` = '%f', `posY` = '%f', `posZ` = '%f', `price` = '%f' WHERE id='%d'", FactionData[factionid][fdUser_id], FactionData[factionid][fdPosX], FactionData[factionid][fdPosY], FactionData[factionid][fdPosZ], FactionData[factionid][fdPrice], FactionData[factionid][fdId]);
- mysql_tquery(Handle, query, "", "");
- return 1;
- }
- stock DeleteFaction(factionid)
- {
- if(FactionData[factionid][fdActive] == false) return -2;
- new query[128];
- format(query, 128, "DELETE FROM `houses` WHERE id = '%d'",FactionData[factionid][fdId]);
- mysql_tquery(Handle, query, "", "");
- FactionData[factionid][fdActive] = false;
- return 1;
- }
- stock DestroyFaction(factionid)
- {
- if(FactionData[factionid][fdActive] == false) return -2;
- FactionData[factionid][fdActive] = false;
- return 1;
- }
- stock GetFreeFactionID()
- {
- for(new factionid=0; factionid<MAX_FACTION; factionid++)
- {
- if(FactionData[factionid][fdActive] == true) continue;
- return factionid;
- }
- return -1;
- }
- stock GetFactionCount()
- {
- new count = 0;
- for(new factionid=0; factionid<MAX_FACTION; factionid++)
- {
- if(FactionData[factionid][fdActive] == false) continue;
- count ++;
- }
- return count;
- }
- stock getNearstFaction(playerid) {
- new x = -1, Float: distanz[2];
- for(new factionid; factionid <MAX_FACTION; factionid++) {
- distanz[0] = GetPlayerDistanceFromPoint(playerid, FactionData[factionid][fdPosX], FactionData[factionid][fdPosY], FactionData[factionid][fdPosZ]);
- if(FactionData[factionid][fdActive] == true && distanz[0] < distanz[1]) x = factionid, distanz[1] = distanz[0];
- }
- return x;
- }
- stock GetFactionID(dbID)
- {
- for(new factionid=0; factionid <MAX_FACTION; factionid++)
- {
- if(FactionData[factionid][fdActive] == false) continue;
- if(dbID != FactionData[factionid][fdId]) continue;
- return factionid;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement