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
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 )
you specify the 2 rects that will be used for entering and the rest is taken care of.
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
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,"")
call EnterRect.create(end,start,0,"")
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 )
you specify the 2 rects that will be used for entering and the rest is taken care of.
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
Only 1 trigger for all events
Discovered the awesomeness of rectwraps
UPDATE 2
Added custom message
Added unit filter
Credits to Renedaru aswell
UPDATE 3
Struct syntax
code looks nicer
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
Removed ABC for rectwraps
Credits to Azlier + Jesus4Lyf
It wont crap up on patch 1.24 which is good
Only 1 trigger for all events
Discovered the awesomeness of rectwraps
UPDATE 2
Added custom message
Added unit filter
Credits to Renedaru aswell
UPDATE 3
Struct syntax
code looks nicer
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