SphereCommunity
Patrol script with lists, suggestion & improvements - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: Patrol script with lists, suggestion & improvements (/Thread-Patrol-script-with-lists-suggestion-improvements)



Patrol script with lists, suggestion & improvements - Crusader - 01-12-2014 12:06 PM

This is just an embrional script, but i would like ideas for improvement and make it work better (if possible)

Code:
[FUNCTION f_assegna_patrol]
//serv.log <args> <- i tried to check if there aren't arguments..but doesn't work like this... help?
//IF !(<args>)
//src.Sysmessage You need 6 arguments: Continent (ex Sigil), Region (ex Lumen), Type (ex Guard), Route (ex 1), How Many chars(ex 4), Radius(4)
//ELSE
TARGETF f_patrol <argv[0]>,<argv[1]>,<argv[2]>,<argv[3]>,<argv[4]>,<argv[5]>
src.sysmessage On whom u wanna put a patrol script?
//ENDIF
RETURN 1

[FUNCTION f_patrol]
local.npchome=<serv.list.Patrol_<argv[0]>_<argv[1]>_<argv[2]>_<argv[3]>.0>
FORCHARS <eval <argv[5]>> // //note: actually the forchars starts from the player not from the targetted npc... meh =/
IF ((<ISCHAR>) && (<brain>))
    events +e_patrol
    tag.status = 2
    tag.patrol_routenum=<argv[3]>
    home = <local.npchome>
    homedist = 3
    goto <home>
    LOCAL.FIND_PATROLCHAR=1
ENDIF
ENDFOR
IF (<LOCAL.FIND_PATROLCHAR>)
    serv.newitem i_patrol_controller
    new.tag.infolist=<argv[0]>,<argv[1]>,<argv[2]>,<argv[3]>,<argv[4]>
    new.tag.patrol_now=0
    new.p = <local.npchome>
    new.more1=0
    new.timer=5
ENDIF

[ITEMDEF i_patrol_controller]
ID=I_CRYSTAL_RED
Name=Patrolling Controller [DO NOT REMOVE!]
TYPE=t_eq_script

ON=@CREATE
ATTR=ATTR_Invis|attr_move_never

ON=@TIMER
REF1=<uid>
IF <MORE1>=0
    LOCAL.TIMERVAR=0
    LOCAL.LIGHTGREEN=0
    LOCAL.PATROL_COUNT=0
    FORCHARS 3
    IF (<tag0.status> == 2)
        LOCAL.PATROL_MAXCHARCOUNT=<ritorna 5,<ref1.tag.infolist>> //n of npc patrolling together
        IF <eval <TAG.PATROL_ROUTENUM>> == <ritorna 4,<ref1.tag.infolist>> //which route
            LOCAL.PATROL_COUNT += 1
            IF <dLOCAL.PATROL_COUNT> == <dLOCAL.PATROL_MAXCHARCOUNT>
                REF1.MORE1=1
                LOCAL.TIMERVAR=-12
            ENDIF
        ENDIF
    ENDIF
    ENDFOR
ELSE
    tag.homecoord=<serv.list.Patrol_<ritorna 1,<tag.infolist>>_<ritorna 2,<tag.infolist>>_<ritorna 3,<tag.infolist>>_<ritorna 4,<tag.infolist>>.<tag.patrol_now>>
    FORCHARS 3
        IF (<tag0.status> == 2) && (<eval <TAG.PATROL_ROUTENUM>> == <ritorna 4,<ref1.tag.infolist>>)
            home = <ref1.tag.homecoord>
            goto <home>
        ENDIF
    ENDFOR
    IF (<tag.patrol_now> == <eval <serv.list.Patrol_<ritorna 1,<tag.infolist>>_<ritorna 2,<tag.infolist>>_<ritorna 3,<tag.infolist>>_<ritorna 4,<tag.infolist>>.COUNT>-1>)
        tag.patrol_now=0
    ELSE
        tag.patrol_now += 1
    ENDIF
    REF1.P = <tag.homecoord>
    LOCAL.TIMERVAR=0
    MORE1=0
ENDIF
TIMER=<eval <LOCAL.TIMERVAR>+15>
RETURN 1

[EVENTS e_patrol]

[function patrol_list]
//serv.list.Patrol_Continent_Region_Type_0.ADD 4511,1439,0        // example

serv.list.Patrol_Trammel_Britain_Guard_0.ADD 1110,1222,0    
serv.list.Patrol_Trammel_Britain_Guard_0.ADD 1130,1222,0
sserv.list.Patrol_Trammel_Britain_Guard_0.ADD 1150,1222,0
serv.list.Patrol_Trammel_Britain_Guard_0.ADD 1170,1222,0
serv.list.Patrol_Trammel_Britain_Guard_0.ADD 1190,1222,0    

serv.list.Patrol_LostLands_Papua_Citizen_0.ADD 4110,1222,0    
serv.list.Patrol_LostLands_Papua_Citizen_0.ADD 4210,1322,0

serv.list.Patrol_LostLands_Papua_Citizen_1.ADD 4510,1222,0    
serv.list.Patrol_LostLands_Papua_Citizen_1.ADD 4610,1322,0

[FUNCTION ritorna]  // returns a tag array cell value
return <argv[<argn1>]>



RE: Patrol script with lists, suggestion & improvements - XuN - 01-12-2014 04:42 PM

To make the FORCHARS work from the target instead from yourself you must use a function to call it externally or just check for the distance difference

Code:
ref1=<argo>
FORCHARS <eval <argv[5]>+<ref1.distance>>
IF ((<ISCHAR>) && (<brain>) && (<distance <ref1>><=<argv[5]>))
And for the Patrol Controler: I guess in the Timer you are checking for the other members of the patrol, forchars 3 seems excesive small IMO as so much things can happen like combats, movement blocks, etc... I think you'll better do a forchars 20 or something like or better store the patrol members in the item and execute directly all your code on them, this way you can send all to attack if one is attacked and this kind of nice stuff.


RE: Patrol script with lists, suggestion & improvements - Crusader - 01-12-2014 11:20 PM

Code:
ref1=<argo>
FORCHARS <eval <argv[5]>+<ref1.distance>>
IF ((<ISCHAR>) && (<brain>) && (<distance <ref1>><=<argv[5]>))

doesn't work =/

the patrol controller works fine like that...the only problem is that sometimes npcs get stuck in a corner or such...so i need to find a way to force (teleport?) them near the controller.


RE: Patrol script with lists, suggestion & improvements - XuN - 01-12-2014 11:40 PM

argo.another_function <eval <argv[5]>+<ref1.distance>>


[function another_function]
forchars <dargn>
blabla code
endfor