wc3edit.net
https://forum.wc3edit.net/

[JASS] JJCP: NewGen
http://forum.wc3edit.net/tutorials-cheatpacks-f80/jjcp-newgen-t37351-10.html
Page 2 of 4

Author:  haxorico [ May 6th, 2020, 7:01 pm ]
Post subject:  Re: [JASS] JJCP: NewGen

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:
            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-2458284

The 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 for CreateGroup:
Attachment:
CreateGroup.png


Spoiler for DestroyGroup:
Attachment:
DestroyGroup_2.png

Attachment:
DestroyGroup.png


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.

Author:  owner123 [ May 7th, 2020, 12:11 am ]
Post subject:  Re: [JASS] JJCP: NewGen

Great in-depth analysis, Unryze!

Author:  Vlkodlak_CZ [ May 17th, 2020, 2:04 am ]
Post subject:  Re: [JASS] JJCP: NewGen

Hi there I got Q why -copy work only on heroes?

Author:  owner123 [ May 18th, 2020, 10:33 pm ]
Post subject:  Re: [JASS] JJCP: NewGen

Because copying units was never programmed:
Code:
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:
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

Author:  Unryze [ May 28th, 2020, 1:06 pm ]
Post subject:  Re: [JASS] JJCP: NewGen

owner123 wrote:
Because copying units was never programmed:
Spoiler for original quote:
Code:
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:
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

Or even better:
Code:
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

Author:  nuzamacuxe [ May 29th, 2020, 12:16 am ]
Post subject:  Re: [JASS] JJCP: NewGen

Vlkodlak_CZ wrote:
Hi there I got Q why -copy work only on heroes?


Fixed.

Thanks to you guys.

Author:  havok43 [ July 3rd, 2020, 9:26 pm ]
Post subject:  Re: [JASS] JJCP: NewGen

can i request something? is it possible to make -tele applicable to everyone? if so can someone make it? thanks!!

Author:  owner123 [ July 5th, 2020, 6:17 pm ]
Post subject:  Re: [JASS] JJCP: NewGen

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:
call SaveInteger( jjHashTable, PlayerHandle( ), StringHash( "TPKey" ), 851990 )
call SaveBoolean( jjHashTable, PlayerHandle( ), StringHash( "Teleport" ), not GetBoolean( "Teleport" ) )

Code:
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.

Author:  havok43 [ July 5th, 2020, 8:15 pm ]
Post subject:  Re: [JASS] JJCP: NewGen

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:
call SaveInteger( jjHashTable, PlayerHandle( ), StringHash( "TPKey" ), 851990 )
call SaveBoolean( jjHashTable, PlayerHandle( ), StringHash( "Teleport" ), not GetBoolean( "Teleport" ) )

Code:
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

Author:  owner123 [ July 7th, 2020, 3:34 am ]
Post subject:  Re: [JASS] JJCP: NewGen

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.

Page 2 of 4 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/