snkman 351 Posted May 10, 2007 Well i try to write a script with a Array but i can't get it to work... May someone can explain me what i'm doing wrong... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _west = _this select 0 _east_ = this select 1 _west = [w1,w2,w3] _east = [e1,e2,e3] #loop If ((_east distance _west) < 20) then {_east say "rus01"} If ((_west distance _east) < 20) then {_west say "us01"} ~10 goto "loop" But it doesn't work's... Share this post Link to post Share on other sites
baddo 0 Posted May 10, 2007 That script is definitely not written correctly... First mistake: you are assigning values to _west and _east two times for each in the start of the script. I don't know what you pass for the script but it is gone pretty quickly. Second mistake: you try to compare the distance of the _west and _east arrays. That won't work. You must compare the distance of individual objects (soldiers). Third mistake: you are trying to make the arrays _west and _east say something. That won't work. You must make an individual unit say something. I think the thing that you have missed here is how to pick stuff from an array. Let me give you a short example: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _west = [w1, w2, w3] (_west select 0) say "us01" (_west select 1) say "us01" (_west select 2) say "us01" This piece of code will make first w1 say "us01" and then w2 and w3 do the same thing. First item in an array is selected with 0. So with select you use an index number of 0...n-1 where n is the number of items in the array. Share this post Link to post Share on other sites
tj72 0 Posted May 10, 2007 note the typo as well.... _west = _this select 0 _east_ = this select 1 first uses _this second uses this and the _ is before the = _this is the correct way to get those array points in a script. its the local variable type and westgroup would be a global but nevermind that for now. If you have your groups named like westgroup = group this in leaders init and if a trigger has: [westgroup,eastgroup] exec "checkdist.sqs" in activation field..... the script will have: _westgroup = _this select 0 _eastgroup = _this select 1 to use to check the distance between the two. You may need to get the group leader for the check though.... if thats the case you can define (leader _westgroup) or _west_leader = leader _westgroup same for east..... and use those for the check. ...Ooops your checking units so just do leader if you want to do the same thing for groups Share this post Link to post Share on other sites
snkman 351 Posted May 14, 2007 Thank's a lot Guy's i think i finally understood how _this select 0,1,2 works. Well but now again i have another problem i can't figure out how to get this... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; ; This is a part of the Group Link II script. ; ; /KeyCat ; ; ---------------------------------------------------------------------------- ; Get current group _group = _this select 0 _tg = _this select 1 ; 50 % chance to get a voice comment from the enemy group ;? (random 100 < 50) : exit ; Randomly select voice comment to play at clients KEY_VoiceNumber = random 44 KEY_VoiceNumber = KEY_VoiceNumber - KEY_VoiceNumber % 1 ; ########### DEBUG ########### hint format["DEBUG: Voice Alert Groups # %1",KEY_VoiceNumber] ; ############################# ; Assign current group to global variable KEY_VoiceGroup = _group ; broadcast current group to all clients publicVariable "KEY_VoiceGroup" ; broadcast voice number to all clients publicVariable "KEY_VoiceNumber" ; wait until all received it ~1 ; Set global variable KEY_VoiceAlert true KEY_VoiceAlert = True ; broadcast it to all clients (plays voice alert on clients) publicVariable "KEY_VoiceAlert" ~1 ; Set variable to false KEY_VoiceAlert = False exit Okay at the beginning i have the 2 Groups _group = _this select 0 _tg = _this select 1 But there's only one Group assignd to the global variable: KEY_VoiceGroup = _group How can i get bouth groups in there? I tryed: KEY_VoiceGroup = (_group) + (_tg), KEY_VoiceGroup = [(_group) + (_tg)], KEY_VoiceGroup = [_group] + [_tg] But it all doesn't work... Share this post Link to post Share on other sites
baddo 0 Posted May 14, 2007 An enemy group is supposed to say something when they encounter the player's group. The player's group is just supposed to hear what the other group says. So I would say, the logic here is not correct as you are trying to make the target group also say something when they shouldn't. Do you want to change this logic somehow? This comment from the top of my head without looking at the original OFP Group Link II scripts. If you want different logic than how it is in OFP GL II then there is not much I can say to this (too little information from your side). Share this post Link to post Share on other sites
snkman 351 Posted May 14, 2007 Okay some more informations abou this: In grouplink2.sqs i call this script with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((KEY_AIvoicealert) && ((count (units _nh)) >= 1)) then {[_nh,_tg] exec "ai\ai_voice\ai_voice2.sqs"} ai_voice2.sqs<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; ; This is a part of the Group Link II script. ; ; /KeyCat ; ; ---------------------------------------------------------------------------- ; Get current group _group = _this select 0 _tg = _this select 1 ; 50 % chance to get a voice comment from the enemy group ;? (random 100 < 50) : exit ; Randomly select voice comment to play at clients KEY_VoiceNumber = random 3 KEY_VoiceNumber = KEY_VoiceNumber - KEY_VoiceNumber % 1 ; ########### DEBUG ########### hint format["DEBUG: Voice Alert Groups # %1",KEY_VoiceNumber] ; ############################# ; Assign current group to global variable KEY_VoiceGroup = _group ; broadcast current group to all clients publicVariable "KEY_VoiceGroup" ; broadcast voice number to all clients publicVariable "KEY_VoiceNumber" ; wait until all received it ~1 ; Set global variable KEY_VoiceAlert true KEY_VoiceAlert = True ; broadcast it to all clients (plays voice alert on clients) publicVariable "KEY_VoiceAlert" ~1 ; Set variable to false KEY_VoiceAlert = False exit So now on the map i have a trigger with: On Condition: KEY_VoiceAler On Activate: [KEY_VoiceGroup,KEY_VoiceNumber] exec "ai\ai_voice\ai_voice3.sqs" ai_voice3.sqs <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _group = _this select 0 _voicenumber = _this select 1 _tg = _this select 2 hint "ALERT" ; Arrays with all voices _comments = ["Brian_Get_out_here","Brian_Fire_in_the_hole","Brian_Run"] ; Let the Units of the group say the comment (units _group select 1) say (_comments select _voicenumber) (units _tg select 1) say (_comments select _voicenumber) ; Set variable to false KEY_VoiceAlert = false exit Well that's it Share this post Link to post Share on other sites