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".
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
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..
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.
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.
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]
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
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.
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