Jump to content
Sign in to follow this  
BomboBombom

Function script problems

Recommended Posts

Well, oddly enough it remains outputting nothing. using function or sqf, neither one. I wish I knew what broke everything. Unable to find why no matter what _output will never transfer out of the function and into the value. It did work, for a brief period of time.

I completely removed the "NIL" as it wont be used in either case.

## Will be attempting to rewrite the whole script and use dynamic search of structures and the locations in the structures. Can't contemplate functions well atm.

Current code, for those who are curious:

Trigger loop;

Trigger 1. Condition: true

On act.

conditiontime=time;

Trigger 2. Condition: conditiontime<time

hint format["%1 , %2",conditiontime,time]; if ( format["%1",oo] == "any" ) then { objects=[];oo=thistrigger nearObjects ["building",triggerarea thistrigger select 0]; { if !(format["%1",_x buildingPos 0]=="[0,0,0]") then {objects=objects+[_x]; }; }forEach oo; oo=[]; {if (["MAKELOOT",getPos _x] call fnc_InMarker) then { oo=oo+[_x]; }; }forEach objects;}; if (format["%1",houses]=="any") then { {houses=houses+([_x,houses] call fn_Loota select 1); }forEach oo; } else { {null=[_x] call fnc_Loota;}forEach houses; }; conditiontime=time+(25*1);

Trigger 2 is missing a few things. I'll change it and run the "oo" building array through the function instead later.

fnc_Loots

private ["_building","_loots","_dummy","_spot"];
_building=_this select 0;
_loots=[];
_count=0;
_dummy="";
_spot=[];

while {format["%1",_house buildingPos _count]!="[0,0,0]} do {
_spot=_house buildingPos _count;
_dummy="Hen" createVehicle [_spot select 0,_spot select 1,(_spot select 2)+5;
sleep 0.5;
_spot=getPos _dummy;
deleteVehicle _dummy;
_loots=_loots+_spot;
_count=_count+1;
};
_loots

fnc_Loota

private ["_house","_houses","_search","_locations","_out"];
_house=_this select 0;
_houses=_this select 1;
_search=typeOf _house;
_locations=[];
_out=[];

if !(_search in _hosues) then {
_locations=[_house] call fn_Loots;
};
_house setVariable ["SPAWNS",_locations];
_out=[_house,_search];
_out

The goal with the code is to get an array of the loot locations in all buildings. The original ones do not work like they should. WeaponHolder's in bars end up under ground even when raised above slightly and perfectly placed in other buildings. Spawning these hen's and letting them fall will allow for an location "on" the floor. A lot of tweaks and changes will be needed, but eventually I hope to be able to post a good array of values. One day...

Good night (21:52 pm, 15/10/2012)

Edited by BomboBombom

Share this post


Link to post
Share on other sites

fnc_Loota

private ["_house","_houses","_search","_locations","_out"];
_house=_this select 0;
_houses=_this select 1;
_search=typeOf _house;
_locations=[];
_out=[];

if !(_search in [color="#FF0000"]_hosues[/color]) then {
_locations=[_house] call fn_Loots;
};
_house setVariable ["SPAWNS",_locations];
_out=[_house,_search];
_out

I did spot _hosues instead of _houses!

Share this post


Link to post
Share on other sites
thank you twirly. That will probably save me quite some time.

I'm pretty sure pasting the code into Squint would have given a warning about the variable name. So, if you are into "saving time", then I'm going to repeat myself and suggest using the program.

Share this post


Link to post
Share on other sites

Trying to read typeOf string value and determine building type by "Land_Ind_" in "Land_Ind_Mlyn_02" for example. Then _house setVariable ["Type","IND"]; for industrial buildings.

Can not figure out what commands reads a string and I've been looking through comref and searched google some for a method, but found nothing. I do remember seeing some sort of method using forEach, where it would go through each letter of a string.

---------- Post added at 19:14 ---------- Previous post was at 19:07 ----------

Shuko: I use Squint, even after fixing various problems in my old script it didn't work. Couldn't figure why it stopped working. Probably some tweak that messed it up. I gave up and am rewriting it all.

Share this post


Link to post
Share on other sites

I just modified a function I had here that returns a buildings ID to now return a buildings Type.

The function is fed a building and it will return "wall" or "ind" or "shed" extracted from the classname.

Not sure how much use it is to you but seemed to be along the lines of what you needed so here it is. The code alone might help you work out what you need.

fnc_getBuildType

/*

fnc_getBuildType.sqf
Function for returning building type

In your init.sqf:-

	fnc_getBuildType = compile preprocessFile "fnc_getBuildType.sqf";

Call with:-

	_typ = [building] call fnc_getBuildType;

*/

private ["_build","_sn","_sf","_ef","_na","_tp","_i","_item1","_item2"];

_build = _this select 0;

_sn = toArray (str (_build));

_sf = false;
_ef = false;
_na = [];
_tp = "";

for "_i" from 1 to (count _sn)-1  do {
_item1 = _sn select _i-1;
_item2 = _sn select _i;
if (_sf and (not (_ef))) then {
	_na set [count _na,_item1];
};
if (_item1 == 58 and _item2 == 32) then {
	_sf = true;
};
if (_item1 == 95) then {
	_ef = true;
};
};

if ((count _na) >=3) then {
_na set [((count _na)-1) ,"delete"];
_na = _na - ["delete"];
_na set [0 ,"delete"];
_na = _na - ["delete"];
_tp = toString (_na);
};

_tp

To compile the function and have it available for use put this in your init.sqf....

fnc_getbuildType = compile preprocessFile "fnc_getBuildType.sqf";

Use like this....

_buildtyp = [_build] call fnc_getbuildType;

There is a Demo Mission here.

Edited by twirly
Calrity and fixed shit

Share this post


Link to post
Share on other sites

@Shuko: Thanks, I may implement the suggested if needed. Twirly's post seem to contain what is needed.

@Twirly: Fantastic Twirly, I am testing the demo mission to see how it works. Thanks

:)

Share this post


Link to post
Share on other sites

I've edited the script provided Twirly, experimenting with how to do a good item spawn system trying to get the weaponholder positioning working properly.

I decided to try and move one position up a bit as it was ending up on the staircase and the weaponholder wouldn't angle itself.

removed ** updated in next post **

I'm experimenting with loot positions. The code works for one building, but if I angle the building it fails.

I'll go back to solving the original positions rather than custom ones. Tomorrow I will continue and keep on track. ;p

Thanks again and have a good night/day/afternoon/evening, cheers~

Edited by BomboBombom

Share this post


Link to post
Share on other sites

I don't understand why setPos doesn't care about the height that the object is at. When I try using the chicken method for determining floor height it still puts the weaponHolder on the ground. Even after I do setPos after createvehicle. -_-;

+++ Solved.

/*

*/

sleep 2;

titleText ["View the map to see the markers and types of buildings found.","plain down"];

fnc_getbuildType = compile preprocessFile "fnc_getBuildType.sqf";

sleep 1;

//finds buildings closeby
_builds = nearestObjects [player,["Building"],500];

_id = 0;
_idees = [];

for "_i" from 0 to ((count _builds)-1) do {
_build = _builds select _i;

       if (format["%1",_build buildingPos 0]!="[0,0,0]") then {
_type = typeOf _build;
hint format["Building: %1 Type: %2 Loot: 0",_type,_build];
_count=0;
while { format["%1",_build buildingpos _count]!="[0,0,0]" } do {
 	 hint format["Building: %1 Type: %2 Loot: %3",_type,_build,(_count+1)];
        _gpos=_build buildingPos _count;
 _cock="Hen" createVehicle _gpos;
 _cock setPosATL _gpos;
 _gpos=getPosATL _cock;
 deleteVehicle _cock;

 _wph="WeaponHolder" createVehicle _gpos;
 _wph addWeaponCargo ["M16A2",5];
 _wph addMagazineCargo ["30Rnd_556x45_Stanag",10];
 _wph setPosATL [_gpos select 0,_gpos select 1,1];
 _wph setPosATL [getPos _wph select 0,getPos _wph select 1,(getPosATL _wph select 2)-(getPos _wph select 2)];
 _ris=getPosATL _wph select 2;
 while {_ris<_gpos select 2} do { _ris=_ris+0.01; _wph setPosATL [_gpos select 0,_gpos select 1,_ris-0.005];};
 _count=_count+1;

};

_typ = [_build] call fnc_getbuildType;

_idees set [count _idees,_typ];

hint format ["Type: %1",_typ];

_mrkr = format ["mkr_%1_%2", diag_ticktime,_i];

_m = createMarkerLocal [_mrkr, position _build];
_m setMarkerShape "ICON";
_m setMarkerColorLocal "colorORANGE";
_m setMarkerTypeLocal "mil_dot";
_m setMarkerSizeLocal [1, 1];
//_m setMarkerAlphaLocal 0.2;
_m setMarkerTextLocal format ["%1 Name: %2",_typ,_type];
};

sleep 0.01;

};

- This is currently experimental. The _ris part will be removed eventually.

- Part 2 of tests initiated.

Part 2 Will be moving this to a later stage, right now I'm going to rewrite spawn list and such

- Adding custom loot location to buildings lacking.

@ Figure out how to position objects according to a structures facing angle thus placing objects correctly no matter what direction a structure is facing.

# Current buildings lacking buildingPos locations that I require:

- Land_A_MunicipalOffice : Has about 6 positions preset. None on roof.

- Land_A_Hospital : Has 0 positions preset. None inside, nor on the roof.

Edited by BomboBombom

Share this post


Link to post
Share on other sites
I don't understand why setPos doesn't care about the height that the object is at. When I try using the chicken method for determining floor height it still puts the weaponHolder on the ground. Even after I do setPos after createvehicle. -_-;

when creating something you usually have to set the position again after createVehicle. So createvehicle blah blah; blah setPos blah;

If you still have issues i'd use setPosATL, I use it and rarely get issues.

Share this post


Link to post
Share on other sites

@Tonic-_-: Thank you. I found a way to solve the issue.

- Quickest way to determine loot tables?:

SWITCH

 _table=_building getVariable "TABLE";
switch (_table) do {
case "MIL": {
_spots=_building getVariable "SPOTS";
while { _count < _spots } do { the loot table code/function };
};
case "RES": {
blablabla..
};
};

- Case would compare swifly due to that it only searches for the compareable string?

IF

_table=_building getVariable "TABLE";
_spots=_building getVariable "SPOTS";

if (_table=="RES") then {
while {_count<_spots} do { that code again };
};
if (_table=="MIL") then {
other code stuff..
};

- If may be slower due to that it will compare all cases?

Dynamic call.

_table=_building getVariable "TABLE";
_spots=_building getVariable "SPOTS";
[_building,_table,_spots] call fnc_lootSpawn;

- fnc_lootSpawn would contain either the case or if version of the table spawn script and be preprocessed.

# Optimization ideas

- setVariable ["SPOTARRAY",(all lootspots variable)];

And then use forEach _SPOTARRAY; to go through the locations after initiation.

Even higher optimization in the future could be using preprocessed locations.

- Preprocess spots.

- Reduce spots used.

- Full custom spots preprocess list. (A lot of work)

- Avoiding overuse of script for spawning objects. Right now the script uses quite a lot of script to spawn one weaponholder. Would enjoy lowering that.

? Any way to generate a preprocessed location list or function script by using DIAG_LOG(or w/e it was called)?

Cheers.

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  

×