• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Need EXPERT help for creep revival system

Status
Not open for further replies.
Level 9
Joined
Oct 15, 2006
Messages
339
***PLEASE MOVE THIS TO REQUESTS SECTION***
Thanks


Hello. I need a revival system for Neutral units that's a bit more complex than any revival system out there..

***At the beginning of the map i need to place 48 random Neutral units in random spots within a rect.
There can be no more than 48 Neutral units on the map at a time.
Every 20 seconds, how ever many Neutral units are missing from the 48, a random number of random creeps is generated and placed randomly within the rect to eqal 48 creeps.

Not only that.. haha.. but every 40 seconds a random number between 5 and 20 of a random selection of the Neutral units needs to be "displaced" - by removing them from the rect/game, and allow the 20-second revival timer to replenish the map.


This may be a crucial factor so i am adding it.. Acturally, i know it is a crucial factor..

The neutral units will all be using the same name, and will look the same, but they serve as ability gains. If a user character comes within a very short range of these nuetral units, they gain modifications (spped, turn-rate, etc) or abilities. Once they come within the range of the neutral unit, the neutral unit will be "collected" - by removing the unit and then adding a mod/ability.

*** The units may not have to be different if the following is doable.

So i guess the only real way to do this is by having a bunch of Action triggers for the mods/abilities. Then if a player-character comes within range, remove neutral unit from game and somehow apply/"run" random trigger from 'trigger-group?' (using variables) for triggering unit?


I could not finish my map without this. So, please, dedicated scripters!

EDIT: Yar, no experts here, me matey!?!

(PLEASSSSSSEE!)
 
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
I have a script for you. If it looks complicated, that's cuz it is. The problem is that blizz made the "TriggerRegisterUnitInRange" ("Unit comes Within Range of Unit" in GUI) only able to take single units, and the parameter only accepts either pre-existing units on the map (gg_unit_...) or units returned by functions. So basically for every creep unit you add to your map you have to add another trigger SPECIFICALLY for that creep. (Can't just add events to one trigger, mainly because there's no way to remove/destroy events and after too many events get added the game lags.)

The following script makes several assumptions:

1. You only have ONE type of creep unit
2. Creeps all belong to ONE player
3. Bonuses are in the forms of abilities
4. Creeps respawn in one continuous rectangular area (otherwise known as a rect)

If any of these assumptions are wrong, make a reply and I'll do my best to fix the script.

IMPORTANT: The script requires you to have the vJass preprocessor to compile it. If you don't have vJass when you save your map it will give you a bunch of syntax errors and it might crash WE. If you don't have vJass, get it by dling the Jass NewGen pack by Vexorian from wc3campaigns.net. If you don't want to use vJass, reply and I'll make the script old-fashioned WE-friendly.

JASS:
library CreepSystem

struct creepsystemdata
    unit creep
    triggeraction action
endstruct

globals
    creepsystemdata creepdata = 0
    rect respawnrect = null
    timer creeptimer = CreateTimer()
    player creepplayer = Player(16) //Change this player to the player you want controlling the creeps
    integer creepcount = 0
    integer creepid = 0 //Change this to the custom data code of your creep unit
    real creeprange = 0 //Change this to the range at which you want the Addbonus trigger to fire
                        //(the range the player-controlled chars need to be within a creep unit for the creep to be removed and the chars given the bonuses)
    integer array creepbonusid = 0
    integer creepbonustotal = 0
    integer array playerunitid = 0
    integer playerunittotal = 0
endglobals

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

function CreepSystem_Create takes player p, integer id, real x, real y returns unit
    set bj_lastCreatedUnit = CreateUnit( p, id, x, y, GetRandomReal( 1, 360 ) )
    return bj_lastCreatedUnit
endfunction

function CreepSystem_CheckPlayerId takes integer id returns boolean
    local integer counter = 0
    loop
        exitwhen ( counter > playerunittotal )
        if ( id == playerunitid[counter] ) then
            return true
        endif
        set counter = counter + 1
    endloop
    return false
endfunction

function CreepSystem_AddBonus takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local unit u = GetTriggerUnit()
    local integer id = GetUnitTypeId( u )
    local creepsystemdata temp = GetStoredInteger( udg_CreepVars, I2S(H2I(t)), "temp" )
    if ( CreepSystem_CheckPlayerId( id ) ) then
        call RemoveUnit( temp.creep )
        call UnitAddAbility( u, creepbonusid[ GetRandomInt( 0, creepbonustotal - 1 ) ] )
        call TriggerRemoveAction( t, temp.action )
        call temp.destroy()
        call DestroyTrigger( t )
    endif
    set t = null
endfunction

function CreepSystem_Respawn takes nothing returns nothing
    local trigger t
    local real x = GetRandomReal( GetRectMinX( respawnrect ), GetRectMaxX( respawnrect ) )
    local real y = GetRandomReal( GetRectMinY( respawnrect ), GetRectMaxY( respawnrect ) )
    if ( creepcount < 48 ) then
        set t = CreateTrigger()
        call TriggerRegisterUnitInRange( t, CreepSystem_Create( creepplayer, creepid, x, y ), creeprange, null )
        set temp.action = TriggerAddAction( t, function CreepSystem_AddBonus )
        set temp.creep = bj_lastCreatedUnit
        call StoreInteger( udg_CreepVars, I2S(H2I(t)), "temp", temp )
        set creepcount = creepcount + 1
        set t = null
    endif
endfunction

function CreepSystem_BonusInit takes nothing returns nothing
    set creepbonusid[0] = 'A000' //Change these to the custom data codes that match the bonus abils in your map
    set creepbonusid[1] - 'A001'
    set creepbonusid[2] = 'A002'
    //Add more abilities if you wish
    set creepbonustotal = 3 //Set this to the total number of abilities defined above
endfunction

function CreepSystem_PlayerInit takes nothing returns nothing
    set playerunitid[0] = 'H000' //Change these to the custom data codes that match the player-controlled units that you want to be able to get bonuses
    set playerunitid[1] = 'H001'
    set playerunitid[2] = 'H002'
    set playerunittotal = 3 //Set this to the total number of units defined above
endfunction

function CreepSystem_Init takes nothing returns nothing
    local trigger t
    local real x = GetRandomReal( GetRectMinX( respawnrect ), GetRectMaxX( respawnrect ) )
    local real y = GetRandomReal( GetRectMinY( respawnrect ), GetRectMaxY( respawnrect ) )
    local creepsystemdata temp = creepsystemdata.create()
    call SetRect( respawnrect, 0, 0, 0, 0 ) //Change the values here to match the region in which you want your creeps to respawn 
    call CreepSystem_BonusInit()
    call CreepSystem_PlayerInit()
    loop
        exitwhen ( creepcount > 47 )
        set t = CreateTrigger()
        call TriggerRegisterUnitInRange( t, CreepSystem_Create( creepplayer, creepid, x, y ), creeprange, null )
        set temp.action = TriggerAddAction( t, function CreepSystem_AddBonus )
        set temp.creep = bj_lastCreatedUnit
        call StoreInteger( udg_CreepVars, I2S(H2I(t)), "temp", temp )
        set creepcount = creepcount + 1
        set t = null
    endloop
    call TimerStart( creeptimer, 20, true, function CreepSystem_Respawn )
endfunction

endlibrary

either copy/paste this into your custom script section or copy/paste into a trigger, doesn't matter.

You will need to call the CreepSystem_Init function at Map Initialization. Just make a trigger with event: Map Initialization, change to Custom Script, and type in "call CreepSystem_Init()" in the Trigger Actions function.
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Nice job! +rep

With vJass he doesn't even have to create a map initialization trigger, he doesn't have to call CreepSystem_Init, because of one library feature you forgot about: initializers.

Just change that top line into:

library CreepSystem initializer CreepSystem_Init
 
Status
Not open for further replies.
Top