Advertisement
blackwolfsden

find player location/create location

Dec 9th, 2013
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. --[[ 1 first is beginning section checking if the location exsists in the -->sql<--
  2.      if it doesn't then it creates it using CreateLocation.
  3.      if it does exsist then it gets location entryid using GetLocationId ]]--
  4. function GWcommands(event, pPlayer, msg, type, language)
  5. local Xentrydb = WorldDBQuery("SELECT `entry` FROM guild_warz.zones WHERE `map_id` = '"..pPlayer:GetMapId().."' AND `area_id` = '"..pPlayer:GetAreaId().."' AND `zone_id` = '"..pPlayer:GetZoneId().."';");
  6.     if(Xentrydb==nil)then
  7.         CreateLocation(pPlayer:GetMapId(), pPlayer:GetAreaId(), pPlayer:GetZoneId())
  8.         end
  9. local LocId = GetLocationId(pPlayer)
  10.  
  11. --[[ 2 this again scans sql to get the location id.
  12.       I have been trying to get it to scan the table to match up the
  13.        map,area,zone values to the players map,area,zone with no luck so far.
  14.        if I can get it to find the location by table then I can
  15.        get it to check if it exists in the table and if not then CreateLocation.
  16.     even tried to create a table just for this trying to use multiple keys(location mapid,areaid,zoneid
  17.     but it fell flat on its face lol even tried sub table setup GWTloc.map.area.zone.Entryid
  18. local function GetLocationId(player, unit)
  19. local Locdb=WorldDBQuery("SELECT `entry` FROM guild_warz.zones WHERE `map_id`='"..player:GetMapId().."' AND `area_id`='"..player:GetAreaId().."' and `zone_id`='"..player:GetZoneId().."';");
  20. return Locdb:GetColumn(0):GetULong() or 0;
  21. end
  22.  
  23. --[[ 3 this should be fine it does only insert/update
  24. local function CreateLocation(map, area, zone)
  25. local CLentrydb = WorldDBQuery("SELECT `entry` FROM guild_warz.zones;");
  26.         repeat
  27.             CLentry = CLentrydb:GetColumn(0):GetLong()
  28.             until(CLentrydb:NextRow()~=true)
  29.     CLentry=(CLentry+1)
  30.     WorldDBQuery("INSERT INTO guild_warz.zones SET `entry` = '"..CLentry.."';");
  31.     WorldDBQuery("UPDATE guild_warz.zones SET `map_id` = '"..map.."' WHERE `entry` = '"..CLentry.."';");
  32.     WorldDBQuery("UPDATE guild_warz.zones SET `area_id` = '"..area.."' WHERE `entry` = '"..CLentry.."';");
  33.     WorldDBQuery("UPDATE guild_warz.zones SET `zone_id` = '"..zone.."' WHERE `entry` = '"..CLentry.."';");
  34.     WorldDBQuery("UPDATE guild_warz.zones SET `guild_name` = '"..Server.."' WHERE `entry` = '"..CLentry.."';");
  35.     GWARZ[CLentry] = {}
  36.     GWARZ[CLentry].Entryid = CLentry
  37.     GWARZ[CLentry].Mapid = map
  38.     GWARZ[CLentry].Areaid = area
  39.     GWARZ[CLentry].Zoneid = zone
  40.     GWARZ[CLentry].Guildname = Server
  41.     GWARZ[CLentry].Team = 2
  42.     GWARZ[CLentry].Buildingcnt = 0
  43.     GWARZ[CLentry].Pigcnt = 0
  44.     GWARZ[CLentry].Guardcnt = 0
  45.     GWARZ[CLentry].Flagid = 0
  46. print(""..CLentry..": created")
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement