• 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] CODE problem ;p

Status
Not open for further replies.
Level 6
Joined
Mar 9, 2009
Messages
175
sry my eng abit lousy~~ er i copy 2 spell from 2 different map and the code were different ...:gg: how to use 2 code in 1 map (myownmap)
 
Level 6
Joined
Aug 19, 2006
Messages
187
go into your map and create 2 new triggers. convert them to custom text delete everything in it and then copy the code from the other map into your triggers. 1 trigger = 1 spell. you also have to copy the spells from the object editor and copy the dummy units if there are dummies used.
 
Level 11
Joined
May 16, 2007
Messages
288
Make sure you are running the NewGen WE, not normal WE, even if you have newgen but are running on normal WE, it will not work.

Now, even if you are running on NewGen WE and the problem persists, post the trigger here and I'll see what I can do.
 
Level 6
Joined
Mar 9, 2009
Messages
175
function AntiLeak takes nothing returns boolean
return true
endfunction

library Knockback initializer Init

// *******************************************************************************
// ** **
// ** Knockback(Ex) **
// ** ————————————— **
// ** **
// ** Just a function I made for efficient knockbacking **
// ** ** Made by Silvenon
// *******************************************************************************

public struct Data
unit u
real d1
real d2

real sin
real cos

real r

string s = ""
effect e = null
endstruct

globals
private timer Tim = CreateTimer()
private Data array Ar
private boolean array BoolAr
private integer Total = 0
private boolexpr Cond = null

private real MAX_X
private real MAX_Y
private real MIN_X
private real MIN_Y
endglobals

public function TreeFilter takes nothing returns boolean
local integer d = GetDestructableTypeId(GetFilterDestructable())
return d == 'ATtr' or d == 'BTtw' or d == 'KTtw' or d == 'YTft' or d == 'JTct' or d == 'YTst' or d == 'YTct' or d == 'YTwt' or d == 'JTwt' or d == 'JTwt' or d == 'FTtw' or d == 'CTtr' or d == 'ITtw' or d == 'NTtw' or d == 'OTtw' or d == 'ZTtw' or d == 'WTst' or d == 'LTlt' or d == 'GTsh' or d == 'Xtlt' or d == 'WTtw' or d == 'Attc' or d == 'BTtc' or d == 'CTtc' or d == 'ITtc' or d == 'NTtc' or d == 'ZTtc'
endfunction

private constant function Interval takes nothing returns real
return 0.04
endfunction

private function KillTree takes nothing returns nothing
if BoolAr[0] then
call KillDestructable(GetEnumDestructable())
else
set BoolAr[1] = true
endif
endfunction

private function Execute takes nothing returns nothing
local Data kd
local integer i = 0
local real x
local real y
local rect r

loop
exitwhen i >= Total
set kd = Ar

if kd.s != null and kd.s != null then
set x = GetUnitX(kd.u)
set y = GetUnitY(kd.u)

call DestroyEffect(AddSpecialEffect(kd.s, x, y))

set x = x + kd.d1 * kd.cos
set y = y + kd.d1 * kd.sin
else
set x = GetUnitX(kd.u) + kd.d1 * kd.cos
set y = GetUnitY(kd.u) + kd.d1 * kd.sin
endif

set r = Rect(x - kd.r, y - kd.r, x + kd.r, y + kd.r)
set BoolAr[0] = kd.r != 0

call EnumDestructablesInRect(r, Cond, function KillTree)
call RemoveRect(r)

set r = null

if (x < MAX_X and y < MAX_Y and x > MIN_X and y > MIN_Y) and not BoolAr[1] then
call SetUnitX(kd.u, x)
call SetUnitY(kd.u, y)
endif

set kd.d1 = kd.d1 - kd.d2

if kd.d1 <= 0 or (x > MAX_X or y > MAX_Y or x < MIN_X or y < MIN_Y) or BoolAr[1] then

if kd.e != null then
call DestroyEffect(kd.e)
endif

call PauseUnit(kd.u, false)

set Ar = Ar[Total - 1]
set Total = Total - 1
call kd.destroy()

set BoolAr[0] = false
set BoolAr[1] = false
endif

set i = i + 1
endloop

if Total == 0 then
call PauseTimer(Tim)
endif
endfunction

function KnockbackEx takes unit u, real d, real a, real w, real r, integer t, string s, string p returns Data
local Data kd = Data.create()
local integer q = R2I(w / Interval())

set kd.u = u
set kd.d1 = 2 * d / (q + 1)
set kd.d2 = kd.d1 / q

set kd.sin = Sin(a)
set kd.cos = Cos(a)

set kd.r = r

if s != "" and s != null then
if t == 2 then
if p != "" and p != null then
set kd.e = AddSpecialEffectTarget(s, u, p)
else
set kd.e = AddSpecialEffectTarget(s, u, "chest")
endif
elseif t == 1 then
set kd.s = s
endif
endif

call SetUnitPosition(u, GetUnitX(u), GetUnitY(u))
call PauseUnit(u, true)

if Total == 0 then
call TimerStart(Tim, Interval(), true, function Execute)
endif

set Total = Total + 1
set Ar[Total - 1] = kd

return kd
endfunction

function Knockback takes unit u, real d, real a, real w returns Data
return KnockbackEx(u, d, a, w, 0, 1, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", "")
endfunction

private function Init takes nothing returns nothing
set Cond = Filter(function TreeFilter)

set BoolAr[0] = false
set BoolAr[1] = false

set MAX_X = GetRectMaxX(bj_mapInitialPlayableArea) - 64
set MAX_Y = GetRectMaxY(bj_mapInitialPlayableArea) - 64
set MIN_X = GetRectMinX(bj_mapInitialPlayableArea) + 64
set MIN_Y = GetRectMinY(bj_mapInitialPlayableArea) + 64
endfunction

endlibrary

function SetUnitXY takes unit u, real x, real y returns nothing
local real minx = GetRectMinX ( bj_mapInitialPlayableArea )
local real maxx = GetRectMaxX ( bj_mapInitialPlayableArea )
local real miny = GetRectMinY ( bj_mapInitialPlayableArea )
local real maxy = GetRectMaxY ( bj_mapInitialPlayableArea )
if ( x < minx ) then
call SetUnitX ( u, minx )
elseif ( x > maxx ) then
call SetUnitX ( u, maxx )
else
call SetUnitX ( u, x )
endif
if ( y < miny ) then
call SetUnitY ( u, miny )
elseif ( y > maxy ) then
call SetUnitY ( u, maxy )
else
call SetUnitY ( u, y )
endif
endfunction

library Jump initializer Init_Jump

// *******************************************************************************
// ** **
// ** Jump **
// ** ———————— **
// ** **
// ** Just a function I made for efficient jumping **
// ** **
// *******************************************************************************

//========================================//
//Credits to Shadow1500 for this function!//
//========================================//

private function JumpParabola takes real dist, real maxdist, real curve returns real
local real t = (dist * 2) / maxdist - 1
return (- t * t + 1) * (maxdist / curve)
endfunction

//=======================================//
//Credits to PitzerMike for this function//
//=======================================//

//===========================================================================

private function TreeKill takes nothing returns nothing
call KillDestructable(GetEnumDestructable())
endfunction

globals
private integer DUMMY_ID = 'h005'

private constant real Interval = 0.035
private boolexpr Bool
private location Loc = Location(0, 0)

private timer Tim = CreateTimer()
private integer Total = 0
endglobals

private function TreeFilter takes nothing returns boolean
local destructable d = GetFilterDestructable()
local boolean i = IsDestructableInvulnerable(d)
local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID,GetWidgetX(d), GetWidgetY(d), 0)
local boolean result = false
call UnitAddAbility(u, 'Ahrl')
if i then
call SetDestructableInvulnerable(d, false)
endif
set result = IssueTargetOrder(u, "harvest", d)
call RemoveUnit(u)
if i then
call SetDestructableInvulnerable(d, true)
endif
set u = null
set d = null
return result
endfunction

public struct Data
unit u
integer q
real md
real d
real c

real sin
real cos
integer i = 1

real r
string s

static method create takes unit u, integer q, real x2, real y2, real c, real r, string s1, string s2 returns Data
local Data dat = Data.allocate()

local real x1 = GetUnitX(u)
local real y1 = GetUnitY(u)
local real dx = x1 - x2
local real dy = y1 - y2
local real a = Atan2(y2 - y1, x2 - x1)

set dat.u = u
set dat.q = q
set dat.md = SquareRoot(dx * dx + dy * dy)
set dat.d = dat.md / q
set dat.c = c
set dat.sin = Sin(a)
set dat.cos = Cos(a)
set dat.r = r
set dat.s = s2

if s1 != "" and s1 != null then
call DestroyEffect(AddSpecialEffect(s1, x1, y1))
endif

call UnitAddAbility(u, 'Amrf')
call UnitRemoveAbility(u, 'Amrf')
call PauseUnit(u, true)

return dat
endmethod

method onDestroy takes nothing returns nothing
local real x
local real y
local rect r

if .r != 0 then
set x = GetUnitX(.u)
set y = GetUnitY(.u)
set r = Rect(x - .r, y - .r, x + .r, y + .r)
call EnumDestructablesInRect(r, Bool, function TreeKill)
call RemoveRect(r)

set r = null
endif

if .s != "" and .s != null then
call DestroyEffect(AddSpecialEffect(.s, x, y))
endif

call PauseUnit(.u, false)
endmethod
endstruct

globals
private Data array Ar
endglobals

private function Execute takes nothing returns nothing
local Data dat
local integer i = 0
local real x
local real y
local location l
local real h
local rect r

loop
exitwhen i >= Total
set dat = Ar
set x = GetUnitX(dat.u) + dat.d * dat.cos
set y = GetUnitY(dat.u) + dat.d * dat.sin

call MoveLocation(Loc, x, y)

set h = JumpParabola(dat.d * dat.i, dat.md, dat.c) - GetLocationZ(Loc)

call SetUnitX(dat.u, x)
call SetUnitY(dat.u, y)
call SetUnitFlyHeight(dat.u, h, 0)

if dat.i >= dat.q then
call dat.destroy()
set Total = Total - 1
set Ar = Ar[Total]
else
set dat.i = dat.i + 1
endif

set i = i + 1
endloop

if Total == 0 then
call PauseTimer(Tim)
endif

set l = null
endfunction

function Jump takes unit whichUnit, real dur, real destX, real destY, real curve, real radius, string sfx1, string sfx2 returns nothing
local Data dat = Data.create(whichUnit, R2I(dur / Interval), destX, destY, curve, radius, sfx1, sfx2)

if Total == 0 then
call TimerStart(Tim, Interval, true, function Execute)
endif

set Ar[Total] = dat
set Total = Total + 1
endfunction

//==================================================================================

function Init_Jump takes nothing returns nothing
set Bool = Filter(function TreeFilter)
endfunction

endlibrary


function CreateTextTagUnit takes string s, unit whichUnit, real zOffset, real size, integer red, integer green, integer blue, integer transparency, real velocityA, real velocityB, real lifespan, boolean perma, boolean visible returns nothing
local texttag LastTextTag = CreateTextTag()
call SetTextTagText(LastTextTag, s, size * 0.023 / 10)
call SetTextTagPosUnit(LastTextTag, whichUnit, zOffset)
call SetTextTagColor(LastTextTag, red, green, blue, transparency)
call SetTextTagVelocity( LastTextTag, velocityA, velocityB )
call SetTextTagLifespan( LastTextTag, lifespan )
call SetTextTagPermanent( LastTextTag, perma )
call SetTextTagVisibility( LastTextTag, visible )
endfunction

this is a code ~~
 
Level 11
Joined
May 16, 2007
Messages
288
That trigger is working perfectly, if you're talking about the error message:
"The trigger 'trigger name' must have an initialization function called 'InitTrg_triggername'." then ignore it if you're using NewGen, it'll automatically generate that function (but be careful, if you're writing a code and don't make a function to register the trigger events and actions/conditions, NewGen will generate the init function, but since it cannot identify which functions in your trigger are actions/conditions, the trigger will not run).
 
Level 11
Joined
May 16, 2007
Messages
288
Ok, let me explain these things a little:

JASS is the programming (or scripting, whatever you call it) language used by all Warcraft 3 codes, even when you make something in GUI, you're actually making a code in JASS, just using a different interface.

vJASS is an extension to JASS made by Vexorian, it does everything JASS can do and a whole lot more, it's purpose is to make JASS more object oriented, when you run a map, vJASS code is converted to JASS so that it can run, so you could basically consider vJASS a way to make JASS scripting easier.

Now, JESP is neither a language nor an extension to JASS, vJASS or GUI, JESP (JASS enhanced spell pseudotemplate) is an agreement between the coding community that says “all spells must have a SETUP section in the code. Inside this SETUP section the user will be able to modify the spell without having the need to enter the spell’s core or without having the need to even understand it. A SETUP section can be anywhere inside the spell” among other small rules.

Now, about your question, yes, a map can have JASS and vJASS code and will still work.
 
Level 11
Joined
May 16, 2007
Messages
288
Wait, are you putting all the JASS stuff into one trigger? I'm guessing thats what you did based on the stuff you copyed above. That could be whats caussing problems

No, that's not it, I put the whole code in a single trigger and it still worked perfectly.

o2bryan, what kind of error are you having, and when does it happen? Does it happen while saving the map or after turning off / on a trigger? If it's the 2nd option, save the map and see if it happens while saving too. If it doesn't, then I'm pretty sure that the trigger will still work (but only if you are using JNGP, if you're not, it will NOT work).
 
Status
Not open for further replies.
Top