
killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 22, 2015 10:14 PM
Msg. 1 of 14
hey guys im having problems getting this script to work, can anyone help me fixing it? im not all that great at scripting.
(script continuous void load (begin (if (and (volume_test_object orange_pickup ep1) (unit_get_current_flashlight_state ep1) (= flashlight1 false)) (begin (if (and (volume_test_object orange_pickup w1) (!= (vehicle_test_seat_list w1 (players)) true) (= cargoa none)) (set cargoa hog0)) (if (and (volume_test_object orange_pickup w1) (!= (vehicle_test_seat_list w1 (players)) true) (= cargoa none)) (set cargoa w1))
(script continuous void hold (begin (if (and flashlight1 (!= cargoa none))) (begin (objects_attach ep1 cargo cargoa ) (objects_detach ep1 cargoa)) (if (and flashlight2 (!= cargob none)) (begin (objects_attach ep1 cargo cargob ) (objects_detach ep1 cargob)))))
(script continuous void unload (begin ---> (if (and flashlight1 (= (unit_get_current_flashlight_state ep1) false)) (begin (if (= cargoa w1) (begin (object_create_anew w1) (objects_attach ep1 cargo w1 ) (objects_detach ep1 w1))))
the arrow is where it gives me problems, it says its unmatched and i cant figure out where i need to close it. any help? its for a pelican pickup and drop of vehicles
|
|
|

FtDSpartn
Joined: May 1, 2009
Verified AI.
|
Posted: Jan 22, 2015 11:52 PM
Msg. 2 of 14
Looks like you're missing ~3 closing parenthesis; try this: (script continuous void unload (begin (if (and flashlight1 (= (unit_get_current_flashlight_state ep1) false)) (begin (if (= cargoa w1) (begin (object_create_anew w1) (objects_attach ep1 cargo w1 ) (objects_detach ep1 w1)))))))
Also, those begins are unnecessary in this case. Edited by FtDSpartn on Jan 22, 2015 at 11:53 PM
|
|
|

teh lag
Joined: May 6, 2008
|
Posted: Jan 23, 2015 12:45 AM
Msg. 3 of 14
1) As stated above, you don't need to use all of those (begin) expressions. They're only needed when you're wrapping multiple sequential operations into a single expression. Generally, this is only necessary when you're defining the actions resulting from an (if) or a (cond), though sometimes it can be useful in other places if you're getting fancy with evaluating values. You definitely don't need to wrap every script's body in a (begin). 2) You should get in the habit of formatting your scripts! It will make them easier to read and problems will be easier to find. Notepad++ is a fine editor for this purpose, and there are a few HSC language syntax definitions floating around for it. Placing multiple close-parentheses on the same line when their expressions are on different lines is very ugly :( 3) Not immediately related, but you don't need to test boolean expressions' equality with true / false - they just evaluate to true / false anyway. You can negate a boolean with (not) instead of that (!= <expr> true) thing. The problem is basically that you have some missing close-parentheses that are confusing the compiler. I think you're also using the (objects_attach) function wrong - it takes 4 parameters, not 3 - but maybe the compiler is smart enough to fill in an empty string for the 4th argument. A lot of the logic here is kind of odd and I'm assuming that there are other things (globals etc) that have been omitted, so I am not 100% sure what is supposed to be happening. But, I think that something along these lines is probably what you want. Update: also get rid of the "void" declarations after "script continuous". Continuous (and dormant and startup) scripts do not have return types. (script continuous load (if (and (volume_test_object orange_pickup ep1) (unit_get_current_flashlight_state ep1) (not flashlight1) ) (begin (if (and ;; should w1 be replaced with hog0 in these conditions? ;; not sure why the same exact check is repeated below, ;; but the resulting cargoa object is different... (volume_test_object orange_pickup w1) (not (vehicle_test_seat_list w1 (players))) (= cargoa none) ) (set cargoa hog0) ) (if (and (volume_test_object orange_pickup w1) (not (vehicle_test_seat_list w1 (players))) (= cargoa none) ) (set cargoa w1) ) ) ) )
(script continuous hold (if (and flashlight1 (!= cargoa none) ) (begin (objects_attach ep1 "cargo" cargoa "") (objects_detach ep1 cargoa) ) ) (if (and ;; should this section be operating on a second pelican object? ;; otherwise I'm not seeing why we would want a second flashlight ;; test + cargo object for ep1... flashlight2 (!= cargob none) ) (begin (objects_attach ep1 "cargo" cargob "") (objects_detach ep1 cargob) ) ) )
(script continuous unload (if (and flashlight1 (not (unit_get_current_flashlight_state ep1)) ) (begin (if (= cargoa w1) (begin (object_create_anew w1) (objects_attach ep1 "cargo" w1 "") (objects_detach ep1 w1) ) ) ;; presumably more actions go here? otherwise you can just take ;; the second (if) condition and add it to the outer (if)'s (and). ) ) )
Edited by teh lag on Jan 23, 2015 at 07:36 PMEdited by teh lag on Jan 23, 2015 at 07:40 PM
|
|
|

killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 23, 2015 06:48 PM
Msg. 4 of 14
Yeah its a script i extracted from Coldsnap for the pelican vehicle pickup i wanted to use for my maps, i think its a cool idea for maps
and i tried your script just now, it said the first parenthesis "left parenthesis is unmatched (script continuous load" Edited by killerbear82 on Jan 23, 2015 at 06:52 PM
|
|
|

teh lag
Joined: May 6, 2008
|
Posted: Jan 23, 2015 07:54 PM
Msg. 5 of 14
Also get rid of the "void" declarations after "script continuous". Continuous (and dormant and startup) scripts do not have return types. I missed that.
The compiler will pretty much always say that a parenthese is unmatched if you have a syntax error, even if your parentheses actually line up. Usually you'll want to look at the error message printed out above that (if there is one), unless it turns out that you really are missing a parenthese somewhere.
I also should note at this point that (in case you weren't just omitting them in your original post) that you will need to declare globals for cargoa, cargob, flashlight1... etc. You'll also need the scripts that update the pelican flashlight globals.
|
|
|

killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 23, 2015 09:40 PM
Msg. 6 of 14
alright well it was the script i got from coldsnap i copied parts out of i may have messed up anyways. lets do something else.
Say i have an encounter for Ai that will be on my team for multiplayer for red team, the encounter name would be spartans, and they are selected as not initially created, how would i make it so i can use a trigger volume to spawn them?
|
|
|

FtDSpartn
Joined: May 1, 2009
Verified AI.
|
Posted: Jan 24, 2015 12:20 AM
Msg. 7 of 14
Pretty simple: (script startup spawnSpartans (sleep_until (volume_test_objects trigvol (unit (list_get (players) 0))) 15) (ai_place spartans) )
Just replace 'trigvol' with the name of your trigger volume, and 'spawnSpartans' with your own script name if you wish. Explanation: The sleep_until is self-explanatory; it sleeps until the specified condition (player in trigger) is true, and then continues. The next part just checks the named trig volume for an object specified. Unit tells the game that we're getting a unit, and list_get is getting the player list/array and looking for the first element (arrays are zero-based and so they start at 0). The fifteen at the end is how much time passes (in ticks; 1 second = 30 ticks) before the game checks if the condition is true. This means that this specific script would check every half-second to see if the player is standing in the trigger volume. Basically, this checks the named trigger to see if player 0 is in it every half-second, and if so, continues the script, spawning the encounter named 'spartans'. Edited by FtDSpartn on Jan 24, 2015 at 12:26 AM
|
|
|

killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 24, 2015 09:41 AM
Msg. 8 of 14
this helps so much man, ive been trying to figure that out ever since i started adding ai to maps. thanks a lot man, i appreciate it
one last thing before im done with this thread. what is the script to make the AI exit your vehicle when you press a button like flashlight? as for every time you press it that if you have ai on board they will get out every time? Edited by killerbear82 on Jan 24, 2015 at 10:00 AM
|
|
|

FtDSpartn
Joined: May 1, 2009
Verified AI.
|
Posted: Jan 24, 2015 11:07 AM
Msg. 9 of 14
This should work, but I haven't done this before. Copied from Gamma927's script: (script continuous exit_vehicle (if (and (= (unit_get_current_flashlight_state (unit (list_get (players) 0))) true) (vehicle_test_seat vehicle_name "" (unit (list_get (players) 0))) ) (vehicle_unload vehicle_name "") (unit_enter_vehicle (unit (list_get (players) 0)) vehicle_name "") (unit_set_desired_flashlight_state (unit (list_get (players) 0)) false) ) ) Just replace 'vehicle_name' with the name of your vehicle. Explanation (to my understanding): The script continuously runs in the background. If the player's flashlight is on and they're in the named vehicle (unit_get_current_flashlight_state and vehicle_test_seat), the script continues and it unloads all units in the vehicle. The player is instantly loaded back in (unit_enter_vehicle) and the flashlight is turned off (unit_set_desired_flashlight_state). (= (unit_get_current_flashlight_state (unit (list_get (players) 0))) true) Basically, checks if the unit's flashlight is on, and returns true if it is (in this case, checks the player's). (vehicle_test_seat vehicle_name "" (unit (list_get (players) 0))) Tests the named vehicle for the specified unit (in this case, the player) in any seat ("" means any seat) and returns true if the unit is in the vehicle. (vehicle_unload vehicle_name "") Unloads the vehicle of any unit in the named seat ("" is any seat, so it unloads the whole vehicle of any units). (unit_enter_vehicle (unit (list_get (players) 0)) vehicle_name "") Puts the specified unit into the named vehicle and seat (in this case, the player into any seat). (unit_set_desired_flashlight_state (unit (list_get (players) 0)) false) Sets the unit's flashlight to off (in this case, the player's). Edited by FtDSpartn on Jan 24, 2015 at 11:09 AM
|
|
|

killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 25, 2015 09:56 AM
Msg. 10 of 14
its giving me problems about the first if command
|
|
|

FtDSpartn
Joined: May 1, 2009
Verified AI.
|
Posted: Jan 25, 2015 10:18 AM
Msg. 11 of 14
(script continuous exit_vehicle (if (and (= (unit_get_current_flashlight_state (unit (list_get (players) 0))) true) (= (vehicle_test_seat vehicle_name "" (unit (list_get (players) 0))) true) ) (vehicle_unload vehicle_name "") (unit_enter_vehicle (unit (list_get (players) 0)) vehicle_name "") (unit_set_desired_flashlight_state (unit (list_get (players) 0)) false) ) )
Hmm, try this one; I'm no pro scripter so if this doesn't work I'll go in-game and try some other things out. I added a check to see if the vehicle_test_seat check came back true. Edited by FtDSpartn on Jan 25, 2015 at 10:18 AM
|
|
|

killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 25, 2015 12:44 PM
Msg. 12 of 14
still isnt working :/
|
|
|

FtDSpartn
Joined: May 1, 2009
Verified AI.
|
Posted: Jan 25, 2015 01:04 PM
Msg. 13 of 14
I'll leave you with one more while I try it myself. (script continuous exit_vehicle (begin (if (and (= (unit_get_current_flashlight_state (unit (list_get (players) 0))) true) (vehicle_test_seat vehicle_name "" (unit (list_get (players) 0))) ) (begin (vehicle_unload vehicle_name "") (unit_enter_vehicle (unit (list_get (players) 0)) vehicle_name "") (unit_set_desired_flashlight_state (unit (list_get (players) 0)) false) ) ) ) ) What error is it giving you? Unmatched parenthesis?
|
|
|

killerbear82
Joined: Jan 22, 2015
|
Posted: Jan 31, 2015 07:14 PM
Msg. 14 of 14
no, now it says "i expected a string, but this function returns a unit (unit (list_get (players) Edited by killerbear82 on Jan 31, 2015 at 07:16 PM
|
|
|