Jump to content
Sign in to follow this  
daimyo21

Createvehicle through IsServer, Addaction to object so player can use JIP HELP!

Recommended Posts

SHUKOOOOO! With the help of twirly and demonized (twirly adding nice buildingpos check feature), the script you practically wrote all for me (which i understand much better now) is now having MP issues with the addactions once again. No errors show on -showscripterrors and all code checks out in squint.

So I have a mp server on lan, then I join as a player (so i simulate a real player and not as the server host). Than this runs on init.sqf:

foodcheck = 0;
watercheck = 0;


[] spawn {
 waituntil {!isnil "SHK_pv_foodAction";};
 {
   _x addAction[("<t color=""#FF0000"">" + ("Take Food!") +"</t>"),"example_scripts\take_food.sqf", [], 1, false, false, "", ""];
 } foreach SHK_pv_foodAction;
};
while {foodcheck < 3} do {
if(isServer) then { 
private ["_baskets", "_pos", "_posarray", "_rndpos", "_cnt", "_randfood", "_randbuilds", "_build", "_genfood"];
 _baskets = []; 
 _pos =[]; 
 _posarray = [];
 _rndpos = [];
 _randFood = ["land_basket_ep1", "land_wicker_basket_ep1", "land_bag_ep1", "land_vase_loam_3_ep1", "land_vase_ep1", "land_vase_loam_2_ep1", "land_vase_loam_ep1"];
 _randbuilds = [bt25, bt35, bt45];
 _build = _randbuilds select (floor (random (count _randbuilds)));
 _cnt = 0;
while {format ["%1", _build buildingpos _cnt] != "[0,0,0]" } do {
_pos = _build buildingPos _cnt;
_posarray = _posarray + [_pos];
_cnt = _cnt + 1;
sleep 0.02;
};

for "_i" from 1 to (floor(random 3)) do {
   _rndpos = _posarray select (floor (random (count (_posarray))));
   _genfood = _randfood select floor (random (count _randfood)) createvehicle getpos _build;
_genfood setpos _rndpos;
   _baskets set [count _baskets, _genfood];
};
 SHK_pv_foodAction = _baskets;
 publicvariable "SHK_pv_foodAction";
};
foodcheck=foodcheck+1;
sleep .01;
};

[] spawn {
 waituntil {!isnil "SHK_pv_waterAction"};
 {
   _x addAction[("<t color=""#0F81EB"">" + ("Take Water!") +"</t>"),"example_scripts\take_water.sqf", [], 1, false, false, "", ""];
 } foreach SHK_pv_wateraction;
};
while {watercheck < 3} do {
if(isServer) then { 
private ["_randbuilds", "_build", "_genfood", "_randwater", "_genwater", "_buckets", "_pos", "_posarray", "_cnt", "_rndpos"];

 _randWater = ["land_barrel_water", "land_teapot_ep1", "land_canister_ep1", "land_bucket_ep1", "metalbucket", "land_water_pipe_ep1"];
 _randbuilds = [bt25, bt35, bt45];
 _buckets = [];
 _pos =[]; 
 _posarray = [];
 _rndpos = [];
 _build = _randbuilds select (floor (random (count _randbuilds)));
 _cnt = 0;
 while {format ["%1", _build buildingpos _cnt] != "[0,0,0]" } do {
_pos = _build buildingPos _cnt;
_posarray = _posarray + [_pos];
_cnt = _cnt + 1;
sleep 0.02;
};
 for "_i" from 1 to (floor(random 3)) do {
   _rndpos = _posarray select (floor (random (count (_posarray))));
   _genwater = _randwater select floor (random (count _randwater)) createvehicle getpos _build;
   _genwater setPos _rndpos; 
   _buckets set [count _buckets, _genwater];
 };
 SHK_pv_waterAction = _buckets;
 publicvariable "SHK_pv_waterAction";
};
watercheck=watercheck+1;
sleep .01;
};

Its all dandy, all objects spawn but only 1 or 2 addactions show up on the objects for the client player (out of maybe 10), on rejoin though those same objects dont show up anymore as addaction.

When I place the While Loop before [] spawn like this:

while {foodcheck < 3} do {
[] spawn {
 waituntil {!isnil "SHK_pv_foodAction";};
 {
   _x addAction[("<t color=""#FF0000"">" + ("Take Food!") +"</t>"),"example_scripts\take_food.sqf", [], 1, false, false, "", ""];
 } foreach SHK_pv_foodAction;
};

It does the same thing but now the addaction will show multiple times on 1 item and none for others. I believe JIP either sees same thing ornothing at all.

Anyways, The basic code you gave me before would work fine but would only do 1 run through when it worked.

[] spawn {
 waituntil {!isnil "SHK_pv_foodAction"};
 {
   _x addAction[("<t color=""#FF0000"">" + ("Take Food!") +"</t>"),"example_scripts\take_food.sqf", [], 1, false, false, "", ""];
 } foreach SHK_pv_foodAction;
};

if(isServer) then { 
 _nObject = bt25;

 _baskets = [];

 for "_i" from 1 to 4 do {
   _genfood="land_basket_ep1" createvehicle getpos _nobject; 
   //_genfood setPos (_nobject buildingpos (random 20)); 
   _baskets set [count _baskets, _genfood];
 };
 SHK_pv_foodAction = _baskets;
 publicvariable "SHK_pv_foodAction";
};

Any advice on what I can try to change or do to make it MP friendly again? Also if anyone would like me to upload my mission for clearer reference let me know.

Edited by Daimyo21
misstypes i code

Share this post


Link to post
Share on other sites

Hello,

Have you heard of the Remote Execution?

Let me give you an example of adding an action that will happen on every machine in the network including JIP (Functions module must be placed in the editor).

[nil, _obj, "per", rADDACTION, ("<t color=""#0F81EB"">" + ("Take Water!") +"</t>"),"example_scripts\take_water.sqf", [], 1, false, false, "", ""] call RE;

Then, lets say you want that when a player clicks the action, the action is removed from everyone, including JIP.

[nil, _obj, "per", rREMOVEACTION, _id] call RE;

_neo_

Share this post


Link to post
Share on other sites
Hello,

Have you heard of the Remote Execution?

Let me give you an example of adding an action that will happen on every machine in the network including JIP (Functions module must be placed in the editor).

[nil, _obj, "per", rADDACTION, ("<t color=""#0F81EB"">" + ("Take Water!") +"</t>"),"example_scripts\take_water.sqf", [], 1, false, false, "", ""] call RE;

Then, lets say you want that when a player clicks the action, the action is removed from everyone, including JIP.

[nil, _obj, "per", rREMOVEACTION, _id] call RE;

_neo_

So I dont know exactly where to place that or in a way that it grabs all the 100s of items created dynamically. Ill mess around with it more and leave update i I figure it out.

EDIT*** Without using the Remote execution Ive found that for the client, its showing the addaction "take food" multiple times for certain items and then none for most others.

EDIT UPDATE: Actually it seems as tho the "Take Food" action is actually showing up on all food items... but in a spam of 10+ actions while "Take Water" is not showing up on any its items.

Edited by Daimyo21

Share this post


Link to post
Share on other sites

Change this:

[] spawn {
 waituntil {!isnil "SHK_pv_foodAction";};
 {
   _x addAction[("<t color=""#FF0000"">" + ("Take Food!") +"</t>"),"example_scripts\take_food.sqf", [], 1, false, false, "", ""];
 } foreach SHK_pv_foodAction;
};

To this:

[] spawn {
 waituntil {!isnil "SHK_pv_foodAction";};
[color="Red"] {[nil, _x, "per", rADDACTION, ("<t color=""#0F81EB"">" + ("Take Water!") +"</t>"),"example_scripts\take_water.sqf", [], 1, false, false, "", ""] call RE;} foreach SHK_pv_foodAction[/color];
};

Share this post


Link to post
Share on other sites
Change this:

[] spawn {
 waituntil {!isnil "SHK_pv_foodAction";};
 {
   _x addAction[("<t color=""#FF0000"">" + ("Take Food!") +"</t>"),"example_scripts\take_food.sqf", [], 1, false, false, "", ""];
 } foreach SHK_pv_foodAction;
};

To this:

[] spawn {
 waituntil {!isnil "SHK_pv_foodAction";};
[color="Red"] {[nil, _x, "per", rADDACTION, ("<t color=""#0F81EB"">" + ("Take Water!") +"</t>"),"example_scripts\take_water.sqf", [], 1, false, false, "", ""] call RE;} foreach SHK_pv_foodAction[/color];
};

Just did a test through, now it doesnt seem to be adding actions to anything but they are spawning the same and -showscripterrors didnt have errors.

Share this post


Link to post
Share on other sites

I have a solution to fix this but not sure how to write it.

_randFood = ["land_basket_ep1", "land_wicker_basket_ep1", "land_bag_ep1", "land_vase_loam_3_ep1", "land_vase_ep1", "land_vase_loam_2_ep1", "land_vase_loam_ep1"];

player addaction [("<t color=""#FF0000"">" + ("Take Food!") +"</t>"),"example_scripts/eat_food.sqf", 1,true,true,"","_randfood = typeof cursorTarget && cursorTarget distance player < 5"];

So basically im making the addaction local to player and when his CursorTarget is over one of the _randfood. Itll show the action.

EDIT** I tried

cursortarget iskindof 'land_wicker_basket_ep1'

but it doesnt seem to work or give errors. whenever I just leave it as cursortarget distance player <5; it works

EDIT EDIT** NEVERMIND IM RETARDED, cursortarget iskindof 'land_wicker_basket_ep1' Works! YAY

Edited by Daimyo21

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  

×