wc3edit.net

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

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: December 11th, 2016, 12:40 am 
Offline
Old Wrinkly Member
User avatar

Joined: April 19th, 2009, 12:46 pm
Posts: 234
Hullo~

I'm making a new post about this since I tried to come up with a better way to do it (without deprotecting the map and looking for the Rects in map editor) and wanted peoples' opinions on if there is a better way to do it. So, essentially, I take a "-ping xxx.xx,xxx.xx,xxx.xx" command that looks for a X,Y,Duration for a map ping. I figured this would be an easy format to use since most of the Rect creations in JASS use "x,y,x2,y2".

Code:
function PingLoc takes player p2p,string s2s returns nothing
local real xLoc=0.0
local real yLoc=0.0
local real pingDuration=0.0
local integer loopCounter=0
local integer stringLength=StringLength(s2s)
local integer loopDone=0
local integer xIndex=0
loop
exitwhen loopDone==2 or loopCounter>stringLength
if SubString(s2s,loopCounter,loopCounter+1)==","then
if loopDone==0then
set xLoc=S2R(SubString(s2s,0,loopCounter))
set xIndex=loopCounter+1
set loopDone=loopDone+1
endif
if (loopDone==1)and(loopCounter!=xIndex-1)then
set yLoc=S2R(SubString(s2s,xIndex,loopCounter))
set pingDuration=S2R(SubString(s2s,loopCounter+1,stringLength))
set loopDone=loopDone+1
endif
endif
set loopCounter=loopCounter+1
endloop
call DisplayTextToPlayer(p2p,0,0,"Ping X:"+R2S(xLoc)+" Y:"+R2S(yLoc)+" Duration:"+R2S(pingDuration))
call PingMinimapForPlayer(p2p,xLoc,yLoc,pingDuration)
endfunction


Top
 Profile  
 
PostPosted: December 11th, 2016, 6:46 am 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3815
Location: JEW LAND
Made a cleaner command. Also removed memory leaks.
Code:
function FindPoint takes string s2s, integer whichPoint returns real
    local integer looper1=6 //skip 6 first characters, -ping<space>
    local integer currentPoint=1
    local string tempLoc=""
    local string currentChar=""
    local real retLoc=-1
    if whichPoint>5 or whichPoint<1 then
        return -1
    endif
    loop
        exitwhen looper1>StringLength(s2s)
        set currentChar=SubString(s2s,looper1,looper1+1)
        if (currentChar==",") then     
            set currentPoint=currentPoint+1
        elseif (whichPoint==currentPoint and currentChar!=" ") then
            set tempLoc=tempLoc+currentChar
        endif
        if (currentPoint>whichPoint) then
            //got the point. no need for all the loop to go on. Get value and return it
            set retLoc=S2R(tempLoc)
            set tempLoc="" //memory leak fix
            set s2s="" //memory leak fix
            return retLoc
        endif
        set looper1=looper1+1
    endloop
    set retLoc=S2R(tempLoc)
    set tempLoc="" //memory leak fix
    set s2s="" //memory leak fix
    return retLoc
endfunction

function PingLoc takes nothing returns nothing
    local real x1 = FindPoint(GetEventPlayerChatString(),1) 
    local real y1 = FindPoint(GetEventPlayerChatString(),2)
    //local real x2 = FindPoint(GetEventPlayerChatString(),3)
    //local real y2 = FindPoint(GetEventPlayerChatString(),4)
    local real pingDuration = FindPoint(GetEventPlayerChatString(),3)//if you are using all of the above. set it to 5.
    call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Ping x1:"+R2S(x1)+" y1:"+R2S(y1)+" Duration:"+R2S(pingDuration))
    call PingMinimapForPlayer(GetTriggerPlayer(),x1,y1,pingDuration)
endfunction

Also I thought you needed x1 and x2 so I showed you how to get it.
Mainly the command FindPoint takes the string (to find) and the place in the string, 1=first paramater to find (in your example its X) etc..


Top
 Profile  
 
PostPosted: December 11th, 2016, 6:20 pm 
Offline
Old Wrinkly Member
User avatar

Joined: April 19th, 2009, 12:46 pm
Posts: 234
Oh ok cool, this seems like a much smarter way of approaching it haha. Another small question, is there an easy way to create some sort of string split function? (I ask since you can't pass arrays). Or would I have to use something like an outer array to catch all that.


Top
 Profile  
 
PostPosted: December 11th, 2016, 8:35 pm 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3815
Location: JEW LAND
Durge wrote:
Oh ok cool, this seems like a much smarter way of approaching it haha. Another small question, is there an easy way to create some sort of string split function? (I ask since you can't pass arrays). Or would I have to use something like an outer array to catch all that.

I don't quite understand what you mean. Mind giving me an example of a command (like "-ping X,Y,D") and then tell me what it is supposed to do. I might be able to help you with it.


Top
 Profile  
 
PostPosted: December 11th, 2016, 11:09 pm 
Offline
Old Wrinkly Member
User avatar

Joined: April 19th, 2009, 12:46 pm
Posts: 234
Oh sure sorry, I figured it was a common enough programming method xD. "Split" takes a string and a delimeter (or a key character) and then runs through a string and creates an array where the number of elements equals the amount of strings separated by the delimeter character.

Ex: Split("1,2,3,4,5",",") would return an array holding [1][2][3][4][5]


Top
 Profile  
 
PostPosted: December 12th, 2016, 12:09 am 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3815
Location: JEW LAND
I don't see why that won't work for the trigger above.
I coded the following while at work so I cannot test if it works. But you should be able to see the logic behind it. If not let me know and I will test / explain when I am at home and can properly test it

add the global
Code:
string array haxSplits

and the function itself
Code:

function SetSplits takes string s2s returns nothing
    local integer looper1=6 //skip 6 first characters, -ping<space>
    local integer currentSplitLoc=1
    local string tempLoc=""
    local string currentChar=""   
    loop
        exitwhen looper1>StringLength(s2s)
        set currentChar=SubString(s2s,looper1,looper1+1)
        if (currentChar==",") then     
         set haxSplits[curretSplitLoc]=tempLoc
         set tempLoc="" //empty the string to fill the next one
            set currentSplitLoc=currentSplitLoc+1
        elseif (currentSplitLoc!=" ") then //just to make sure it won't add spaces.
            set tempLoc=tempLoc+currentChar
        endif
        set looper1=looper1+1
    endloop
    set haxSplits[curretSplitLoc+1]=tempLoc//last value to add
    set tempLoc="" //memory leak fix
    set s2s="" //memory leak fix
   set currentChar=""//memory leak fix
endfunction



Also you could probably make it better. tempLoc could be removed. But again I cannot properly test and code at the moment. This should give you the basic structure to work with.

Note: haxSplits[0] is empty and not being used.


Top
 Profile  
 
PostPosted: December 12th, 2016, 12:20 am 
Offline
Old Wrinkly Member
User avatar

Joined: April 19th, 2009, 12:46 pm
Posts: 234
Ok cool, I figured using a global array would be the only clean way to do it, but wasn't sure if there was a different way to keep it local, thanks!


Top
 Profile  
 
PostPosted: December 12th, 2016, 3:22 pm 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3815
Location: JEW LAND
Got bored at work. Made the following code. Let me know how this works.
Code:
globals
    string array haxSplits
endglobals

function SetSplits takes string s2s returns nothing
    local integer looper1=6 //skip 6 first characters, -ping<space>
    local integer currentSplitLoc=1
    local string currentChar=""
    loop
        exitwhen looper1>StringLength(s2s)
        set currentChar=SubString(s2s,looper1,looper1+1)
        if (currentChar==",") then
            set currentSplitLoc=currentSplitLoc+1
        elseif (currentChar!=" ") then //just to make sure it won't add spaces.
            set haxSplits[currentSplitLoc]=haxSplits[currentSplitLoc]+currentChar
        endif
        set looper1=looper1+1
    endloop
    set s2s="" //memory leak fix
    set currentChar=""//memory leak fix
endfunction


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 12 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)