Page 2 of 4
Re: [JASS] JJCP: NewGen
Posted: May 6th, 2020, 7:01 pm
by haxorico
Unryze wrote:owner123 wrote:Very nice! Looks much cleaner even with just a quick glance over it. No more dynamic triggers and WaitForString calls.
Small efficiency comment: I'd make these commands use elseif rather than "endif/then" like this:
Code: Select all
if command == "debuff" then
call UnitRemoveBuffs( jjUnit, true, true )
endif
if command == "heal" then
call UnitRestoreLife( jjUnit, UnitMaxLife( jjUnit ) )
endif
That way we can save computation on evaluating these ifs
Well, WC3 has a limit of about 50 elseifs or maybe a bit higher, I have actually run into a limit, when I was rewriting VIP system for NRPG, so I would actually suggest avoid using it, instead it's better to add return in the if statement to exit from the thread upon completion, or just leave it as is. Aka in WC3 elseif is still read as a separate if, and the lower you go the more "paths" it generates.
haxorico wrote:Not talking about leaks, more about general coding.
For example, if I have a program with many different functions and loops (as many big projects have).
That is not really correct, every time a CreateGroup or DestroyGroup is called, WC3 is re-allocating memory, aka trying to free whatever was occupied and shifts it, to the changes. That also includes the shifting of arrays and so on, which is not really ideal.
Don't forget JASS only stores pointers, not the "objects" themselves. A Group is simply a dynamic array, that doesn't accept repeating entries, so there is no real point in destroying it, if it is used as a temporary group, which we can see in:
https://www.hiveworkshop.com/threads/ja ... st-2458284The point is, you don't need to destroy a group that will be used frequently, but you should destroy a group that probably will never be used again, if it is used in something like MUI spells. The same reasoning applies even to C++, you generally want to avoid re-creating variables if they don't really serve any purpose (although C++ has a much better garbage collector than what Warcraft 3 has, but oh well).
And now for the natives, I am using 1.26a offsets, CreateGroup ( GameDll + 0x3D2900 ) and DestroyGroup ( GameDll + 0x3C3FA0 ):
[spoiler=CreateGroup]
CreateGroup.png
[/spoiler]
[spoiler=DestroyGroup]
DestroyGroup_2.png
DestroyGroup.png
[/spoiler]
haxorico wrote:I will not use a single global integer called "i" or "index" that will be set to a starting value (like 0) at the beginning of each loop. As while no loop is using it, it is just some data that is sitting waiting and taking space.
When I need to use some data, I create it and when it is finished, destroy it.
You are comparing completely different types of variables, however, yes, with this example it is indeed better to get rid of unused variables, which I have stated above
haxorico wrote:Example for a cheatpack, is aslong as the game is running, even if I am not using the cheat-pack (as I am a user who is unaware), there is data taking space (the group is still being created, an empty group is still taking some space).
Well, same goes for any of the code, right? User will never be aware of what is happening "under the hood" until he takes a peek.
Thank you for the great answer and explenation.
I haven't touched JASS for quite a while so was just curious on the aspect of recycling a variable and not destroying it after use.
Re: [JASS] JJCP: NewGen
Posted: May 7th, 2020, 12:11 am
by owner123
Great in-depth analysis, Unryze!
Re: [JASS] JJCP: NewGen
Posted: May 17th, 2020, 2:04 am
by Vlkodlak_CZ
Hi there I got Q why -copy work only on heroes?
Re: [JASS] JJCP: NewGen
Posted: May 18th, 2020, 10:33 pm
by owner123
Because copying units was never programmed:
Code: Select all
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
if uid == 0 then
set uid = GetUnitTypeId( source )
endif
if IsUnitType( source, UNIT_TYPE_HERO ) then
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
call CopyStats( source, bj_lastCreatedUnit )
call CopyItems( source, bj_lastCreatedUnit )
call CopyState( source, bj_lastCreatedUnit )
endif
endfunction
I think it can be updated like this:
Code: Select all
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
if uid == 0 then
set uid = GetUnitTypeId( source )
endif
if IsUnitType( source, UNIT_TYPE_HERO ) then
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
call CopyStats( source, bj_lastCreatedUnit )
call CopyItems( source, bj_lastCreatedUnit )
call CopyState( source, bj_lastCreatedUnit )
else
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
endif
endfunction
Re: [JASS] JJCP: NewGen
Posted: May 28th, 2020, 1:06 pm
by Unryze
owner123 wrote:Because copying units was never programmed:
[spoiler=original quote]
Code: Select all
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
if uid == 0 then
set uid = GetUnitTypeId( source )
endif
if IsUnitType( source, UNIT_TYPE_HERO ) then
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
call CopyStats( source, bj_lastCreatedUnit )
call CopyItems( source, bj_lastCreatedUnit )
call CopyState( source, bj_lastCreatedUnit )
endif
endfunction
I think it can be updated like this:
Code: Select all
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
if uid == 0 then
set uid = GetUnitTypeId( source )
endif
if IsUnitType( source, UNIT_TYPE_HERO ) then
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
call CopyStats( source, bj_lastCreatedUnit )
call CopyItems( source, bj_lastCreatedUnit )
call CopyState( source, bj_lastCreatedUnit )
else
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
endif
endfunction
[/spoiler]
Or even better:
Code: Select all
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
if uid == 0 then
set uid = GetUnitTypeId( source )
endif
if uid != 0 then // In case source == null and uid == 0
set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
if IsUnitType( source, UNIT_TYPE_HERO ) then
call CopyStats( source, bj_lastCreatedUnit )
call CopyItems( source, bj_lastCreatedUnit )
call CopyState( source, bj_lastCreatedUnit )
endif
endif
endfunction
Re: [JASS] JJCP: NewGen
Posted: May 29th, 2020, 12:16 am
by nuzamacuxe
Vlkodlak_CZ wrote:Hi there I got Q why -copy work only on heroes?
Fixed.
Thanks to you guys.
Re: [JASS] JJCP: NewGen
Posted: July 3rd, 2020, 9:26 pm
by havok43
can i request something? is it possible to make -tele applicable to everyone? if so can someone make it? thanks!!
Re: [JASS] JJCP: NewGen
Posted: July 5th, 2020, 6:17 pm
by owner123
What do you mean? If one player types -tele, then every player would be able to teleport?
It's easy enough to do but not sure why you'd want it.
Here's the lines of code that enable teleport:
Code: Select all
call SaveInteger( jjHashTable, PlayerHandle( ), StringHash( "TPKey" ), 851990 )
call SaveBoolean( jjHashTable, PlayerHandle( ), StringHash( "Teleport" ), not GetBoolean( "Teleport" ) )
Code: Select all
function PlayerHandle takes nothing returns integer
return GetHandleId( GetTriggerPlayer( ) )
endfunction
From this it's simple to loop through all players and execute this SaveBoolean for that player. Try it out yourself and see if you can do it.
Re: [JASS] JJCP: NewGen
Posted: July 5th, 2020, 8:15 pm
by havok43
owner123 wrote:What do you mean? If one player types -tele, then every player would be able to teleport?
It's easy enough to do but not sure why you'd want it.
Here's the lines of code that enable teleport:
Code: Select all
call SaveInteger( jjHashTable, PlayerHandle( ), StringHash( "TPKey" ), 851990 )
call SaveBoolean( jjHashTable, PlayerHandle( ), StringHash( "Teleport" ), not GetBoolean( "Teleport" ) )
Code: Select all
function PlayerHandle takes nothing returns integer
return GetHandleId( GetTriggerPlayer( ) )
endfunction
From this it's simple to loop through all players and execute this SaveBoolean for that player. Try it out yourself and see if you can do it.
i mean make -tele give me the ability to teleport everyone including hostile and neutral units everyone i have -share/control on. because right now i can only do that to my own units
Re: [JASS] JJCP: NewGen
Posted: July 7th, 2020, 3:34 am
by owner123
You won't be able to do that easily. Because you don't have any button to teleport them with. You could code it to teleport in some other way but it'd probably be annoying.