Jump to content
Sign in to follow this  
dachevs

Inventory

Recommended Posts

Is there a way check a players inventory through a script?

I'm trying to create a mission where a script checks if a player has a certain object but I can't get it to work.

This is what I have so far, Can anyone help ? huh.gif

object init

Quote[/b] ] this addaction ["Buy Skoda", "Buy.sqf"]

Buy.sqf

Quote[/b] ]_player = _this select 0;

_action = _this select 2;

if ("RPO_obj17" in magazines _player) then

{

if (removemagazine _player == 1) exitwith

{

hint "You bought a car for $100.";

};

Share this post


Link to post
Share on other sites

if you combine

weapons player and magazines player you will get the inventory.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (("Something" in weapons player) || ("Something" in magazines player)) then

{

hint "i got the object";

}else{

hint "no i missing it";

};

Share this post


Link to post
Share on other sites
Quote[/b] ]if you combine weapons player and magazines player you will get the inventory.

That is good to know but I was unaware of the issue.  I have always just defined the array ahead of time like this...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_mags = magazines _player

if ("something" in _mags) then {....

...and not had a problem.

Also, there are some other things wrong with the code I think (assuming you posted the entire script or code snippet).  Are you trying to use nested if-statements?  If so, you are missing a "};".  Barring any other code changes it should look like this (if not please ignore):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ("RPO_obj17" in magazines _player) then

{

if (removemagazine _player == 1) exitwith

{

hint "You bought a car for $100.";

};

}:

I am also unsure of your use of "removemagazine". Are you trying to use the removeMagazine command or is it global variable you create for something?

On a semi-related note just to make sure you avoid any potential pitfalls: Whenever you drop ANY weapon, along with dropping that weapon and its related magazines it also drops ANY magazines for any weapon you don' have.  So, if you are using roleplaying objects in the form of magazines (as opposed to weapons) if the player drops a weapon and the player does not have a weapon in inventory that uses those role playing magazines then he will also drop those role playing objects.

There are three solutions to this that I can think of off the top of my head: 1) Create a "proxy" weapon that a player has and "uses" roleplaying object magazines.  Of course, it will then take up a weapon inventory slot, or 2) Make your roleplaying objects weapons (but this will also take up extra space), or 3) not actually use objects but instead use variables (via setVariable perhaps) to determine what roleplaying objects a player is carrying.

I hope this helps...Good luck!

Share this post


Link to post
Share on other sites

Thanks!! Yeah I just put that script together with reference from another script, wasn't actually sure it was going to work. wink_o.gif Thank you both! Very much. thumbs-up.gif The objects are already created, it is money from Roleplay Objects by Al Simmons and Tiger

*EDIT* THIS IS EXACTLY WHAT I NEEDED THANK YOU!!!!!!! IT WORKS PERFECT! notworthy.gif

Share this post


Link to post
Share on other sites

Keeps returning an error

missin { and };

and the script stops working.

for example it is supposed to check if the player has the magazine but it just says both messages and stops.

huh.gifconfused_o.gifbanghead.gif

should I just use hints? instead of player specific messages (groupchat etc)

Share this post


Link to post
Share on other sites

What's the exact code you are working with now? Did you correct the removeMagazine line?

I just tried the following code (using a laser battery instead of the role playing object since I don't have that addon installed) and it worked, that is, it removed the laser battery from the unit and showed the hint:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_player = _this select 0;

_action = _this select 2;

if ("Laserbatteries" in magazines _player) then

{

_player removeMagazine "Laserbatteries";

hint "You bought a car for $100.";

};

Share this post


Link to post
Share on other sites

hmmm... I try this.

I have been using

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if ("blank" in magazine player)) then

{

player groupchat '"You bought a car."

}else{

player grouchat "You can't afford this car."

};

That seems buggy though. I'll try yours.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_player = _this select 0;

_action = _this select 2;

if ("Laserbatteries" in magazines _player) then

{

_player removeMagazine "Laserbatteries";

hint "You bought a Skoda for $500.";

};

I still get this error

error {, ... missing }; banghead.gif

Am I doing something wrong?

Share this post


Link to post
Share on other sites

What is the eacrt error message. Where does the # show up in the message (it it does). From looking at the snippet it all looks ok so there is something else we are missing. Is there more to the script that just that snippet?

Share this post


Link to post
Share on other sites

I still get this error

error {, ... missing }; banghead.gif

Are you sure that your script file has the right extension ?

It must be .sqf and not .sqs

This is an error message that can occur if you try to call a sqf script with exec.

Xeno

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
Sign in to follow this  

×