gangland吧 关注:500贴子:4,130
  • 3回复贴,共1

关于购买建筑物

取消只看楼主收藏回复

tARMSDEALERs = findBusinessesInRadius("ARMSDEALER",0,0,999999999)
local ARMSDEALER=nil
local sl=2
local ARMSDEALERindex=nil
local dist=999999999
for index, value in tARMSDEALERs do
bx, by = building.buildingtoworld(value,5,5)
ARMSDEALER=value
ARMSDEALERindex=index
if index<sl then
buildingcmd.buildingbuy(ARMSDEALER,player)
end
--mm.cprint(index)
end


IP属地:山东1楼2023-01-15 14:18回复
    以购买枪店为例,sl如果赋值为2,就代表购买两个。sl赋值为8,就代表买8个。前提是地图里有那么多。位置是随机的。如果想选择近的,就需要增加一个测量距离的功能。用枪店的bx,by坐标和安全屋的坐标进行比较,求出最短的距离。舍弃距离远的坐标。


    IP属地:山东2楼2023-01-15 14:23
    回复
      tARMSDEALERs = findBusinessesInRadius("ARMSDEALER",soldierstart_x, soldierstart_y,999999999)
      local ARMSDEALER=nil
      local sl=1
      local ARMSDEALERindex=nil
      local dist=999999999
      for index, value in tARMSDEALERs do
      bx, by = building.buildingtoworld(value,5,5)
      ARMSDEALER=value
      ARMSDEALERindex=index
      if 19<index and index<sl+20 then
      buildingcmd.buildingbuy(ARMSDEALER,player)
      end
      --mm.cprint(index)
      end
      tRESTAURANTs = findBusinessesInRadius("RESTAURANT",soldierstart_x, soldierstart_y,999999999)
      local RESTAURANT=nil
      local sl=1
      local RESTAURANTindex=nil
      local dist=999999999
      for index, value in tRESTAURANTs do
      bx, by = building.buildingtoworld(value,5,5)
      RESTAURANT=value
      RESTAURANTindex=index
      if 16<index and index<sl+17 then
      buildingcmd.buildingbuy(RESTAURANT,player)
      end
      --mm.cprint(index)
      end
      tResidentials = findBusinessesInRadius("RESIDENTIAL",soldierstart_x, soldierstart_y,999999999)
      local residential=nil
      local residentialindex=nil
      local sl=2
      for index,value in tResidentials do
      bx, by = building.buildingtoworld(value,5,5)
      residential=value
      residentialindex=index
      --mm.cprint(index)
      if 5<index and index<sl+6 then
      buildingcmd.buildingbuy(residential,player)
      start_x, start_y = building.buildingtoworld(residential,5,5)
      soldier={}
      for i=0,3 do
      soldier[i] = world.activatecharacter("HENCHMAN")
      family.addsoldier(player, soldier[i])
      charactercmd.setposition(soldier[i], start_x, start_y)
      charactercmd.fortify(player, soldier[i], residential)
      end
      end
      end


      IP属地:山东3楼2023-01-15 18:02
      回复
        关于购买指定位置的建筑物,我发现,每一类的每一个建筑物都有一个序号,也就是index
        这个序号的编写方法似乎是从正北到正南排序的。
        只要给出需要的建筑物的序号范围,即可购买到指定范围内的建筑物。
        比如19<index and index<sl+20
        这个范围就是20到19+sl
        如果sl=1
        那么就买的是20号建筑物


        IP属地:山东4楼2023-01-15 18:06
        回复