Furby
Current occupation: News poster
- Reaction score
- 144
The Rune System
by FURBY
version 1.01a
by FURBY
version 1.01a
Preface: Many friends was asking me if I can make something like this. So I decided to make system for this.
What does this do: This system allows creators of maps to simple add runes to regions choosed by creator also set a lot of stuffs around.
Features:
- You are able to change time in which are runes spawned at first time
- You are able to change time in which are runes respawned after each pick
- You are able to change if is rune placed randomly or exactly in center of region
- You are able to add new or remove existing runes and regions in which are runes spawned
Requires: Jass NewGen Pack
Changelog:
version 1.00
- First release
- Fixed code
- Scope instead of library
- Private Init instead of public Init
- Added nulling of timer in Init
Copy the trigger called TRS from the attached map or create a trigger named TRS, convert it to custom text, and replace everything inside it with the code below. Then you can addm remove or edit values in Editable Zone in trigger you created.
System code:
JASS:
//==============================================================================
//==============================================================================
//
// TRS - THE RUNES SYSTEM BY FURBY - v1.01a
//
// MORE INFO ON THE THEHELPER.NET AND CLANMAPZ.COM
//
// thanks to Romek and Artificial for helping
//
//==============================================================================
//==============================================================================
scope TheRuneSystem initializer Init
globals
private integer array TheRuneType
private rect array TheRuneRect
private real array TheRuneRespawn
private boolean array TheRuneRandomPlace
private item array TheRunes
private timer array TheRuneTimer
private boolean TheRuneDebugMode = false
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// EDITABLE ZONE - EDITABLE ZONE - EDITABLE ZONE - EDITABLE ZONE
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//How many types of runes system allowing
private constant integer CountTheRuneTypes = 4
//How many regions for runes system allowing
private constant integer CountTheRuneRects = 3
//How long time from start of the map runes will spawn
private constant real FirstSpawnTime = 30.
endglobals
private function SetGlobalArray takes nothing returns nothing
local integer i
//Rawcodes of the runes
//Be sure if you changed count of rune types in globals, variable: CountTheRuneTypes - base 4
set TheRuneType[1] = 039;rhe3039;
set TheRuneType[2] = 039;rma2039;
set TheRuneType[3] = 039;rspd039;
set TheRuneType[4] = 039;rspl039;
//set TheRuneType[5] = ...
//Regions where are runes spawned
//Be sure if you changed count of rune regions in globals, variable: CountTheRuneRects - base 3
set TheRuneRect[1] = gg_rct_TheRuneOne
set TheRuneRect[2] = gg_rct_TheRuneTwo
set TheRuneRect[3] = gg_rct_TheRuneThree
//set TheRuneRect[5] = ...
//If item should spawn at random place in region
//Be sure if you changed count of rune regions in globals, variable: CountTheRuneRects - base 3
set TheRuneRandomPlace[1] = false
set TheRuneRandomPlace[2] = false
set TheRuneRandomPlace[3] = true
//set TheRuneRandomPlace[4] = ...
set i = 1
loop
exitwhen(i>CountTheRuneTypes)
set TheRuneRespawn<i> = 15.
set i = i + 1
endloop
endfunction
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// END OF EDITABLE ZONE - END OF EDITABLE ZONE - END OF EDITABLE ZONE
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
private function TheRuneDebug takes string s returns nothing
if TheRuneDebugMode==true then
debug call BJDebugMsg(s)
endif
endfunction
private function TheRuneDebugChange takes nothing returns nothing
if GetEventPlayerChatString()=="-TRS debug on" then
set TheRuneDebugMode=true
elseif GetEventPlayerChatString()=="-TRS debug off" then
set TheRuneDebugMode=false
endif
endfunction
private function GetRuneSpawnX takes integer Id returns real
if TheRuneRandomPlace[Id]==true then
return GetRandomReal(GetRectMinX(TheRuneRect[Id]), GetRectMaxX(TheRuneRect[Id]))
else
return GetRectCenterX(TheRuneRect[Id])
endif
endfunction
private function GetRuneSpawnY takes integer Id returns real
if TheRuneRandomPlace[Id]==true then
return GetRandomReal(GetRectMinY(TheRuneRect[Id]), GetRectMaxY(TheRuneRect[Id]))
else
return GetRectCenterY(TheRuneRect[Id])
endif
endfunction
private function GetItemId takes item TheItem returns integer
local integer i = 1
loop
exitwhen(i>CountTheRuneRects)
if TheItem == TheRunes<i> then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function RespawnItem takes nothing returns nothing
local integer i = 1
call TheRuneDebug("Respawn timer expired")
loop
exitwhen(i>CountTheRuneRects)
if GetExpiredTimer()==TheRuneTimer<i> then
call TheRuneDebug("Creating item with id 039;" + I2S(i) + "039;")
set TheRunes<i> = CreateItem(TheRuneType[GetRandomInt(1,CountTheRuneTypes)],GetRuneSpawnX(i),GetRuneSpawnY(i))
endif
set i = i + 1
endloop
call DestroyTimer(GetExpiredTimer())
endfunction
private function Act takes nothing returns nothing
local item TheItem = GetManipulatedItem()
set TheRuneTimer[GetItemId(TheItem)] = CreateTimer()
call TimerStart(TheRuneTimer[GetItemId(TheItem)], TheRuneRespawn[GetItemId(TheItem)], false, function RespawnItem)
call TheRuneDebug("Respawn timer of rune started with 039;" + R2S(TheRuneRespawn[GetItemId(TheItem)]) + "039; seconds")
set TheItem = null
endfunction
private function Cond takes nothing returns boolean
local item TheItem = GetManipulatedItem()
call TheRuneDebug("Picking of item detected")
if GetItemId(TheItem)!=0 then
call TheRuneDebug("Detected item is rune with id 039;" + I2S(GetItemId(TheItem)) + "039;")
return true
endif
call TheRuneDebug("Detected item is not rune")
return false
endfunction
private function FirstSpawn takes nothing returns nothing
local integer i = 1
call TheRuneDebug("First spawn timer expired")
call DestroyTimer(GetExpiredTimer())
loop
exitwhen(i>CountTheRuneRects)
call TheRuneDebug("Creating rune with id 039;" + I2S(i) + "039;")
set TheRunes<i> = CreateItem(TheRuneType[GetRandomInt(1,CountTheRuneTypes)],GetRuneSpawnX(i),GetRuneSpawnY(i))
set i = i + 1
endloop
endfunction
private function True takes nothing returns boolean
return true
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i
local timer tim = CreateTimer()
call SetGlobalArray()
set i = 1
call TheRuneDebug("Starting first spawn timer with 039;" + R2S(FirstSpawnTime) + "039; seconds")
call TimerStart(tim, FirstSpawnTime, false, function FirstSpawn)
set i = 0
loop
exitwhen(i>11)
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, Filter(function True))
set i = i + 1
endloop
call TriggerAddCondition(t, Filter(function Cond))
call TriggerAddAction(t, function Act)
// Debug set
set i = 0
loop
exitwhen(i>11)
call TriggerRegisterPlayerChatEvent( t, Player(i), "-TRS debug ", false )
set i = i + 1
endloop
call TriggerAddAction(t, function TheRuneDebugChange)
set tim = null
endfunction
endscope
//==============================================================================
// END OF TRS - THE RUNES SYSTEM
//==============================================================================</i></i></i></i></i>
Demo Map: