SphereCommunity
Looping trough all region - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Looping trough all region (/Thread-Looping-trough-all-region)

Pages: 1 2


Looping trough all region - admin phoenix - 03-14-2013 07:43 PM

is there a chance to loop trough all region you have in your map script
like

for x 0 <eval <serv.map.region>-1>
your function
endfor

or is there another way like storing the region defname in a sql database and check it via a sql function

I am at work so I can´t test my example Smile

gr

phoenix


RE: Looping trough all region - Skul - 03-15-2013 09:20 PM

So you want to apply 'your function' to every region on a map. To what I can think of there is no 'easy' way of doing this, although you could always use an item/character to move around through some while loops, example:
Code:
local.p=<p>
for x 1 <eval <strarg <serv.map(1,1,<argn1>).region.p>> /32>
  for y 1 <eval <streat <strarg <serv.map(1,1,<argn1>).region.p>> /32>
    p=<eval <local.x> *32>,<eval <local.y> *32>,0,<argn1> //change your <p>
    region.'your function'
  endfor
endfor
p=<local.p>



RE: Looping trough all region - admin phoenix - 03-17-2013 06:25 AM

I made it so but it doesn´t work rightfull.

Code:
serv.newitem=i_gold
    local.y=1
    local.num=1
    FOR x 1 6173
     IF (<dlocal.y> < 65)
        new.p=<eval <local.num>*64>,<eval <local.y>*64>
         IF (STRMATCH(<new.region.defname>,a_athoria))
                 SERV.MAP.0.SECTOR.<dlocal.x> rain
                 serv.log Got it!!!
         ENDIF
        serv.log Region: <new.region.defname> Sector: <dlocal.x> P: <new.p>
      ELSE
          local.y=0
          local.num +=1
     ENDIF
    local.y +=1
    ENDFOR
        
        new.remove
I Loop through all sectors (I think so) and when I jump to the coordinates where I got the serv.log message "Got it" it doesn´t rain.
I think it´s not the right sector I got with local.x.
At first I loop downstairs (y coordinates) then jump I sector right.
I don´t know how the sectors are counted in which Position like
1,2,3,4 .....6144
65, 66,67.....4096


or
1, 65
2, 66
3, 67
4, 68
5, 69
.
.
.
4096,6144


I think it will be nice if we can read the sector number via
serv.map.(0).sector.number
so you can go ingame and type
.Show sector.number


RE: Looping trough all region - Mordaunt - 03-17-2013 08:07 AM

You're overthinking it:

Code:
serv.map.<argn>.allsectors rain


Also you could loops through the sectors individually like this:
Code:
[function make_it_rain]
for 1 <serv.maplist.<argn>.sector.qty>
    serv.map.<argn>.sector.<local._for> rain
endfor
This will only work on a server build AFTER 20-02-2013 btw..
This is a feature I am taking personal credit for, not because I added it... but because I bugged the sh*t out of Ben to add it Big Grin

as for reading sectors, you can read the following:

Code:
MAPLIST.map_num.SECTOR.COLS     R     Returns the number of sector columns on a map.
MAPLIST.map_num.SECTOR.QTY     R     Returns the number of sectors on a map.
MAPLIST.map_num.SECTOR.ROWs     R     Returns the number of sector rows on a map.
MAPLIST.map_num.SECTOR.SIZE     R     Returns the size of the sectors on a map.

And with this information you can plot exactly where a sector is and should you wish affect entire rows/columns something I was working on prior to the hardcoded system being fixed


RE: Looping trough all region - admin phoenix - 03-17-2013 05:40 PM

mordaunt, you are my hero Smile
but this help isn´t documented in the revision text
Will give a try


RE: Looping trough all region - admin phoenix - 03-17-2013 08:50 PM

still got the Problem that it will rain in another sector and not the sector with the Region defname I declare

PHP Code:
[FUNCTION make_weather]
    
local.map=<dargv[0]> // map, 0
    
local.region_defname=<argv[1]> // your region name you wish that it rain
    
local.weather=<argv[2]> // weather like rain, snow or try
    
serv.newitem=i_gold
    
 
FOR <serv.maplist.<dlocal.map>.sector.qty//
  
IF (<dlocal.y_> == 64)
    new.
p=<eval 32+(64*<local.x_>)>,<eval 32+(64*<local.y_>)>
   IF (
STRMATCH("<local.region_defname>*","<new.region.defname>"))
       
SERV.MAP.<dlocal.map>.SECTOR.<dlocal._for> <local.weather>
   ENDIF
      
local.y_=0
      local
.x_ +=1
   
ELSE
    new.
p=<eval 32+(64*<local.x_>)>,<eval 32+(64*<local.y_>)>
   IF (
STRMATCH("<local.region_defname>*","<new.region.defname>"))
       
SERV.MAP.<dlocal.map>.SECTOR.<dlocal._for> <local.weather>
   ENDIF
    
local.y_ +=1    
  
ENDIF
  ENDFOR
     new.
remove 

it rain far away from my sector/Region I wish


RE: Looping trough all region - Ben - 03-17-2013 10:54 PM

This would probably work better

PHP Code:
[FUNCTION make_weather]
    
local.map=<dargv[0]> // map, 0
    
local.region_defname=<argv[1]> // your region name you wish that it rain
    
local.weather=<argv[2]> // weather like rain, snow or try
    
local.size=<serv.maplist.<dlocal.map>.sector.size>

    
FOR 
<serv.maplist.<dlocal.map>.sector.qty>
  
    
local.secx = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.rows>) * <local.size>)
    
local.secy = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.cols>) * <local.size>)
    
local.secregion = <SERV.MAP(<dlocal.secx>,<dlocal.secy>,<dlocal.map>).region.defname>

    IF (
STRMATCH("<local.region_defname>*","<local.secregion>"))
       
SERV.MAP.<dlocal.map>.SECTOR.<dlocal._for> <local.weather>
    ENDIF
ENDFOR 

It's not tested but should do the trick.


RE: Looping trough all region - admin phoenix - 03-18-2013 02:07 AM

Thanks Ben. I think it´s the right way but it doesn´t work rightfull.
I put two serv.logs inside the code. The first one Shows me th coordination. the second one should appears when the Region ist found. but nothing but an error.
PHP Code:
[FUNCTION make_weather]
    
local.map=<dargv[0]> // map, 0
    
local.region_defname=<argv[1]> // your region name you wish that it rain
    
local.weather=<argv[2]> // weather like rain, snow or try
    
local.size=<serv.maplist.<dlocal.map>.sector.size>
        
FOR 
<eval <serv.maplist.<dlocal.map>.sector.qty>-1//<-- fixed the last bug in my error code with <SERV.MAP(6176>
  
    
local.secx = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.rows>) * <local.size>)
    
local.secy = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.cols>) * <local.size>)
    
serv.log Loc: <dlocal.secx>,<dlocal.secy>
    
    
local.secregion = <SERV.MAP(<dlocal.secx>,<dlocal.secy>,<dlocal.map>).region.defname>

    IF (
STRMATCH("<local.region_defname>*","<local.secregion>"))
       
SERV.MAP.<dlocal.map>.SECTOR.<dlocal._for> <local.weather>
       
serv.log Find the Region.
    ENDIF
ENDFOR 
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 32,32
17:03:(sphere_gm_commands.scp,6872)Loc: 96,32
17:03:(sphere_gm_commands.scp,6872)Loc: 96,32
17:03:(sphere_gm_commands.scp,6872)Loc: 96,32
17:03:(sphere_gm_commands.scp,6872)Loc: 96,32
17:03:ERROR:(sphere_gm_commands.scp,6874)Can't resolve <SERV.MAP(6176>


RE: Looping trough all region - Mordaunt - 03-18-2013 03:45 AM

This works..
The locals were not being correctly defined before so it would never match.

Code:
[FUNCTION make_weather]
    local.map=<dargv[0]> // map, 0
    local.region_defname=<strarg <streat <args>>> // your region name you wish that it rain
    local.weather=<streat <streat <args>>> // weather like rain, snow or try
    local.size=<serv.maplist.<dlocal.map>.sector.size>
        
FOR 1 <eval <serv.maplist.<dlocal.map>.sector.qty>-1> //<-- fixed the last bug in my error code with <SERV.MAP(6176>
  
    local.secx = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.rows>) * <local.size>)
    local.secy = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.cols>) * <local.size>)
    serv.log Loc: <dlocal.secx>,<dlocal.secy>
    
    local.secregion = <SERV.MAP(<dlocal.secx>,<dlocal.secy>,<dlocal.map>).region.defname>

    IF (strmatch(*<local.region_defname>*,<local.secregion>))
       SERV.MAP.<dlocal.map>.SECTOR.<dlocal._for> <local.weather>
       serv.b Find the Region. <local.secregion>
    ENDIF
ENDFOR



RE: Looping trough all region - Ben - 03-18-2013 10:45 AM

Well, here is a working version (been tested)

PHP Code:
[FUNCTION make_weather]
    
local.map=<dargv[0]> // map, 0
    
local.region_defname=<argv[1]> // your region name you wish that it rain
    
local.weather=<argv[2]> // weather like rain, snow or try
    
local.size=<serv.maplist.<dlocal.map>.sector.size>

    
FOR 
<eval <serv.maplist.<dlocal.map>.sector.qty>-1>
  
    
local.secx = (<local.size>/2) + ((<local._for> % <serv.maplist.<dlocal.map>.sector.cols>) * <local.size>)
    
local.secy = (<local.size>/2) + ((<local._for> / <serv.maplist.<dlocal.map>.sector.cols>) * <local.size>)
    
local.secregion = <SERV.MAP(<dlocal.secx>,<dlocal.secy>,<dlocal.map>).region.defname>

    IF (
STRMATCH("<local.region_defname>*","<local.secregion>"))
        
SERV.MAP.<dlocal.map>.SECTOR.<eval <local._for>+1> <local.weather>
    ENDIF
ENDFOR 

The problem was the location was not calculated properly

Now I do see potential issues with this... if a region is very small, it could be skiped over since it's only testing every sector.size tiles (64 in this case)