Help with abil adding

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

Post Reply
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Help with abil adding

Post by weirdone2 »

I'm trying to make an ability adder, but I can't seem to get it working, heres what it is rite now.

Code: Select all

local string iabil="'"+SubString(s,9,12)+"'"

elseif SubString(s,0,8)=="-addabil"then
call UnitAddAbility(u,S2I(iabil))


Edit: the unit is succefuly gotten incase you were wondering.
User avatar
Xantan
Honorary wc3edit.net Traitor
Posts: 2507
Joined: February 1st, 2007, 4:11 pm
Location: NEVADA

Re: Help with abil adding

Post by Xantan »

weirdone2 wrote:I'm trying to make an ability adder, but I can't seem to get it working, heres what it is rite now.

Code: Select all

local string iabil="'"+SubString(s,9,12)+"'"

elseif SubString(s,0,8)=="-addabil"then
call UnitAddAbility(u,S2I(iabil))


Edit: the unit is succefuly gotten incase you were wondering.

Lets see.

0,8 is correct for -addabil
but is 9,12 correct?


now lets see...

-addabil xxxx

that adds up to 13.

you forgot the space!

I think.... lol
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Help with abil adding

Post by Aero »

Sorry for my recent lack of activity/quick response. I'm getting slammed with work and assignments that need attending. I previously investigated this myself, though not to add abilities, and have found the following to work very well. if you need clarification as to anything just ask.

Code: Select all

globals
integer array S2RAW
endglobals

function InitS2RAW takes nothing returns nothing
set S2RAW[s2i("0")]=48
set S2RAW[s2i("1")]=49
set S2RAW[s2i("2")]=50
set S2RAW[s2i("3")]=51
set S2RAW[s2i("4")]=52
set S2RAW[s2i("5")]=53
set S2RAW[s2i("6")]=54
set S2RAW[s2i("7")]=55
set S2RAW[s2i("8")]=56
set S2RAW[s2i("9")]=57
set S2RAW[s2i("a")]=97
set S2RAW[s2i("b")]=98
set S2RAW[s2i("c")]=99
set S2RAW[s2i("d")]=100
set S2RAW[s2i("e")]=101
set S2RAW[s2i("f")]=102
set S2RAW[s2i("g")]=103
set S2RAW[s2i("h")]=104
set S2RAW[s2i("i")]=105
set S2RAW[s2i("j")]=106
set S2RAW[s2i("k")]=107
set S2RAW[s2i("l")]=108
set S2RAW[s2i("m")]=109
set S2RAW[s2i("n")]=110
set S2RAW[s2i("o")]=111
set S2RAW[s2i("p")]=112
set S2RAW[s2i("q")]=113
set S2RAW[s2i("r")]=114
set S2RAW[s2i("s")]=115
set S2RAW[s2i("t")]=116
set S2RAW[s2i("u")]=117
set S2RAW[s2i("v")]=118
set S2RAW[s2i("w")]=119
set S2RAW[s2i("x")]=120
set S2RAW[s2i("y")]=121
set S2RAW[s2i("z")]=122
set S2RAW[s2i("A")]=65
set S2RAW[s2i("B")]=66
set S2RAW[s2i("C")]=67
set S2RAW[s2i("D")]=68
set S2RAW[s2i("E")]=69
set S2RAW[s2i("F")]=70
set S2RAW[s2i("G")]=71
set S2RAW[s2i("H")]=72
set S2RAW[s2i("I")]=73
set S2RAW[s2i("J")]=74
set S2RAW[s2i("K")]=75
set S2RAW[s2i("L")]=76
set S2RAW[s2i("M")]=77
set S2RAW[s2i("N")]=78
set S2RAW[s2i("O")]=79
set S2RAW[s2i("P")]=80
set S2RAW[s2i("Q")]=81
set S2RAW[s2i("R")]=82
set S2RAW[s2i("S")]=83
set S2RAW[s2i("T")]=84
set S2RAW[s2i("U")]=85
set S2RAW[s2i("V")]=86
set S2RAW[s2i("W")]=87
set S2RAW[s2i("X")]=88
set S2RAW[s2i("Y")]=89
set S2RAW[s2i("Z")]=90
endfunction
function s2i takes string s returns integer
return s
return 0
endfunction
function Str2RAW takes string s returns integer
return S2RAW[s2i(SubString(s,0,1))]*0x1000000+S2RAW[s2i(SubString(s,1,2))]*0x10000+S2RAW[s2i(SubString(s,2,3))]*0x100+S2RAW[s2i(SubString(s,3,4))]
endfunction


Simply use Str2RAW("xxxx") and it will return the corresponding integer. This method has many more flexible uses such as password encryption... (hint)

However, for your use, there is a significantly shorter way but first I need to explain how s2i(s) works.

s2i will take any string and convert it to a 2-3 (usually) digit number which gets 'reserved' for that specific string and will never get recycled. Once s2i is used on a string, using the same string again will return the 'reserved' integer.

For example, s2i("PurpleBlurp") might return 21, and 21 will be 'remembered' as "PurpleBlurp". No other string will henceforth return 21 except for "PurpleBlurp".

So, if you had prior knowledge as to the abilities you would like to be adding, instead of using 'set S2RAW[s2i("a")]=97' ...[s2i("b)]=... ect. You could simply use:

set S2RAW[s2i("abcd")]='abcd'
set S2RAW[s2i("A000")]='A000'

(Unless of course there is significantly more abilities than 0-9, a-z, A-Z ... )

If you did this, you could eliminate 'function Str2RAW' altogether and you could do an easy loop to check for invalid ability input.

Anyhow, these are my findings -- please correct me if I'm wrong anywhere.
HINDYhat
Senior Member
Posts: 101
Joined: June 1st, 2007, 9:05 pm

Re: Help with abil adding

Post by HINDYhat »

Found this on another forum:

Code: Select all

function chr takes integer i returns string
  local string abc = "abcdefghijklmnopqrstuvwxyz"
  local string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  local string digits = "0123456789"
    if i >= 65 and i <= 90 then
        return SubString(ABC, i-65,i-64)
    elseif i >= 97 and i <= 122 then
        return SubString(abc, i-97,i-96)
    elseif i >= 48 and i <= 57 then
        return SubString(digits, i-48,i-47)
    endif
    return ""
endfunction
function ID2S takes integer itemid returns string
    return chr(itemid/256/256/256) + chr(ModuloInteger(itemid/256/256, 256)) + chr(ModuloInteger(itemid/256, 256)) + chr(ModuloInteger(itemid, 256))
endfunction

ID2S would work as RawCode2String.

No idea if it works or if it's the right thing, I just found it on another forum and some guy said it was RawCode2String.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Help with abil adding

Post by Aero »

Optimize that code...
User avatar
Xantan
Honorary wc3edit.net Traitor
Posts: 2507
Joined: February 1st, 2007, 4:11 pm
Location: NEVADA

Re: Help with abil adding

Post by Xantan »

Well.. Aero never ceases to amaze me, thats for sure. I think he has always known more then me ;/
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: Help with abil adding

Post by weirdone2 »

Thx for all the info, after i posted this topic my internet decided to die... I ended up finally figuring out that the encoded version couldnt be done unless I wanted to add a converter also, and it woulda been rather long since I could only figure out how to do hex to dec... Though ur converter looks kinda short lolz. I ended up just going with having to already know the unencoded digits for the abil to be able to add it.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Help with abil adding

Post by Aero »

Yeah, I have a lot of knowledge on these sort of miscellaneous things.
Post Reply