Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* tienda_mp.sqf
- * [true, "objeto"] execVM "tienda_mp.sqf"; -> comprar
- * [false, "objeto"] execVM "tienda_mp.sqf"; -> vender
- */
- if (isNil {arr_stock}) then {
- arr_stock = [5, 1, 1, 1, 1, 1];
- publicVariable "arr_stock";
- };
- if (isNil {tienda}) then {
- tienda = [["platano", 100], ["manzana", 200], ["kiwi", 150], ["pera", 160], ["sandia", 190], ["melon", 400]];
- };
- _item = _this select 1;
- _comprarOvender = _this select 0;
- _precio = 0;
- _itemvalido = false;
- _indc = 0;
- //Asigna el precio correspondiente a ese objeto y guarda la posición del array en la que se encuentra
- {
- if ((_x select 0) == _item)
- then {
- _precio = _x select 1;
- _itemvalido = true;
- _indc = _foreachindex;
- };
- }forEach tienda;
- _stock = arr_stock select _indc;
- //Si el objeto no existe sale del script
- if (!_itemvalido) exitWith {hint "Producto no disponible"};
- if (_comprarOvender) then {
- //COMPRO
- //si no tengo dinero para comprarlo, sale del script
- if (dinero < _precio) exitwith {hint "No tienes suficiente dinero"};
- //si no hay stock, sale del script
- if (_stock <= 0) exitwith {hint format ["No hay stock de %1", _item]};
- //resta una unidad al stock de la tienda
- arr_stock set [_indc, (arr_stock select _indc) -1];
- //resta el dinero al comprador
- dinero = dinero - _precio;
- //me añado el item
- missionNamespace setVariable [_item, (missionNamespace getVariable _item) +1];
- hint format ["Has comprado un %1 por %2 euros", _item, _precio];
- } else {
- //VENDO
- //Si no tengo el objeto no lo puedo vender / sale de la script
- if (missionNamespace getVariable _item <= 0) exitwith {hint format ["No tienes %1", _item]};
- //Me sumo el dinero
- dinero = dinero + _precio;
- //Me resto el item
- missionNamespace setVariable [_item, (missionNamespace getVariable _item) -1];
- //Sumo uno al stock
- arr_stock set [_indc, (arr_stock select _indc) +1];
- hint format ["Has vendido un %1 por %2 euros", _item, _precio];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement