| 03-21-2004, 06:41 AM | #1 |
This is my 1st AI script. Why this AI script does NOT work? I want it to apply to a 3C game, but whatever I test, computer hero don;t learn skill when he is level up. Why? Pls Help me to test and fix the AI. Thank The AI scirpt is: Code:
//==================================================
// Hero Learn skill on level up AI
// -- by: GreedWind ver: 0.1 beta1
//==================================================
//==================================================
// Int2Str -- integer to string
// --by AIAndy
// I2S() DOESN'T run porperly in AI scirpt,
//==================================================
function Dig2Str takes integer i returns string
if i == 1 then
return "1"
elseif i == 2 then
return "2"
elseif i == 3 then
return "3"
elseif i == 4 then
return "4"
elseif i == 5 then
return "5"
elseif i == 6 then
return "6"
elseif i == 7 then
return "7"
elseif i == 8 then
return "8"
elseif i == 9 then
return "9"
else
return "0"
endif
endfunction
function Int2Str takes integer ic returns string
local string s = ""
local integer i = ic
local integer ialt = 0
local boolean neg = false
if i == 0 then
return "0"
endif
if i < 0 then
set neg = true
set i = (-1)*i
endif
loop
exitwhen i == 0
set ialt = i
set i = i / 10
set s = Dig2Str( ialt - 10*i ) + s
endloop
if neg then
set s = "-"+s
endif
return s
endfunction
//==================================================
//Returns the the position where the first occourence of
//'find' appears in 'subject' starting the search from 'offset'.
//Returns -1 if 'find' wasn't found.
//This function is case-sensitive,
//for a case-insensitive version see: StringIFind.
//Example:
// StringFind("ass", "The Jass Vault", 1) == 6
// StringFind("a", "The Jass Vault", 8) == 11
// Returns -1 if find was not found anywhere
//==================================================
function StringFind takes string find, string subject, integer offset returns integer
local integer len = StringLength(find)
local integer pos = offset
local string s
local string str
if ( offset < 1 ) then
set pos = 1
endif
if ( find == "" ) then
return -1
endif
loop
set s = SubString(subject, pos-1, pos+len-1)
if ( s == find ) then
return pos
endif
if ( SubString(subject, pos-1, pos) == "" ) then
return -1
endif
set pos = pos + 1
endloop
return -1
endfunction
function LearnSkillAI takes nothing returns integer
local integer level = GetHeroLevelAI()
local string array learn_sequence
local integer numofskill = 4
local integer array skills
local integer i = 1
local integer learnskill
//trace msg
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 3600, "Add skill")
//Hero: Demon Hunter
if GetHeroId() == 'Edem' or Player(GetAiPlayer())== 'Edmm' then
set skills[1] = 'AEev' //Demon Hunter - Evasion
set skills[2] = 'AEim' //Demon Hunter - Immolation
set skills[3] = 'AEmb' //Demon Hunter - Mana Burn
set skills[4] = 'AEme' //Demon Hunter - Metamorphosis
//learn_sequence contain string "^12^" make hero learn that skill
//when hero is level 12
//major skill level interval: 6 11 16 21 26
set learn_sequence[1] = "^1^3^5^7^9^12^13^15^17^19^"
set learn_sequence[2] = "^2^4^8^10^14^18^20^22^23^24^"
set learn_sequence[3] = "^25^27^28^29^30^31^32^33^34^35^"
set learn_sequence[4] = "^6^11^16^21^26^"
endif
//Hero: BLADEMASTER
if GetHeroId() == 'Obla' then
set skills[1] = 'AOcr' //Blade Master - Critical Strike
set skills[2] = 'AOmi' //Blade Master - Mirror Image
set skills[3] = 'AOwk' //Blade Master - Wind Walk
set skills[4] = 'AOww' //Blade Master - Bladestorm
set learn_sequence[1] = "^1^3^5^7^9^12^13^15^17^19^"
set learn_sequence[2] = "^4^8^10^14^18^20^22^23^24^25^"
set learn_sequence[3] = "^2^27^28^29^30^31^32^33^34^35^"
set learn_sequence[4] = "^6^11^16^21^26^"
endif
//
// Add more code below for other hero.
//
loop
exitwhen i > numofskill
if StringFind(learn_sequence[i] , "^" + Int2Str(level) + "^", 1) != -1 then
//trace msg
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 3600, "Skill Learned!!!")
return skill[i]
endif
set i = i + 1
endloop
endfunction
//==================================================
// main
//==================================================
function main takes nothing returns nothing
//call InitAI()
//call SetHeroLevels(function LearnSkillAI)
call StandardAI(function LearnSkillAI, null, null)
call SleepForever()
endfunctionCode:
//=================================================
//Run Custom AI in Trigger(NOT AI)
//Call in MAP INIT event: Custom Scirpt: Call StartMyAI("learnskill.ai")
//=================================================
function StartMyAI takes string ai_name returns nothing
local integer index
local player indexPlayer
local race indexRace
set index = 0
loop
set indexPlayer = Player(index)
if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
set indexRace = GetPlayerRace(indexPlayer)
if (GetPlayerController(indexPlayer) == MAP_CONTROL_COMPUTER) then
// Run a coustom AI script.
call PickMeleeAI(indexPlayer, ai_name, null, null)
//call ShareEverythingWithTeamAI(indexPlayer)
endif
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
endfunction |
| 03-22-2004, 02:38 PM | #2 |
Pls help, guide me how to use AI script in a game |
| 03-22-2004, 08:24 PM | #3 |
If you want to be helped plz remove those PHP tags and replace them by code tags. That syntax coloring is unreadable. For testing, have you put in some debug messages to see if the script is running ? |
| 03-24-2004, 10:42 AM | #4 |
I remove the PHP code already. I already put debug code in it. but on my testing, no any trace message output to screen. It seem the AI did not run or terminate in somewhere. Thx for your help |
| 03-24-2004, 11:51 AM | #5 |
Well, if no debug messages are printed, there is likely a syntax error in the script. Use PJASS ( http://amai.wc3campaigns.com/pjass.zip ). Unfortunately your code has a problem anyway. SubString is a common.j native that returns a string and those do not work in AI (because it returns an entry number in the string table of the trigger context and since the AI has a separate string table it is meaningless there). I have thought a bit on how to overcome that problem and a possible solution would be: go through a list of known single character strings and run SubString on it. Store the result using the return bug in an array of strings like that: you run SubString on "A", then convert the result in an integer x with the return bug and then store my_char_array[x] = "A". Once you have done that for all characters you need, you then have an array that can translate you single character returns of SubString into an actual string in AI. Note though that I have not tested this yet. A possible problem is that x gets too high so you cannot use an array there. In that case the gamecache needs to be used there to translate from a high integer to a low one. A different possibility would be hashing. |
| 03-24-2004, 12:09 PM | #6 |
oh, I should know that native functions that return string not fuction correctly when used in AI scripts. I will change my code. |
