• 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.

[JASS] Problem with Timers and Gamecaches

Status
Not open for further replies.
Ok because my problem is that hard I try to explain with picture

I want 2 make those 3 nether dragons fly to the target location and hit all enemy unit in that region.

Green = Netherdrake
Black = Flyight route
Darkred = Area Effect
Red = Target Location

dwod4.jpg


Can someone help me? I've done that and I am using JNGP!

JASS:
globals
gamecache udg_GameCache = null
endglobals

function T2I takes timer t returns integer
  return t
  return 0
endfunction
function I2T takes integer i returns timer
  return i
  return CreateTimer()
endfunction

function DW_Save takes unit u, real t_x, real t_y, integer m returns nothing
  call StoreUnit(udg_GameCache,"DW"+"m","u",u)
  call StoreReal(udg_GameCache,"DW"+"m","t_x",t_x)
  call StoreReal(udg_GameCache,"DW"+"m","t_y",t_y)
endfunction

function DW_Load takes integer i, returns unit u, real t_x, real t_y, integer m
set u = RestoreUnitLocFacingAngleBJ("DW"+I2S(i),"u",udg_GameCache,Player(14))
return i
return
return
return
endfunction

function DW_M_Action takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer i = T2I(t)
local unit u
local integer m
local real t_x
local real t_y
call DW_Load
endfunction

function DW_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer i = GetUnitAbilityLevel(u,'A00Y')
local location l = GetSpellTargetLoc()
local real t_x = GetLocationX(l)
local real t_y = GetLocationY(l)
local timer t = CreateTimer()
local integer m
set m = T2I(t)
call TimerStart(t,0.01,false, function DW_M_Action)
call DW_Save(u,t_x,t_y,m)
endfunction

function DW_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00Y' 
endfunction

//===========================================================================
function InitTrig_DW takes nothing returns nothing
    local trigger gg_trg_DW = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DW, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_DW, Condition( function DW_Conditions ) )
    call TriggerAddAction( gg_trg_DW, function DW_Actions )
endfunction
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Uh, please don't use multiple Store functions when you're using JNGP, vJass is here to make things easier.

First of all, I don't understand exactly what you want, my theory is that you want to make those 3 nether dragons fly following that black flight path, but they should damage enemy units they encounter and when they reach that red area, they explode? If that's right, what's that darkened area around those nether dragons (green dots)?

Something is seriously wrong with your code. First, that I2T thing, what the hell is that? Second, that DW_Load call has a syntax error, not to mention the location leak...... I don't want to go deep in it.

Lets set up the code first (so we can easily modify it later), this is how you're going to start. First, make a trigger, put the map initialization event and convert it to JASS. Find the function that has the prefix Trig_ and the suffix _Actions, remove put this between the function and the endfunction line:

JASS:
call FlushGameCache(InitGameCache("jasslocalvars.w3v"))
set udg_HandleCache = InitGameCache("jasslocalvars.w3v")

so your function looks something like this:

JASS:
function Trig_Map_Initialization_Actions takes nothing returns nothing
    call FlushGameCache(InitGameCache("jasslocalvars.w3v"))
    set udg_HandleCache = InitGameCache("jasslocalvars.w3v")
endfunction

Each time you use stuff like global blocks, structs and such, you should put the whole code in a scope. This is how your code will look like:

JASS:
scope DW

globals
    private constant integer SPELL_ID = 'A00Y'
endglobals

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

private struct Data
    unit u
    real x
    real y
endstruct

function DW_M_Action takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Data dat = GetStoredInteger(HandleCache, I2S(H2I(t)), "dat")
endfunction

function DW_Actions takes nothing returns nothing
    local Data dat = Data.create()
    local unit u = GetTriggerUnit()
    local integer i = GetUnitAbilityLevel(u,SPELL_ID)
    local location l = GetSpellTargetLoc()
    local timer t = CreateTimer()
    set dat.u = u
    set dat.x = GetLocationX(l)
    set dat.y = GetLocationY(l)
    call StoreInteger(HandleCache, I2S(H2I(t)), "dat", dat)
    call TimerStart(t,0.01,false, function DW_M_Action)
    call RemoveLocation(l)
    set l = null
    set t = null
endfunction

function DW_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

//===========================================================================
function InitTrig_DW takes nothing returns nothing
    local trigger gg_trg_DW = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DW, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_DW, Condition( function DW_Conditions ) )
    call TriggerAddAction( gg_trg_DW, function DW_Actions )
endfunction

endscope


This is the basic setup, I suggest you read some Jass/vJass tutorials (there are good ones on wc3campaigns, and here also), you should learn about structs and stuff like that.

That SPELL_ID thing is an integer variable, but when you create globals like that, you don't need an udg_ prefix. Making a variable constant does practically nothing (concerning the basic types: real, integer, string, boolean and code), it just looks cooler. Constant variables return the same value all the time, they cannot be changed, so if you, for example, have a constant timer variable with the value of CreateTimer(), it'll create a new timer each time you use that variable, so it'll basically replace the CreateTimer() line and instead you can use that variable (don't know how that is useful, except if you want to save space). That differs from a non-constant variable because you can change it normally and the value of the variable is a single item so you can use that same item more than once. That was a sloppy explanation of constants, but I think you get the point.

The movement you want to achieve involves heavy triggering + advanced math, that is if you want to achieve it without lagging. I suggest you try to simplify your idea, since curves are not your strong side, I suppose.

I hope I have been of any help.

P.S. That DW_Load function is freaking me out.
 
Last edited:
Status
Not open for further replies.
Top