OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Blanco on 13 Jan 2004, 18:59:22
-
_unit = _this select 0
_handguns = ["Glock","Revolver","Beretta","Skorpion","UZI"]
_c = count _handguns
_i = 0
#start
_gun = _handguns select _i
?_unit hasweapon _gun : goto "yes"
_i = _i + 1
?_i <_c : goto "start"
#yes
hint format ["The player has a %1",_gun]
exit
This script should check if the player got one of the handguns in the _handguns array, but it doesn't work, nothing happens even when I'm sure he got one of them.
I also tried :
?_gun in weapons player : goto "yes"
Doesn't work either.
I know I can do the same with :
Player hasweapon "Glock" OR Player hasweapon "UZI" OR... etc
But is it possible in a script because I don't want to rewrite the line above each time the _handguns array changes.
Please Help
-
What about:
Player hasweapon _revolver or Player hasweapon _glock etc.
Will allow you to change without an array.
:beat: *Gets Blasted* :beat:
-
What about... the script does work!
I copied and pasted it and it works fine. Calling it with
[unitname]exec "handgun.sqs" (or whatever name youve called the script).
It seems there are gliches though. Even when I drop the gun it still says I have a gun. And when I have a skorpion, it says I have an UZI.
-
:o really?,
I can't test it here, but I will when I'm back home.
I tried it with a unarmed civilian and I picked up a glock from a fallen soldier and there was no respons from the script...
Thx, for testing it.
It was late (or early), maybe I've made a mistake during my tests... :beat:
***edit***
It seems there are gliches though. Even when I drop the gun it still says I have a gun
That's normal because the script exits after the hint.
And when I have a skorpion, it says I have an UZI.
That's not normal... :P
-
What I mean by after I drop the gun, is I drop teh gun, and run the script again and it still says I have the gun.
Also if you make a west heavy genadier, it says he has an uzi, when he doesnt. It seems to happen often where hte unit doesnt have a handgun and it incorrectly reports him having an uzi. Also only some skorpions are reported as UZIs. For example the civillian police are reported as carrying uzis, but a Spetznatz (handgun) is reported correctly as having a skorpion.
-
What I mean by after I drop the gun, is I drop teh gun, and run the script again and it still says I have the gun
Yes, that's normal ;)
When you run the script after _unit has dropped his _gun, The loop starts and when _gun is NOT in the _handguns array the loop continues until _i <_c.
Then we've got that hint format line after the loop, so I think it's normal, it returns the _gun you had before you dropped it. When you place an exit after the loop it won't happen.
or something like this :
_unit = _this select 0
_handguns = ["Glock","Revolver","Beretta","Skorpion","UZI"]
_c = count _handguns
_i = 0
#start
_gun = _handguns select _i
?_unit hasweapon _gun : goto "yes"
_i = _i + 1
?_i <_c : goto "start"
;;;don't know this works...
_gun = objnull
#yes
hint format ["The player has a %1",_gun]
exit
But it doesn't solve the other problem(s)
-
The problem with this script is that after the loop has finished (ie looped 5 times), _gun = "UZI".
The script then continues past ?_i <_c : goto "start" and goes onto the #yes section. So Even if the unit has no gun, the script will always return hint "The player has a UZI" at the end.
You need to exit the script after the last loop like so:
_unit = _this select 0
_handguns = ["Glock","Revolver","Beretta","Skorpion","UZI"]
_c = count _handguns
_i = 0
#start
_gun = _handguns select _i
?_unit hasweapon _gun : goto "yes"
_i = _i + 1
?_i <_c : goto "start"
exit
#yes
hint format ["The player has a %1",_gun]
exit
Btw, the "UZI" is not a handgun - that is the primary weapon slot version. The handgun Uzi is "Ingram".