SphereCommunity
Loop on tags. - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Loop on tags. (/Thread-Loop-on-tags)



Loop on tags. - rastrero - 01-22-2016 03:57 PM

Hi
Need to know something


Imagine i got all this tags

tag.enemy.player1=<player_Uid>
tag.enemy.player2=<player_Uid>
tag.enemy.player3=<player_Uid>
tag.enemy.player4=<player_Uid>
tag.enemy.player5=<player_Uid>
tag.any=1
tag.asdas=1


Now I want to do a loop among enemy group tag.
How do I this?


RE: Loop on tags. - darksun84 - 01-22-2016 07:24 PM

I don't understand, you can loop through similar tags by using this
PHP Code:
for 1 5
  
// Print in server console the Uid of the player at tag.enemy.player1/2/34/5 
 
 
serv.log <tag.enemy.player<dlocal._for>>  
endfor 
But i think it's better you use the ATTACKER functions
http://wiki.sphere.torfo.org/index.php/ATTACKER


RE: Loop on tags. - rastrero - 01-23-2016 01:42 AM

Ok, I knew that way but its not the way im looking for.

Anyway thx.


RE: Loop on tags. - darksun84 - 01-23-2016 02:59 AM

What you mean then ?


RE: Loop on tags. - rastrero - 01-23-2016 04:46 AM

Im doing my own "guild system"

I need to safe the members list, enemy, friends, allys, etc etc.
so I want to safe them on tags but Im not sure how to do it.

It this way better?
Tag0.exampleMembers= <Uid> <uid> <uid> <uid>



OR its better at the other way?

ok, Im going to use lists better.
Ty all anyway.


RE: Loop on tags. - karma - 01-23-2016 06:11 AM

If you access frequently to these values you can consider using MySQL.
The way you are suggesting (but using commas as separators instead of blank spaces) may be better than having an high number of tags, if you have a reasonable limit of chars/enemies etc so that in any case the tag won't be too long.

You can use these functions (the code can be improved, it is old and i don't use it now, i think it works though):
Code:
[FUNCTION array_get] //item, source (0 based)
IF (<ISEMPTY <ARGV[<EVAL <ARGN1>+1>]>>)
    RETURN ""
ENDIF
RETURN <ARGV[<EVAL <ARGN1>+1>]>

[FUNCTION array_count]
RETURN <ARGV>

[FUNCTION array_add] //array, item to add
IF (<ARGV>==1)
    RETURN <Streat <ARGV[0]>>
ENDIF
RETURN <ARGS>

[FUNCTION array_remove] //item,array, 0 based
LOCAL.AR=<STREAT <ARGS>>
FOR (<Array_Count <LOCAL.AR>>)
    IF (<LOCAL._FOR>!=<EVAL <ARGV[0]>+1>)
        IF !(<ISEMPTY <VAR.ARRAY>>) //note that I use vars because locals are never empty
            VAR.ARRAY=<VAR.ARRAY>,<Array_Get <EVAL <LOCAL._FOR>-1>,<LOCAL.AR>>
        ELSE
            VAR.ARRAY=<Array_Get <EVAL <LOCAL._FOR>-1>, <LOCAL.AR>>
        ENDIF
    ENDIF
ENDFOR
IF (<ISEMPTY <VAR.ARRAY>>)
    VAR.ARRAY
    RETURN
ENDIF
LOCAL.ARRAY=<VAR.ARRAY>
VAR.ARRAY
RETURN <LOCAL.ARRAY>

[FUNCTION array_update] //item, new val, array
LOCAL.AR=<STREAT <STREAT <ARGS>>>
FOR (<Array_Count <LOCAL.AR>>)
    IF (<LOCAL._FOR>!=<EVAL <ARGV[0]>+1>)
        IF !(<ISEMPTY <LOCAL.ARRAY>>)
            LOCAL.ARRAY=<LOCAL.ARRAY>,<Array_Get <EVAL <LOCAL._FOR>+-1>,<LOCAL.AR>>
        ELSE
            LOCAL.ARRAY=<Array_Get <EVAL <LOCAL._FOR>+-1>, <LOCAL.AR>>
        ENDIF
    ELSE
        IF !(<ISEMPTY <LOCAL.ARRAY>>)
            LOCAL.ARRAY=<LOCAL.ARRAY>,<ARGV[1]>
        ELSE
            LOCAL.ARRAY=<ARGV[1]>
        ENDIF
    ENDIF
    IF (<LOCAL._FOR>>1000)
        RETURN 1
    ENDIF
ENDFOR
LOCAL.ARRAY=<LOCAL.ARRAY>
LOCAL.ARRAY
RETURN <LOCAL.ARRAY>

Anyways, take in mind that guildstones and townstones already have properties to store these values: http://wiki.sphere.torfo.org/index.php/Special_Items#Guild.2FTown_Members
Also, check the current code in the "stones" folder, most of the stuff regarding guild/townstones is scripted.


RE: Loop on tags. - Sirocco - 02-08-2016 06:04 PM

make it self with sources

Code:
[FUNCTION f_arraysort]
if !strlen(<args>)
    local.count = "0"
    return 0
endif
if <eval((<args> / 1000) * 1000)> > 0
    local.count = "<eval(<args>)>"
elseif <eval((<args> / 100) * 100)> > 0
    local.count = "0<eval(<args>)>"
elseif <eval(<args> / 10)> > 0
    local.count = "00<eval(<args>)>"
elseif <eval(<args> / 10)> == 0
    local.count = "000<eval(<args>)>"
endif
return 1


fortags member_*
    local.num = 0<local.num> + 1
    plocal.char= <local._var_value>
    call f_arraysort <plocal.char.tag.char_questnumber>
    ptag.charexp<local.count>_<plocal.char.uid> = <plocal.char.uid>
endfor

local.place = <eval <tag.char_count> + 1>
forptags charexp*
    local.place = <local.place> - 1
    plocal.char= <local._var_value>
    tag.temp_<eval(<local.place>)> = <plocal.char.uid>
endfor

fortags temp_*
//
endfor