Jump to content

Recommended Posts

Hello, I'm in need of help with a script that's basicly a car shop. The units i'm using ingame are: 1 AI named "carseller" and 1 marker called "carspawn".

 

This is the script:

carseller addAction ["Buy Hatchback",{call fn_carBuySystem}, ["C_Hatchback_01_F", 200, "Hatchback"],6,false,false];
carseller addAction ["Buy Hobo",{call fn_carBuySystem}, ["C_man_p_fugitive_F", 3000, "Hobo"],6,false,false];
carseller addAction ["Buy Boxer",{call fn_carBuySystem}, ["C_Van_01_transport_F", 1500, "Boxer"],6,false,false];
carseller addAction ["Buy SUV",{call fn_carBuySystem}, ["	C_SUV_01_F", 500, "SUV"],6,false,false];

carSeller addACtion ["Add 5000£ to wallet",{call fnc_addMoney}];

fn_carBuySystem = {
    private["_Money","_carSpawn"];
    private ["_carID", "_carPrice", "_carName"," _caller"];
    _carSpawn = carSpawn;
    _carID =(_this select 3) select 0;
    _carPrice = (_this select 3) select 1;
    _carName = (_this select 3) select 2;
    _carSpawn = carspawn;
    _caller = _this select 1;
    if (_Money >= _carPrice) then {
    _Money = _Money - _carPrice;
    sleep 3;
    _veh = _carID createVehicle (getPos _carSpawn);
    _veh setVehicleLock "LOCKED";
    _veh setOwner (this select 3);
    _veh addAction ["Unlock Vehicle", {(_this select 0) setVehicleLock "UNLOCKED"}];
    _veh addAction ["Lock Vehicle", {(_this select 0) setVehicleLock "LOCKED"}];

     hint format ["You have bought a %1 and you have %2 dollars left.", _carName, _Money];
      } else {
     hint "You do not have enough money for this car";
     };
};



fnc_addMoney = {
  _Money = _Money + 5000;
}

Anyone got a clue what's wrong? :)

Share this post


Link to post
Share on other sites

Anyone got a clue what's wrong?  :)

 

What is it not doing?

one thing I see is 4th addaction,

 

carseller addAction ["Buy SUV",{call fn_carBuySystem}, ["	C_SUV_01_F", 500, "SUV"],6,false,false];

the classname has alot of spaces, but that shouldn'r break anything.

Share this post


Link to post
Share on other sites

What is it not doing?

one thing I see is 4th addaction,

 

carseller addAction ["Buy SUV",{call fn_carBuySystem}, ["	C_SUV_01_F", 500, "SUV"],6,false,false];

the classname has alot of spaces, but that shouldn'r break anything.

Woops, yea that looks silly yea, wasn't on purpose. And what it's doing is it's saying something along the lines of "local variables in a global scope"

Share this post


Link to post
Share on other sites

And what it's doing is it's saying something along the lines of "local variables in a global scope"

 

Could you put down the complete error, from RPT. so I see where it happens.

Share this post


Link to post
Share on other sites

Could you put down the complete error, from RPT. so I see where it happens.

How do i do that? :/

Share this post


Link to post
Share on other sites

search this in your windows search bar,

C:\Users\%username%\AppData\Local\Arma 3

and get the latest rpt file (where it happend). Copy all the text from there to a pastebin.com and send me the url to it.

Share this post


Link to post
Share on other sites

Also just seen,

_carSpawn = carSpawn;

is done twice, also thats not how you define a marker, you use a string, "carSpawn".

(getPos _carSpawn);

Here you need to use the getMarkerPos command, to get the markers position.

 

This might fix your whole problem, but might not ;).

Share this post


Link to post
Share on other sites
Error position: <private ["_carID", "_carPrice", "_carNam>
Error Local variable in global space
File missions\CYKA%20BLYAT.Stratis\init.sqf, line 14
private["_Money","_carSpawn"];
private ["_carID", "_carPrice", "_carName"," _caller"]; 

I'm thinking, could be wrong, its because you have private twice, so try to use only one so merge them.

It only kicks it out by the 2nd private so that why I think that's wrong.

Share this post


Link to post
Share on other sites
Error position: <private ["_carID", "_carPrice", "_carNam>
Error Local variable in global space
File missions\CYKA%20BLYAT.Stratis\init.sqf, line 14
private["_Money","_carSpawn"];
private ["_carID", "_carPrice", "_carName"," _caller"]; 

I'm thinking, could be wrong, its because you have private twice, so try to use only one so merge them.

It only kicks it out by the 2nd private so that why I think that's wrong.

 

I will try it. Thank you!

Share this post


Link to post
Share on other sites

Still not working, same error :/

 

A few things:

To get the position of a marker, you need to use getMarkerPos.

 

In your script, _money is a local variable and is not defined anywhere. Therefore you are adding and subtracting numerical values from a variable which is not defined (it wont work). To fix, change _money to a global variable.

 

Also, your syntax for setOwner is incorrect. You are using an array for the owner id when you need to use a client id, maybe use (owner (_this select 1)).

Share this post


Link to post
Share on other sites

A few things:

To get the position of a marker, you need to use getMarkerPos.

 

In your script, _money is a local variable and is not defined anywhere. Therefore you are adding and subtracting numerical values from a variable which is not defined (it wont work).

I am now using getMarkerPos :) And for the _money, where should i define it?

 

EDIT: I missread lol

Share this post


Link to post
Share on other sites

I am now using getMarkerPos :) And for the _money, where should i define it?

have a play with this:

 

carseller addAction ["Buy Hatchback", {call fn_carBuySystem}, ["C_Hatchback_01_F", 200, "Hatchback"], 6, false, false];
carseller addAction ["Buy Hobo", {call fn_carBuySystem}, ["C_man_p_fugitive_F", 3000, "Hobo"], 6, false, false];
carseller addAction ["Buy Boxer", {call fn_carBuySystem}, ["C_Van_01_transport_F", 1500, "Boxer"], 6, false, false];
carseller addAction ["Buy SUV", {call fn_carBuySystem}, ["C_SUV_01_F", 500, "SUV"], 6, false, false];
carSeller addACtion ["Add 5000£ to wallet", {call fnc_addMoney}];

fn_carBuySystem = {
	params ["", "_caller", "_id", "_args"];
	_args params ["_carID", "_carPrice", "_carName"];
	
	private _carSpawn = carSpawn;
	private _money = missionNamespace getVariable ["Money", 0];
	
    if (_money >= _carPrice) then {
		_money = _money - _carPrice;
		missionNamespace setVariable [
			"Money",
			_money,
		];
		
		sleep 3;

		private _veh = _carID createVehicle (getMarkerPos _carSpawn);
		_veh setVehicleLock "LOCKED";
		_veh setOwner (owner _caller);

		_veh addAction ["Unlock Vehicle", {(_this select 0) setVehicleLock "UNLOCKED"}];
		_veh addAction ["Lock Vehicle", {(_this select 0) setVehicleLock "LOCKED"}];

		hint format ["You have bought a %1 and you have %2 dollars left.", _carName, _Money];
	} else {
		hint "You do not have enough money for this car";
	};
};

fnc_addMoney = {
	missionNamespace setVariable [
		"Money",
		(missionNamespace getVariable ["Money", 0]) + 5000
	];
};

MissionNamespace getVariable will return the global variable called "Money". If the variable does not exist, a default value of 0 will be used instead.

missionNamespace setVariable [
	"Money",
	(missionNamespace getVariable ["Money", 0]) + 5000,
];

This part will set the value of _Money to it's new value. This is the same as:

Money = Money + 5000;

Essentially this means that it will define the variable if it does not already exist.

Share this post


Link to post
Share on other sites

have a play with this:

 

carseller addAction ["Buy Hatchback", {call fn_carBuySystem}, ["C_Hatchback_01_F", 200, "Hatchback"], 6, false, false];
carseller addAction ["Buy Hobo", {call fn_carBuySystem}, ["C_man_p_fugitive_F", 3000, "Hobo"], 6, false, false];
carseller addAction ["Buy Boxer", {call fn_carBuySystem}, ["C_Van_01_transport_F", 1500, "Boxer"], 6, false, false];
carseller addAction ["Buy SUV", {call fn_carBuySystem}, ["C_SUV_01_F", 500, "SUV"], 6, false, false];
carSeller addACtion ["Add 5000£ to wallet", {call fnc_addMoney}];

fn_carBuySystem = {
	params ["", "_caller", "_id", "_args"];
	_args params ["_carID", "_carPrice", "_carName"];
	
	private _carSpawn = carSpawn;
	private _money = missionNamespace getVariable ["Money", 0];
	
    if (_money >= _carPrice) then {
		_money = _money - _carPrice;
		missionNamespace setVariable [
			"Money",
			_money,
		];
		
		sleep 3;

		private _veh = _carID createVehicle (getMarkerPos _carSpawn);
		_veh setVehicleLock "LOCKED";
		_veh setOwner (owner _caller);

		_veh addAction ["Unlock Vehicle", {(_this select 0) setVehicleLock "UNLOCKED"}];
		_veh addAction ["Lock Vehicle", {(_this select 0) setVehicleLock "LOCKED"}];

		hint format ["You have bought a %1 and you have %2 dollars left.", _carName, _Money];
	} else {
		hint "You do not have enough money for this car";
	};
};

fnc_addMoney = {
	missionNamespace setVariable [
		"Money",
		(missionNamespace getVariable ["Money", 0]) + 5000
	];
};

MissionNamespace getVariable will return the global variable called "Money". If the variable does not exist, a default value of 0 will be used instead.

missionNamespace setVariable [
	"Money",
	(missionNamespace getVariable ["Money", 0]) + 5000,
];

This part will set the value of _Money to it's new value. This is the same as:

Money = Money + 5000;

Essentially this means that it will define the variable if it does not already exist.

Thanks :D

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

×