"Typing" terrain...

mini.dude_22

New Member
Reaction score
1
Hello again, i am still working on the same map.
This time the problem is with SubString's. ( yes, i have looked at other posts )
So in my map i want to expand on the terrain types you can use, so i am adding a command in which you can enter the raw code for the terrain you would like to use. Anyways, here is the trigger's.
Doh, i hate substrings :banghead:
JASS:
function CheckTerrainType takes integer terraintype returns boolean
    local boolean b
    set i = 0
    loop
        exitwhen i > 177 //yes, i have an array with 177 value's for the different types of terrain lol
        if terraintype == terrain<i> then
            set b = true
        else
            set b = false
        endif
        set i = i + 1
    endloop
    return b
endfunction</i>


JASS:
scope ChangeTerrainVar

private function conditions takes nothing returns boolean
    local integer stringlength = StringLength( GetEventPlayerChatString() )
    local string s = GetEventPlayerChatString()
    local boolean b = false
    if stringlength &lt; 15 then
        if SubString ( s, 1, 9 ) == &quot;-terrain &quot; then
            if SubString ( s, 10, 10 ) == &quot;&#039;&quot; then
                if SubString ( s, 15, 15 ) == &quot;&#039;&quot; then
                set b = true
                else
                call BJDebugMsg ( &quot;Missing the second &#039;&quot; )
                endif
            else
            call BJDebugMsg ( &quot;Missing the first &#039;&quot; )
            endif
        else
        call BJDebugMsg ( &quot;Missing -terrain.&quot; ) 
// This fails, if you have just &#039;-terrain&#039; it works, but does not say that i am
// missing either of the &#039;, if i type it in like &#039;-terrain &#039; it says that terrain failed
// i cant test either of the &#039;, because i cant get past &#039;-terrain &#039; the space is 
// failing even &quot;-terrain &#039;&quot; with one of the &#039; says that it still is missing
// the &#039;-terrain&#039;
        endif
    else
    call BJDebugMsg ( &quot;String is too long.&quot; ) // This Works
    endif
    return b
endfunction

private function actions takes nothing returns nothing
    local integer terrainrawname = S2I ( SubString ( GetEventPlayerChatString(), 10, 15 ) )
    if CheckTerrainType ( terrainrawname ) then
        set terrainid[GetPlayerId ( GetTriggerPlayer() )] = terrainrawname
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;Terrain type changed.&quot; )
    else
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;Not a valid terrain type, check your quest for all the valid ones. -3&quot; )
    endif   
endfunction

//===========================================================================
function InitTrig_ChangeTerrainVar takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    set i = 0
    loop
        exitwhen i &gt; 8
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-&quot; + &quot;terrain&quot; + &quot; &quot; + &quot;&quot;, false )
        set i = i + 1
    endloop
    call TriggerAddCondition ( t, Condition (function conditions) )
    call TriggerAddAction( t, function actions )
endfunction

endscope
 

Strilanc

Veteran Scripter
Reaction score
42
Character dividers start at 0, not 1. (Unless you're using GUI, where it's 1 for some weird reason).
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> else
> set b = false

Put the false on the local line.
Otherwise b will always be false unless the "terrain" was the very last one in your list.


> set i = 0

Hm... you have a global variable called i? ...
 

mini.dude_22

New Member
Reaction score
1
K i am still having problems with this trigger, can anyone help me out?

Here i set the String Array Terrain variables:
JASS:
scope SetTerrainVariables

private function actions takes nothing returns nothing
	set terrain[1] = &quot;Ldrt&quot;
	set terrain[2] = &quot;Ldro&quot;
	set terrain[3] = &quot;Ldrg&quot;
	set terrain[4] = &quot;Lrok&quot;
	set terrain[5] = &quot;Lgrs&quot;
	set terrain[6] = &quot;Lgrd&quot;
	set terrain[7] = &quot;Fdrt&quot;
	set terrain[8] = &quot;Fdro&quot;
	set terrain[9] = &quot;Fdrg&quot;
	set terrain[10] = &quot;Frok&quot;
	set terrain[11] = &quot;Fgrs&quot;
	set terrain[12] = &quot;Fgrd&quot;
	set terrain[13] = &quot;Wdrt&quot;
	set terrain[14] = &quot;Wdro&quot;
	set terrain[15] = &quot;Wsng&quot;
	set terrain[16] = &quot;Wrok&quot;
	set terrain[17] = &quot;Wgrs&quot;
	set terrain[18] = &quot;Wsnw&quot;
	set terrain[19] = &quot;Bdrt&quot;
	set terrain[20] = &quot;Bdrh&quot;
	set terrain[21] = &quot;Bdrr&quot;
	set terrain[22] = &quot;Bdrg&quot;
	set terrain[23] = &quot;Bdsr&quot;
	set terrain[24] = &quot;Bdsd&quot;
	set terrain[25] = &quot;Bflr&quot;
	set terrain[26] = &quot;Bgrr&quot;
	set terrain[27] = &quot;Adrt&quot;
	set terrain[28] = &quot;Adrd&quot;
	set terrain[29] = &quot;Agrs&quot;
	set terrain[30] = &quot;Arck&quot;
	set terrain[31] = &quot;Agrd&quot;
	set terrain[32] = &quot;Avin&quot;
	set terrain[33] = &quot;Adrg&quot;
	set terrain[34] = &quot;Alvd&quot;
	set terrain[35] = &quot;Cdrt&quot;
	set terrain[36] = &quot;Cdrd&quot;
	set terrain[37] = &quot;Cpos&quot;
	set terrain[38] = &quot;Crck&quot;
	set terrain[39] = &quot;Cvin&quot;
	set terrain[40] = &quot;Cgrs&quot;
	set terrain[41] = &quot;Clvg&quot;
	set terrain[42] = &quot;Ndrt&quot;
	set terrain[43] = &quot;Ndrd&quot;
	set terrain[44] = &quot;Nrck&quot;
	set terrain[45] = &quot;Ngrs&quot;
	set terrain[46] = &quot;Nice&quot;
	set terrain[47] = &quot;Nsnw&quot;
	set terrain[48] = &quot;Nsnr&quot;
	set terrain[49] = &quot;Ydrt&quot;
	set terrain[50] = &quot;Ydtr&quot;
	set terrain[51] = &quot;Yblm&quot;
	set terrain[52] = &quot;Ybtl&quot;
	set terrain[53] = &quot;Ysqd&quot;
	set terrain[54] = &quot;Yrtl&quot;
	set terrain[55] = &quot;Ygsb&quot;
	set terrain[56] = &quot;Yhdg&quot;
	set terrain[57] = &quot;Ywmb&quot;
	set terrain[58] = &quot;Vdrt&quot;
	set terrain[59] = &quot;Vdrr&quot;
	set terrain[60] = &quot;Vcrp&quot;
	set terrain[61] = &quot;Vcbp&quot;
	set terrain[62] = &quot;Vstp&quot;
	set terrain[63] = &quot;Vgrs&quot;
	set terrain[64] = &quot;Vrck&quot;
	set terrain[65] = &quot;Vgrt&quot;
	set terrain[66] = &quot;Qdrt&quot;
	set terrain[67] = &quot;Qdrr&quot;
	set terrain[68] = &quot;Qcrp&quot;
	set terrain[69] = &quot;Qcbp&quot;
	set terrain[70] = &quot;Qstp&quot;
	set terrain[71] = &quot;Qgrs&quot;
	set terrain[72] = &quot;Qrck&quot;
	set terrain[73] = &quot;Qgrt&quot;
	set terrain[74] = &quot;Xdrt&quot;
	set terrain[75] = &quot;Xdtr&quot;
	set terrain[76] = &quot;Xblm&quot;
	set terrain[77] = &quot;Xbtl&quot;
	set terrain[78] = &quot;Xsqd&quot;
	set terrain[79] = &quot;Xrtl&quot;
	set terrain[80] = &quot;Xgsb&quot;
	set terrain[81] = &quot;Xhdg&quot;
	set terrain[82] = &quot;Xwmb&quot;
	set terrain[83] = &quot;Ddrt&quot;
	set terrain[84] = &quot;Dbrk&quot;
	set terrain[85] = &quot;Drds&quot;
	set terrain[86] = &quot;Dlvc&quot;
	set terrain[87] = &quot;Dlav&quot;
	set terrain[88] = &quot;Ddkr&quot;
	set terrain[89] = &quot;Dgrs&quot;
	set terrain[90] = &quot;Dsqd&quot;
	set terrain[91] = &quot;Gdrt&quot;
	set terrain[92] = &quot;Gbrk&quot;
	set terrain[93] = &quot;Grds&quot;
	set terrain[94] = &quot;Glvc&quot;
	set terrain[95] = &quot;Glav&quot;
	set terrain[96] = &quot;Gdkr&quot;
	set terrain[97] = &quot;Ggrs&quot;
	set terrain[98] = &quot;Gsqd&quot;
	set terrain[99] = &quot;Zdrt&quot;
	set terrain[100] = &quot;Zdtr&quot;
	set terrain[101] = &quot;Zdrg&quot;
	set terrain[102] = &quot;Zbks&quot;
	set terrain[103] = &quot;Zsan&quot;
	set terrain[104] = &quot;Zbkl&quot;
	set terrain[105] = &quot;Ztil&quot;
	set terrain[106] = &quot;Zgrs&quot;
	set terrain[107] = &quot;Zvin&quot;
	set terrain[108] = &quot;Idrt&quot;
	set terrain[109] = &quot;Idtr&quot;
	set terrain[110] = &quot;Idki&quot;
	set terrain[111] = &quot;Ibkb&quot;
	set terrain[112] = &quot;Irbk&quot;
	set terrain[113] = &quot;Itbk&quot;
	set terrain[114] = &quot;Iice&quot;
	set terrain[115] = &quot;Ibsq&quot;
	set terrain[116] = &quot;Isnw&quot;
	set terrain[117] = &quot;Odrt&quot;
	set terrain[118] = &quot;Odtr&quot;
	set terrain[119] = &quot;Osmb&quot;
	set terrain[120] = &quot;Ofst&quot;
	set terrain[121] = &quot;Olgb&quot;
	set terrain[122] = &quot;Orok&quot;
	set terrain[123] = &quot;Ofsl&quot;
	set terrain[124] = &quot;Oaby&quot;
	set terrain[125] = &quot;Kdrt&quot;
	set terrain[126] = &quot;Kfsl&quot;
	set terrain[127] = &quot;Kdtr&quot;
	set terrain[128] = &quot;Kfst&quot;
	set terrain[129] = &quot;Ksmb&quot;
	set terrain[130] = &quot;Klgb&quot;
	set terrain[131] = &quot;Ksqt&quot;
	set terrain[132] = &quot;Kdkt&quot;
	set terrain[133] = &quot;Jdrt&quot;
	set terrain[134] = &quot;Jdtr&quot;
	set terrain[135] = &quot;Jblm&quot;
	set terrain[136] = &quot;Jbtl&quot;
	set terrain[137] = &quot;Jsqd&quot;
	set terrain[138] = &quot;Jrtl&quot;
	set terrain[139] = &quot;Jgsb&quot;
	set terrain[140] = &quot;Jhdg&quot;
	set terrain[141] = &quot;Jwmb&quot;
	set terrain[142] = &quot;CAc2&quot;
	set terrain[143] = &quot;cAc1&quot;
	set terrain[144] = &quot;cBc2&quot;
	set terrain[145] = &quot;cBc1&quot;
	set terrain[146] = &quot;cKc1&quot;
	set terrain[147] = &quot;cKc2&quot;
	set terrain[148] = &quot;cYc2&quot;
	set terrain[149] = &quot;cYc1&quot;
	set terrain[150] = &quot;cXc2&quot;
	set terrain[151] = &quot;cXc1&quot;
	set terrain[152] = &quot;cJc2&quot;
	set terrain[153] = &quot;cJc1&quot;
	set terrain[154] = &quot;cDc2&quot;
	set terrain[155] = &quot;cDc1&quot;
	set terrain[156] = &quot;cCc2&quot;
	set terrain[157] = &quot;cCc1&quot;
	set terrain[158] = &quot;cIc2&quot;
	set terrain[159] = &quot;cIc1&quot;
	set terrain[160] = &quot;cFc2&quot;
	set terrain[161] = &quot;cFc1&quot;
	set terrain[162] = &quot;cLc2&quot;
	set terrain[163] = &quot;cLc1&quot;
	set terrain[164] = &quot;cWc2&quot;
	set terrain[165] = &quot;cWc1&quot;
	set terrain[166] = &quot;cNc2&quot;
	set terrain[167] = &quot;cNc1&quot;
	set terrain[168] = &quot;cOc1&quot;
	set terrain[169] = &quot;cOc2&quot;
	set terrain[170] = &quot;cZc2&quot;
	set terrain[171] = &quot;cZc1&quot;
	set terrain[172] = &quot;cGc2&quot;
	set terrain[173] = &quot;cGc1&quot;
	set terrain[174] = &quot;cVc2&quot;
	set terrain[175] = &quot;cVc1&quot;
	set terrain[176] = &quot;cQc2&quot;
	set terrain[177] = &quot;cQc1&quot;
endfunction

//===========================================================================
function InitTrig_SetTerrainVariables takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction( t, function actions )
endfunction

endscope

Here Is the actual trigger. I have fixed it up a bit, It now rejects Many things:
JASS:
scope ChangeTerrainVar

function CheckTerrainType takes string terraintype returns boolean
    local boolean b = false
    local integer i = 0
    loop
        exitwhen i &gt; 177
        if terraintype == terrain<i> then
            set b = true
        endif
        set i = i + 1
    endloop
    return b
endfunction

private function conditions takes nothing returns boolean
    if SubStringBJ(GetEventPlayerChatString(), 1, 9) != &quot;-terrain &quot; then
        return false
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;condition problems&quot; )
    endif
    if StringLength ( GetEventPlayerChatString() ) &gt; 13 then
        return false
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;condition problems&quot; )
    endif
    return true
endfunction

private function actions takes nothing returns nothing
    local string terrainrawname = SubString ( GetEventPlayerChatString(), 10, 13 )
    local integer rawint = S2I(&quot;&#039;&quot;+terrainrawname+&quot;&#039;&quot;)
    if CheckTerrainType ( terrainrawname ) then
        set terrainid[GetPlayerId ( GetTriggerPlayer() )] = rawint
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;Terrain type changed.&quot; )
    else
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;Not a valid terrain type.&quot; )
    endif   
endfunction

//===========================================================================
function InitTrig_ChangeTerrainVar takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local integer i = 0
    loop
        exitwhen i &gt; 8
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-&quot; + &quot;terrain&quot; + &quot; &quot;, false )
        set i = i + 1
    endloop
    call TriggerAddCondition ( t, Condition (function conditions) )
    call TriggerAddAction( t, function actions )
endfunction

endscope</i>

If you type in just '-terrain ' it says terrain was changed.
If you type in something like '-terrain Nice' It says it failed
?????????????
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
S2I("'Abcd'") is 0.
Actually, any string starting with ' turns to 0.
Abcd is not an integer anyway, and S2I is of no use here.

If you want to type in raw codes, either add a second array with those names as strings and find the corresponding value,
or write a StringID2Integer function...
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
JASS:
function Char2Id takes string c returns integer
    local integer i = 0
    local string abc = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;
    local string t

    loop
        set t = SubString(abc,i,i + 1)
        exitwhen t == null or t == c
        set i = i + 1
    endloop
    if i &lt; 10 then
        return i + 48
    elseif i &lt; 36 then
        return i + 65 - 10
    endif
    return i + 97 - 36
endfunction

function String2Id takes string s returns integer
    return ((Char2Id(SubString(s,0,1)) * 256 + Char2Id(SubString(s,1,2))) * 256 + Char2Id(SubString(s,2,3))) * 256 + Char2Id(SubString(s,3,4))
endfunction
 

mini.dude_22

New Member
Reaction score
1
wow, that doesn't make a ton of sense, but i think i see what its doing. I guess ill have to give it a try. Thanks =D

K just before i test, could you go over to see if it looks good, BTW i changed the terrain variables to integers

JASS:
scope ChangeTerrainVar

// STRING CONVERSION

function Char2Id takes string c returns integer
    local integer i = 0
    local string abc = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;
    local string t

    loop
        set t = SubString(abc,i,i + 1)
        exitwhen t == null or t == c
        set i = i + 1
    endloop
    if i &lt; 10 then
        return i + 48
    elseif i &lt; 36 then
        return i + 65 - 10
    endif
    return i + 97 - 36
endfunction

function String2Id takes string s returns integer
    return ((Char2Id(SubString(s,0,1)) * 256 + Char2Id(SubString(s,1,2))) * 256 + Char2Id(SubString(s,2,3))) * 256 + Char2Id(SubString(s,3,4))
endfunction

// STRING CONVERSION



// CHECK TYPE

function CheckTerrainType takes integer terraintype returns boolean
    local boolean b = false
    local integer i = 0
    loop
        exitwhen i &gt; 177
        if terraintype == terrain<i> then
            set b = true
        endif
        set i = i + 1
    endloop
    return b
endfunction

// CHECK TYPE



// CONDITIONS AND ACTIONS

private function conditions takes nothing returns boolean
    if SubStringBJ(GetEventPlayerChatString(), 1, 9) != &quot;-terrain &quot; then
        return false
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;condition problems&quot; )
    endif
    return true
endfunction

private function actions takes nothing returns nothing
    local string terrains = SubString ( GetEventPlayerChatString(), 10, 14 )
    local integer rawint = String2Id ( terrains )
    if CheckTerrainType ( rawint ) then
        set terrainid[GetPlayerId ( GetTriggerPlayer() )] = rawint
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;Terrain type changed.&quot; )
    else
        call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, &quot;Not a valid terrain type.&quot; )
    endif   
endfunction

// CONDITIONS AND ACTIONS




//??
function InitTrig_ChangeTerrainVar takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local integer i = 0
    loop
        exitwhen i &gt; 8
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-&quot; + &quot;terrain&quot; + &quot; &quot;, false )
        set i = i + 1
    endloop
    call TriggerAddCondition ( t, Condition (function conditions) )
    call TriggerAddAction( t, function actions )
endfunction

endscope</i>
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> set terrain[1] = "Ldrt"

If you edited that to
set terrain[1] = 'Ldrt'
You could compare them directly to String2Id(...)


And, well, it's probably not the best of ideas to try stuff out with terrain[0]... given that value isn't set to anything, chances are that'll crash and burn.


On a related note:

set b = false
loop
- if ... then set b = true
...
endloop
return b

could be:

loop
- if ... then return true
...
endloop
return false
 

mini.dude_22

New Member
Reaction score
1
Trigger Makes War 3 Crash - Help

Hi all im back again, This time, my trigger is causing warcraft 3 to crash, it says that it has something to do with the war3 memory in the error message it gives me. Here is the trigger, i know that all my variables work fine in the IF's but im not sure why its crashing can you see why?

JASS:
scope ChangeTerrainP1

private function actions takes nothing returns nothing
    local location l
    local real x
    local real y
    local integer u
    call TriggerSleepAction ( 0.001 )
    if &#039;T1x1&#039; == GetUnitTypeId ( GetTriggerUnit() ) then
        set u = 1
    else
        set u = 2
    endif
    set l = GetUnitRallyPoint ( GetTriggerUnit() )
    set x = GetLocationX ( l )
    set y = GetLocationY ( l )
    if IsPointInRegion( area[0], x, y ) then
        call SetTerrainType ( x, y, terrainid[0], -1, u, 1 )
    endif
    call RemoveLocation( l )
endfunction

//===========================================================================
function InitTrig_ChangeTerrainP1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterUnitEvent( t, gg_unit_T1x1_0010, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerRegisterUnitEvent( t, gg_unit_T3x3_0009, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( t, function actions )
endfunction

endscope
 

mini.dude_22

New Member
Reaction score
1
Hey, im not sure what you are saying, i have changed the line like you showed me, however warcraft 3 still crashes. This is what i have at the moment.

JASS:
scope ChangeTerrainP1

private function actions takes nothing returns nothing
    local location l = GetSpellTargetLoc()
    local real x
    local real y
    local integer u
    call TriggerSleepAction ( 0.001 )
    if &#039;T1x1&#039; == GetUnitTypeId ( GetTriggerUnit() ) then
        set u = 1
    else
        set u = 2
    endif
    set l = GetUnitRallyPoint ( GetTriggerUnit() )
    set x = GetLocationX ( l )  // I cant set this untill after the wait, because it wont work. 
//If i dont, it set the location to where the point was previousley. And i am not sure how to 
//inialize the location
    set y = GetLocationY ( l )
    if IsPointInRegion( area[0], x, y ) then
        call SetTerrainType ( x, y, terrainid[0], -1, u, 1 )
    endif
    call RemoveLocation( l )
endfunction

//===========================================================================
function InitTrig_ChangeTerrainP1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterUnitEvent( t, gg_unit_T1x1_0010, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerRegisterUnitEvent( t, gg_unit_T3x3_0009, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( t, function actions )
endfunction

endscope
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> I know that all my variables work fine

Well, if you posted that in the thread where that info is instead of here, people would be able to see that no, actually they aren't.
Unless you edited something since then, in which case you will have to repost that part anyway.
 

mini.dude_22

New Member
Reaction score
1
I don't know if this matters, but here is the error that i am getting.

War3Error.jpg


@ AceHart
K sorry :(
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top