cookies2432 105 Posted December 8, 2015 So.. I'm trying to add an action to an ai character however, it doesn't seem to be working. This is my script: _buyHatchBack = carseller addAction ["Buy Hatchback",{call fn_carBuySystem}, [carID = C_Hatchback_01_F, carPrice = 200]6,false,false]]; My function call "fn_carBuysystem" is: fn_carBuySystem { carSpawn = carspawn; if (Money >= carPrice) then { Money = Money - carPrice; carID createVehicle setPos (getPos carSpawn); hint ["You have bought a %1 and you have %2 dollars left.", carName, Money]; } else { hint "You do not have enough money for this car"; }; What am i doing wrong? :) Share this post Link to post Share on other sites
didotto 13 Posted December 8, 2015 If I'm not wrong, you should do something like this: carseller addAction ["Buy Hatchback",{call fn_carBuySystem}, ["C_Hatchback_01_F", 200, "Hatchback"],6,false,false]; fn_carBuySystem = { private ["_carID", "_carPrice", "_carName"]; _carID =(_this select 3) select 0; _carPrice = (_this select 3) select 1; _carName = (_this select 3) select 2; _carSpawn = carspawn; if (Money >= _carPrice) then { Money = Money - _carPrice; _veh = _carID createVehicle (getPos _carSpawn); 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"; }; }; NOTE: I added one more parameter (_carName) (I edited this post btw) Share this post Link to post Share on other sites
cookies2432 105 Posted December 8, 2015 Aha, yea i was thinking of the "this select 0 etc" command, wasn't just sure about it since i'm quite a "magic" variables. Thanks a ton for the help! :) Share this post Link to post Share on other sites
cookies2432 105 Posted December 8, 2015 I have another issue, i use the SetVehicleLock command, i can lock it but i can't unlock it for some reason. This is the function: fn_carBuySystem = { private ["_carID", "_carPrice", "_carName, _caller"]; _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 addAction ["Unlock Vehicle", {_veh setVehicleLock "UNLOCKED"}]; 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"; }; }; Share this post Link to post Share on other sites
didotto 13 Posted December 8, 2015 This should work (the variable is local and not valid in that scope): fn_carBuySystem = { private ["_carID", "_carPrice", "_carName"," _caller"]; _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 addAction ["Unlock Vehicle", {(_this select 0) setVehicleLock "UNLOCKED"}]; 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"; }; }; Share this post Link to post Share on other sites
cookies2432 105 Posted December 8, 2015 Thanks a ton! Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted December 8, 2015 So.. I'm trying to add an action to an ai character however, it doesn't seem to be working. This is my script: _buyHatchBack = carseller addAction ["Buy Hatchback",{call fn_carBuySystem}, [carID = C_Hatchback_01_F, carPrice = 200]6,false,false]]; My function call "fn_carBuysystem" is: fn_carBuySystem { carSpawn = carspawn; if (Money >= carPrice) then { Money = Money - carPrice; carID createVehicle setPos (getPos carSpawn); hint ["You have bought a %1 and you have %2 dollars left.", carName, Money]; } else { hint "You do not have enough money for this car"; }; What am i doing wrong? :) Just for the record: Please try to avoid global variables if you can. Your first post was unnecessarily flooded with global variables, you had no local variable at all (local variables start with underscore, like in didotto's post - global variables don't have such). It happens quicker than you'd believe that one of your global variables accidently overwrites variables used by addons or other scripts, same vice versa. So, try to avoid them and if you really need them, give them a proper unique name (a custom prefix for instance) so the chances of conflicts are extremely low. Share this post Link to post Share on other sites
cookies2432 105 Posted December 9, 2015 Just for the record: Please try to avoid global variables if you can. Your first post was unnecessarily flooded with global variables, you had no local variable at all (local variables start with underscore, like in didotto's post - global variables don't have such). It happens quicker than you'd believe that one of your global variables accidently overwrites variables used by addons or other scripts, same vice versa. So, try to avoid them and if you really need them, give them a proper unique name (a custom prefix for instance) so the chances of conflicts are extremely low. Ah thank, didn't know it could overwrite variables used by addons. :) Share this post Link to post Share on other sites
cookies2432 105 Posted December 9, 2015 I got more issues, YAY. :) So for some reason this doesn't seem to be working: "B_Soldier_F" createUnit [getMarkerPos "test", _group1]; But when i put it like this: "B_Soldier_F" createUnit [getpos player, group player]; I may be a total idiot for not knowing what's wrong but, i don't get it :mellow: . Proabably that damn "_this select 0" command agains isn't it? <_< Share this post Link to post Share on other sites
didotto 13 Posted December 9, 2015 I got more issues, YAY. :) So for some reason this doesn't seem to be working: "B_Soldier_F" createUnit [getMarkerPos "test", _group1]; But when i put it like this: "B_Soldier_F" createUnit [getpos player, group player]; I may be a total idiot for not knowing what's wrong but, i don't get it :mellow: . Proabably that damn "_this select 0" command agains isn't it? <_< Is _group1 an exsisting group? (https://community.bistudio.com/wiki/createUnit) If not, you have to create it first with createGroup _group1 = createGroup side (side can be: west, east, resistance) Share this post Link to post Share on other sites
cookies2432 105 Posted December 9, 2015 Oh, thanks! Share this post Link to post Share on other sites