Home   Help Search Login Register  

Author Topic: Script doesn't work. (hasweapon prob)  (Read 730 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
Script doesn't work. (hasweapon prob)
« on: 13 Jan 2004, 18:59:22 »
Code: [Select]
_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 :

Code: [Select]
?_gun in weapons player : goto "yes"

Doesn't work either.

I know I can do the same with :
Code: [Select]
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






Search or search or search before you ask.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Script doesn't work. (hasweapon prob)
« Reply #1 on: 13 Jan 2004, 19:05:28 »
What about:

Player hasweapon _revolver or Player hasweapon _glock etc.

Will allow you to change without an array.

:beat: *Gets Blasted* :beat:

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:Script doesn't work. (hasweapon prob)
« Reply #2 on: 13 Jan 2004, 19:10:40 »
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.
« Last Edit: 13 Jan 2004, 19:16:50 by [icarus_uk] »

Offline Blanco

  • Former Staff
  • ****
Re:Script doesn't work. (hasweapon prob)
« Reply #3 on: 13 Jan 2004, 19:20:09 »
 :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***
Quote
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.

Quote
And when I have a skorpion, it says I have an UZI.

That's not normal... :P
« Last Edit: 13 Jan 2004, 19:23:14 by Blanco »
Search or search or search before you ask.

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:Script doesn't work. (hasweapon prob)
« Reply #4 on: 13 Jan 2004, 19:28:21 »
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.

Offline Blanco

  • Former Staff
  • ****
Re:Script doesn't work. (hasweapon prob)
« Reply #5 on: 13 Jan 2004, 20:23:05 »
Quote
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 :

Quote
_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)



 
« Last Edit: 13 Jan 2004, 20:44:50 by Blanco »
Search or search or search before you ask.

Offline Welshmanizer

  • Members
  • *
Re:Script doesn't work. (hasweapon prob)
« Reply #6 on: 13 Jan 2004, 21:08:44 »
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:


Code: [Select]
_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".


« Last Edit: 13 Jan 2004, 21:16:40 by Welshmanizer »