wc3edit.net

United Warcraft 3 map hacking!
It is currently March 28th, 2024, 10:22 pm

All times are UTC




Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 6th, 2020, 7:01 pm 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3815
Location: JEW LAND
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.


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 7th, 2020, 12:11 am 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2394
Great in-depth analysis, Unryze!


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 17th, 2020, 2:04 am 
Offline
Newcomer

Joined: April 25th, 2020, 2:46 pm
Posts: 3
Hi there I got Q why -copy work only on heroes?


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 18th, 2020, 10:33 pm 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2394
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


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 28th, 2020, 1:06 pm 
Offline
Member
User avatar

Joined: October 21st, 2013, 4:18 pm
Posts: 75
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


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 29th, 2020, 12:16 am 
Offline
Also Not an Admin, but closer than devoltz
User avatar

Joined: February 14th, 2018, 5:35 am
Posts: 1791
Title: Just Another S.Mod
Vlkodlak_CZ wrote:
Hi there I got Q why -copy work only on heroes?


Fixed.

Thanks to you guys.


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: July 3rd, 2020, 9:26 pm 
Offline
Newcomer

Joined: December 26th, 2019, 2:11 am
Posts: 2
can i request something? is it possible to make -tele applicable to everyone? if so can someone make it? thanks!!


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: July 5th, 2020, 6:17 pm 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2394
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.


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: July 5th, 2020, 8:15 pm 
Offline
Newcomer

Joined: December 26th, 2019, 2:11 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: July 7th, 2020, 3:34 am 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2394
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

phpBB SEO


Privacy Policy Statement
Impressum (German)