System Enter Rect

DrEvil

FCRI Associate!
Reaction score
111
( I don't know whether someone has made this before , I looked but couldn't find anything... )

Requires : Rectwraps + NewGen
JASS:
library EnterRect requires rectwrap

struct EnterRect extends array
    private real tarX
    private real tarY
    // target coordinates
    private integer level
    // level requirement to go through
    private string msg
    // custom msg if they can't enter
    
    private static timer T = CreateTimer()
    private static trigger Trig = CreateTrigger()
    
    private static boolean SHOULD_PAN = true
    // wether user wants to pan after going through rect
    
    private static method UnitFilter takes unit u returns boolean
        return true
    endmethod
    
    private static method RestoreTrig takes nothing returns nothing
        call EnableTrigger(thistype.Trig)
    endmethod// enable the trigger after to avoid the trigger re-firing 
    
    private static method Enter takes nothing returns boolean
        local thistype d = thistype(GetTriggeringRectwrap())
        local unit u = GetTriggerUnit()
        // locals needed
        if thistype.UnitFilter(u) then
            if GetUnitLevel(u) >= d.level then
                
                call DisableTrigger(thistype.Trig)
                // disable it to stop the re-fiing bug               
                call SetUnitX(u,d.tarX)
                call SetUnitY(u,d.tarY)// send the unit to the specified rect
                
                if thistype.SHOULD_PAN and GetLocalPlayer() == GetOwningPlayer(u) then
                    call PanCameraToTimed(d.tarX,d.tarY,1)
                endif// pan the camera for player if user wants to
                
                call IssueImmediateOrder(u,"stop")
                //stop the unit
                call TimerStart(thistype.T,.0,false,function thistype.RestoreTrig)
                // start timer for enabling 
            else
            // the hero is not a high enough level..
                if d.msg == "" then
                    call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,10,"You need to be level "+I2S(d.level)+" in order to pass")
                else
                    call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,10,d.msg)
                endif
            endif
        endif
        
        set u = null
        //leaky unit
        return false
        // because it was a condition action <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
    endmethod
    
    static method create takes rectwrap start,rectwrap end,integer level,string msg returns thistype
        local thistype d = thistype(start)
        // never knew I could do this ^_^
        set d.tarX = end.cenX
        set d.tarY = end.cenY
        set d.level = level
        set d.msg = msg
        // set the struct variables
        
        call start.registerEnter(thistype.Trig)
        // register when the unit enters start ( and on the other call it would register end )
        return d
        // the .create require a return :S
    endmethod
    
    private static method onInit takes nothing returns nothing
        call TriggerAddCondition(thistype.Trig,Condition(function thistype.Enter))    
    endmethod// Add the condition once
endstruct

function RegisterRectEnterEx takes rect r1,rect r2,integer level,string msg returns nothing
    local rectwrap start = rectwrap.wrap(r1)
    local rectwrap end = rectwrap.wrap(r2)
    call EnterRect.create(start,end,level,msg)
    call EnterRect.create(end,start,level,msg)
endfunction// I would recommend this for dungeons requiring levels to enter

function RegisterRectEnter takes rect r1,rect r2 returns nothing
    local rectwrap start = rectwrap.wrap(r1)
    local rectwrap end = rectwrap.wrap(r2)
    call EnterRect.create(start,end,0,&quot;&quot;)
    call EnterRect.create(end,start,0,&quot;&quot;)
endfunction// Average entering rect usage e.g. house entering

endlibrary


Description :
This can be used in loap maps , or orpg's , somewhere where you have to 'enter rects' to get to other 'rects'.
Normally you would have like one or two triggers just for entering one building ( Talking to you GUI'ers ^_^ )
Well with this , you call one function with 2 rects (and a level req if necessary )

JASS:
function RegisterRectEnter takes rect r1,rect r2 returns nothing

you specify the 2 rects that will be used for entering and the rest is taken care of.
JASS:
function RegisterRectEnterEx takes rect r1,rect r2,integer level,string msg returns nothing

you specify the 2 rects ( above ) , a level requirement e.g. orpg dungeons which have a level requirement to enter and a custom message if the unit does not meet the level req.

Hmm.. I suppose that's all I can say ( tbh , I hate putting comments in XD , but if I didn't , I'd probably get moaned at ^_^ )

Is the True filter actually needed in events ? Because I heard they don't leak , so there's no need for it .. ?

Changelog
UPDATE 1
Removed ABC for rectwraps
Credits to Azlier + Jesus4Lyf :)
It wont crap up on patch 1.24 which is good :D
Only 1 trigger for all events
Discovered the awesomeness of rectwraps :D
UPDATE 2
Added custom message
Added unit filter
Credits to Renedaru aswell :)
UPDATE 3
Struct syntax
code looks nicer :p
Credits to kenny!
UPDATE 4
No need for two rectwraps in the struct now , just store the x/y
UPDATE 5
Removed un-needed variables
UPDATE 6
Changed code to more effective code :)
 

Attachments

  • EnterRect.w3x
    24.9 KB · Views: 215

Jesus4Lyf

Good Idea™
Reaction score
397
A much better tool than ABC for this: Rectwraps. (You can attach the data to the rect using this, put all the events on one trigger, and just load the data through GetTriggeringRectWrap.)

Reason is with patch 1.24 coming out, maps using ABC will break on patch. And this can be done with no H2I. :)

Just a thought, s'up to you. ^_^
 

DrEvil

FCRI Associate!
Reaction score
111
Updated to use rectwraps

It took me a while to figure out how to use rectwraps , but I figured the way ( or a way ^_^ )
And I think I will be using rectwraps more often now , they are quite hmm... Awesome ? :)
Plus it wont bugger my map after the 1.24 patch .

I must thank Jesus4Lyf + Azlier for making rectwraps and teaching me how to use them ( without them teaching me anything :p )

If I did use rectwraps wrongly , could you explain ?
Thanks

( btw , I don't use v.1.01 and stuff... so yeh... )
 

Jesus4Lyf

Good Idea™
Reaction score
397
Looks good to me. Feel free to PM Azlier to ask him to check it out. :thup:

But yeah, well done.

Only thing is you could use two "Data" instances... Both with just the target x/y to port the unit to, and no other members. Attach it to the rectwraps and register the trigger for them... Then you wouldn't need to check which rect and use get center. But it doesn't matter a lot, once again up to you. :)

Nice work so far. :thup:
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Following with your rect requiring level, why not add it requiring a boolean? Along with a customized message.
 

DrEvil

FCRI Associate!
Reaction score
111
Because
1. Units can't go behind level 0 ? ( Which is the default for my sys )
2. If the level req. was higher than 1 it would mean that there is a level req.
Hmm.. The customized message could be quite handy though.
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
I meant, only allow units to enter with a boolean set true for them. E.g. PUI_PROPERTY or AIDS structs for example.
 

Jesus4Lyf

Good Idea™
Reaction score
397
One more thing you could add is a filter function, in case mappers don't want neutral creeps and such to be able to get through. Just a simple...
JASS:
private function Filter takes unit u returns boolean
    return true
endfunction

And users could change true to GetOwningPlayer(u)!=Player(15) or something if they like. Just check it for triggering unit...

>I meant, only allow units to enter with a boolean set true for them. E.g. PUI_PROPERTY or AIDS structs for example.
That would require unit indexing and is probably outside the scope of this a bit...
 

DrEvil

FCRI Associate!
Reaction score
111
Added the unit filter ,
Added the custom msg ( if unit is not high enough level )

Thank you to both of you :)
 

Kenny

Back for now.
Reaction score
202
Looks good, I can see this being used in many ORPGs and stuff like that.

May I suggest changing the name of the struct though? Data is a very common word, maybe just make it EnterRect or something, seems more appropriate.

And wasn't it said somewhere that you should not have constant global handles? Not too sure if it applies to static constant struct members (referring to the timer and trigger), but if they are static I don't see much need for them to be constant anyway. But I may be wrong here.
 

DrEvil

FCRI Associate!
Reaction score
111
Changed it to a public struct ( does it really matter if it's public or private , if they want to change stuff they will change it inside that library ^_^ )

( Can I use thistype even though it's not in a module or whatever ? )

I actually created this for a friend's ORPG ^^ , then had the idea of submitting it for other people.. who need something like this.

I don't think static / constant have anything that means the same :p
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
public struct Data

Should be private?

And yeah, those handles probably shouldn't be labelled as constant, even if they are. I think it's because the optimizer is inclined to inline all constants, even handles, which means CreateTimer and CreateTrigger would appear where the variable should instead. We're all a bit unsure of this, but our practice right now is not to label handles as constant.

Only thing is you could use two "Data" instances... Both with just the target x/y to port the unit to, and no other members. Attach it to the rectwraps and register the trigger for them... Then you wouldn't need to check which rect and use get center.
Looking into that, at all? :p
 

Kenny

Back for now.
Reaction score
202
Changed it to a public struct ( does it really matter if it's public or private , if they want to change stuff they will change it inside that library ^_^ )

Well, I think it would matter if it was private. If I was to use this, I would probably go for the struct syntax the majority of the times. But then again, that's just me, and there is actually no need to use struct syntax, as this is a one liner. Just keep it private I guess, lol.

( Can I use thistype even though it's not in a module or whatever ? )

Yes.
 

DrEvil

FCRI Associate!
Reaction score
111
tbh , who is going to name a struct EnterRect_Data :p
And if people do want to mess up a system wouldn't they mess it up from the inside ? ( Like within that library )
 

Jesus4Lyf

Good Idea™
Reaction score
397
Oh righttt. Using the struct syntax. Yeah, I guess that's fine then. o.o

Actually, no they shouldn't be allowed to really. For this reason:
Only thing is you could use two "Data" instances... Both with just the target x/y to port the unit to, and no other members. Attach it to the rectwraps and register the trigger for them... Then you wouldn't need to check which rect and use get center.
You'd have to change the interface on them.
 

Kenny

Back for now.
Reaction score
202
tbh , who is going to name a struct EnterRect_Data

No one? :p Thats why I proposed you use EnterRect instead of Data, to make struct syntax nicer.

You should decide whether you want to allow struct syntax or not. If you want to allow it, you should go through your system and make everything you don't want touched, a private member/method.

And also, get rid of the constant keyword for the timer and trigger, and add thistype where Data is.
 

DrEvil

FCRI Associate!
Reaction score
111
Hmm they are all 'thistype' now , and made most members private...
Anything else ??:confused::confused:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top