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:
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 < 15 then
if SubString ( s, 1, 9 ) == "-terrain " then
if SubString ( s, 10, 10 ) == "039;" then
if SubString ( s, 15, 15 ) == "039;" then
set b = true
else
call BJDebugMsg ( "Missing the second 039;" )
endif
else
call BJDebugMsg ( "Missing the first 039;" )
endif
else
call BJDebugMsg ( "Missing -terrain." )
// This fails, if you have just '-terrain' it works, but does not say that i am
// missing either of the ', if i type it in like '-terrain ' it says that terrain failed
// i cant test either of the ', because i cant get past '-terrain ' the space is
// failing even "-terrain '" with one of the ' says that it still is missing
// the '-terrain'
endif
else
call BJDebugMsg ( "String is too long." ) // 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, "Terrain type changed." )
else
call DisplayTextToPlayer ( Player (GetPlayerId ( GetTriggerPlayer() ) ), 0, 0, "Not a valid terrain type, check your quest for all the valid ones. -3" )
endif
endfunction
//===========================================================================
function InitTrig_ChangeTerrainVar takes nothing returns nothing
local trigger t = CreateTrigger( )
set i = 0
loop
exitwhen i > 8
call TriggerRegisterPlayerChatEvent( t, Player(i), "-" + "terrain" + " " + "", false )
set i = i + 1
endloop
call TriggerAddCondition ( t, Condition (function conditions) )
call TriggerAddAction( t, function actions )
endfunction
endscope