Jump to content
CuddleTank001

Restricting action to when a character has a certain magazine in its inventory

Recommended Posts

1 minute ago, jshock said:

Where are you putting the addAction code? I recommend putting in the initPlayerLocal.sqf in your mission folder (if you don't have one already, make one).

its in an on player respawn, and i got respawn on start on

Share this post


Link to post
Share on other sites

update: when i add it via the debug console it works, but when its added by the first add action it doesn't

Share this post


Link to post
Share on other sites

The others have already explained it quite well, but once more with even more infos doesn't hurt.

 

 

In the first one, your string starts at the " and ends at the first "
So you have the string
"toLower (typeOf currentWeapon player) isEqualTo "

Then hgun_p07_f outside of any string.

And "" at the end.
Scripting language wise that would be a call to the "hgun_p07_f" command, with two strings as arguments.

Just like you would do

"string1" command "string2"

You are doing

"toLower (typeOf currentWeapon player) isEqualTo " hgun_p07_f ""

But the command "hgun_p07_f" obviously doesn't exist, which will end up in a error.

 

In the second case, the string still starts at " and ends at the first "

So you end up with

"toLower (typeOf currentWeapon player) isEqualTo 'hgun_p07_f'"

All is fine.

 

No matter if you start the string with " or ' it will continue till it encounters the first quote of same type. Then checks whether you have two quotes together like "" or '' and if that's the case it will see that and detect that you are trying to just have a quote inside your string, that's called "escaping" in other programming languages that is usually done with a \.

 

9 hours ago, CuddleTank001 said:

i tried this script in multiplayer and it didn't work

What part didn't work? The action didn't show up? Do your other actions show up? Or did the action show up but the code didn't execute when you used the action?

 

9 hours ago, CuddleTank001 said:

'currentWeapon player == "hgun_P07_snds_F"'

That is not the correct classname. That is the classname of a weapon template it consists of the weapon "hgun_P07_F" with a pre-attached silencer "muzzle_snds_L". If you put that into your inventory, you will have a "hgun_P07_F" in your inventory, and not a "hgun_P07_snds_F"

Share this post


Link to post
Share on other sites

I don’t understand, is the problem in the addaction itself, or the foption section as a whole?

 

Share this post


Link to post
Share on other sites
4 hours ago, Dedmen said:
14 hours ago, CuddleTank001 said:

i tried this script in multiplayer and it didn't work

What part didn't work? The action didn't show up? Do your other actions show up? Or did the action show up but the code didn't execute when you used the action?

 

The problem is that we don't know what the problem is unless you are more specific as to what doesn't work. The actions are not showing up at all; the actions are present but do nothing; these specific actions work without issue but these others do not; etc.

 

Getting things to work through the use of the debug console doesn't necessary mean anything since you can execute that code in whatever way is needed. Did you execute globally or locally? Did you only do the one action that we've been using in this thread consistently? Did you just copy and paste the entire onPlayerRespawn.sqf in there and click execute?

 

This is all critical information on what we need to help. When we don't have specifics we tend to make grandiose assumptions as to where, how and why certain stuff is executed (based on our experiences). While I'm sure we can make an educated guess as to what could be happening, the fact is that is that is wildly inefficient and just keeps all of us moving in circles. And for some of us, myself included, we have other projects, work, college, etc. that keep us from dedicating a lot of time to walking people step-by-step through the debugging process for every single hiccup. I love to help (obviously) but help us help you. Because I'm sure if we came in here just to post "Oh, well I couldn't get your code to work either, sucks to suck 😢" it wouldn't be of much help.

 

Sorry if that comes off as harsh but to put it simply; give us specifics for every issue you encounter (the who, what, when, where, why, and how).

  • Like 2

Share this post


Link to post
Share on other sites

The OnPlayerRespawn is in the mission file.

All the actions work perfectly but the ones restricted to the po7 (repair target, delete, destroy, spawn vehicles) the working actions are (repair, eng, rear rotor, earplugs, and soption section).

 

The faulty actions do not show up at all, no matter what gun i have out they wont show up.

Share this post


Link to post
Share on other sites

Nvm its working, it was the weapon class, im sorry for unnecessarily holding you guys.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×