Jump to content
Sign in to follow this  
ShinShin

Script Help! D: (Player Object Spawning Script)

Recommended Posts

Okay, So I Managed to Create an Object Spawning Script by Manipulating

Kylanias "Set Flag/Object" Example Script & Something else.

( http://www.kylania.com/ex/?p=60 )

What I Would Like to Know is...

1: The Objects sometimes do not Spawn Perfectly infront of the Player as I Wish they would.

2: I'd Like to know How to Make the Use of this Action Disappear after 3 or 4 Uses(Clicks).

3: I Need to Get the Script Compatible with Respawns... Script becomes inactive if a Player Dies & Respawns.

4: I Would ALSO Like to Know... How the Hell to give THAT player who placed THAT object... Thee Ability to Remove it if needed & he gains 1 Use (as he removed the Object).

Here is the Script sofar...

//Place in Init Field of Editor Unit or Object//
//action_1 = this addAction ["Place SteelHedge", "Kays_Scripts\bHedge.sqf"];

//Build Object//
private ["_obj"];

_obj = [player, 5, getdir player] call BIS_fnc_relPos; myObject = "Hedgehog" createVehicle _obj;

exit;

I'm VERY VERY VERY New to Scripting... though ive taken Quite alot of time to myself to Read through lots of Scripts and I Think I Can Say... I Understand but Still very unSure of How to Go about Createing Such a Script.

Edited by ShinShin

Share this post


Link to post
Share on other sites

Heres a multiplayer example i created -

gives addaction to the player

creates bunker in direction of that which the player is facing.

the item is given an addaction - to remove the said bunker.

not the prettiest script but should give you an idea how to create it.

could you a pubvariable or setvariable to add subtract the amount of times you can use the addaction. e.g waitUntil {!bunker_active &&(alive player) && uses > 0};

each time you call the bunker script

uses = uses - 1;

Just an idea...

hope it helps

bunkerscriptinit.sqf

sleep 2;
if ! isdedicated then                                   //not run on the dedicated server - client side 
{
waituntil {!isnil "bis_fnc_init"};
[] spawn 								// calls the below script used for a loop
{

private ["_addbunker"];//declaring	
waituntil {!isnull player};
bunker_active = false;


if (!isnull player) then 
{
if (typeof player == "US_Soldier_MG_EP1") then 
   {
	while {true} do 
	{
	    waitUntil {!bunker_active &&(alive player)};

	    _addbunker = player addAction [("<t color=""#66FFFF"">" + ("Build bunker") +"</t>"), "skills\bunker.sqf",[],1,false,true];

	    waitUntil {bunker_active || (!alive player)};
	    player removeAction _addbunker;

	};
    }; //type of player	 
}; //if !is null
}; // []spawn
}; //!isserver

bunker.sqf

if (!isserver) then 

{
private ["_bunker","_bunkerremoval"];
waituntil { !isNil "BIS_fnc_init" };

if (count (nearestObjects [player, ["Fort_EnvelopeSmall_EP1"], 30]) == 0) then  //300metres

{
	bunker_active = true;
	player playMove  "AinvPknlMstpSlayWrflDnon_medic";
	sleep 3.5;
	_bunker = "Fort_EnvelopeSmall_EP1" createVehicle (position player), 
	_bunkerremoval = _bunker addAction ["Remove Bunker", "skills\bunkerremoval.sqf",[],6];
	_bunker setdir getdir player;
	sleep 10; 
	bunker_active = false;
}
else
{
	hintsilent "Bunker already within 30 metres!";
	sleep 2;	
};

};

bunkerremoval.sqf

if (!isserver) then 

{
private ["_bunker","_bunkerremoval"];
_bunker = _this select 0;

player playMove  "AinvPknlMstpSlayWrflDnon_medic";
sleep 3.5;
deletevehicle _bunker;
};

Edited by Mikie boy

Share this post


Link to post
Share on other sites

So your

"BunkerScriptInit.sqf"
is the One Which gives a Unit the Ability to Spawn "xxx" infront of them? (In Other Words, Adds the Action to the Units.)

Your

"Bunker.sqf"
is the Equivalent of What I Have & is the Object itself to be Spawned?

and Your

"BunkerRemoval.sqf"
Obviously gives the Action to Remove thee Object or Object infront of the Player?

Share this post


Link to post
Share on other sites

yep spot on, what happens with add actions is that they get deleted after respawn, i think there is an event handler you can use to do this but it may be a bit of a fiddle.

this basically set up a loop of the add action that automatically waits - therefore stopping the same add action being called on your screen over and over and over.

the bunker is the script that is called by the addaction - and the bunkerremove.sqf is as it says, so yep basically correct.

Share this post


Link to post
Share on other sites

Okay cool...

So i Got the Action Working ingame & it Shows. But Nothing Spawns...

Aside from nothing Spawning.

Say I want this Script to Work on EVERY unit & not just with a Specific Named Unit e.g.

"US_Soldier_Medic_EP1"
Which Obviously is the US Medic Unit. But anyways... Yeah?! :)

Share this post


Link to post
Share on other sites

if single player - can use (player==player) or name the player as something then list them - or delete the line and the brackets accompanying the if line...

Are you using arma 2 or op arrow head? possibly due to the object not being on arma 2 or more likely you need to place a function module on the map.

also add -showScriptErrors to your arma short cut at the end of the target line... e.g

"E:\Program files\Bohemia Interactive\ArmA 2\Expansion\beta\arma2oa.exe" -mod=Expansion\beta;Expansion\beta\Expansion -nosplash -showScriptErrors

show errors in the game - help you find out whats not working

Share this post


Link to post
Share on other sites

Yes, i'm Running Combined Operations...

and this is for Multiplayer.

I have Show Script Errors. But it's kinda hard to Read if it only shows for 2 or 3 seconds and Goes away. Not only that... Mine is all Chopped up and shit. Half shows and Sometimes half doesn't :/

the Object am trying to Use is

"Land_HBarrier1"

e.g.

if (!isserver) then 

{
private ["_bSandBarrier","_dSandBarrier"];
waitUntil { !isNil "BIS_fnc_init" };

if (count (nearestObjects [player, ["Land_HBarrier1"], 5]) == 0) then  //5 meteres

{
	barrier_active = true;
	player playMove  "AinvPknlMstpSlayWrflDnon_medic";
	sleep 5.0;
	_bSandBarrier = "Land_HBarrier1" createVehicle (position player), 
	_dSandBarrier = _bSandBarrier addAction ["Remove Sand Barrier", "Kays_Scripts\dSandBarrier.sqf",[],6];
	_bSandBarrier setdir getdir player;
	sleep 10; 
	barrier_active = false;
}
else
{
	hintsilent "Barrier Within 5 Meters Already!";
	sleep 2;	
};

};

Share this post


Link to post
Share on other sites

try it with something else -- even the medic tent -

work out if that is the error first

Share this post


Link to post
Share on other sites

Hmm...

Nothing Still...

No Error Comes up Regarding the Script.

But nothing Spawns Still... Even though the Action is Right There.

Share this post


Link to post
Share on other sites

remove this in the bunker.sqf

if (!isserver) then {   /// and the last };

addaction is local, so if a player activates the action, the script sees:

if server do this otherwise do nothing, server is only true for MP missions hosted by a player for that player only, and for Single player.

Share this post


Link to post
Share on other sites

Thanks Demonized! :D

It Worked! :yay:

Now Only problem is...

the Object Does not Spawn Directly where my Cursor or Player is Pointing.

Any Ideas?

Plus id Like to Get rid of, Not being able to Build another Object in its same area e.g. Side by Side.

They Aren't Placeable Side to Side. they're Spaced out automaticly (i think.)

Scripts...

SandBarrierInit.sqf

Sleep 2;

waituntil {!isnil "bis_fnc_init"};

[] spawn

{

private ["_addObjectAction"];

waituntil {!isnull player};

barrier_active = false;

if (!isnull player) then

{

if (player==player) then

{

while {true} do

{

waitUntil {!barrier_active &&(alive player) && 5 > 0};

__addObjectAction = player addAction [("<t color=""#66FFFF"">" + ("Place Sand Barrier") +"</t>"), "Kays_Scripts\bSandBarrier.sqf", [], 1, false, true];

waitUntil {barrier_active || (!alive player)};

player removeAction _addObjectAction;

};

}; // type of player

}; // if !isnull

// [] spawn

bSandBarrier.sqf

//Place in Init Field of Editor Unit/Object//

//action_3 = this addAction ["Place SandBarrier", "Kays_Scripts\bSandBarrier.sqf"];

//delete_3 = this addAction ["Remove SandBarrier", "Kays_Scripts\dSandBarrier.sqf"];

private ["_bSandBarrier","_dSandBarrier"];

waitUntil { !isNil "BIS_fnc_init" };

if (count (nearestObjects [player, ["Land_HBarrier1"], 5]) == 0) then //5 meteres

{

barrier_active = true;

player playMove "AinvPknlMstpSlayWrflDnon_medic";

sleep 5.0;

_bSandBarrier = "Land_HBarrier1" createVehicle (position player),

_dSandBarrier = _bSandBarrier addAction ["Remove Sand Barrier", "Kays_Scripts\dSandBarrier.sqf",[],6];

_bSandBarrier setdir getdir player;

sleep 10;

barrier_active = false;

}

else

{

hintsilent "Barrier Within 5 Meters Already!";

sleep 2;

};

dSandBarrier.sqf

//Place in Init Field of Editor Unit/Object//

//action_3 = this addAction ["Place SandBarrier", "Kays_Scripts\bSandBarrier.sqf"];

//delete_3 = this addAction ["Remove SandBarrier", "Kays_Scripts\dSandBarrier.sqf"];

private ["_bSandBarrier","_dSandBarrier"];

_bSandBarrier = _this select 0;

player playMove "AinvPknlMstpSlayWrflDnon_medic";

sleep 5.0;

deletevehicle _bSandBarrier;

Share this post


Link to post
Share on other sites

Thank you Mikie Boy & Demonized :D :yay:

Edited by ShinShin

Share this post


Link to post
Share on other sites

Thanks though man! :D

Atleast I Got Shit spawning now :yay:

I Just Hope Someone else who Knows... Can help me with the Problem i'm having when the Objects Don't Spawn directly infront of the player 2 or 3 meters ahead where they/I want it.

Edited by ShinShin

Share this post


Link to post
Share on other sites

_pos = getPos _player;  // position of reference.
_dist = 1; //Distance from position of reference.
_offdir = 0; //Relative direction from position of reference 0 - 360. (0 = forward, 180 = backwards).

//Find compass direction to spawn from position of reference.
_compassDir = ((getDir _player)+_offdir) mod 360;

//Find absolute coordinates by adding relative to position of reference.
_newX = (_pos select 0) + (sin _compassDir * _dist);
_newY = (_pos select 1) + (cos _compassDir * _dist);
_newPos = [_newX, _newY, 0];  // position found

_yourObject setDir (getDir _player);  // set objects direction to same as player, add + 90 to turn it sideways etc...
_yourObject setPos _newPos;  // place object of choise on new pos.

im not fully familiar with modelToWorld command, i think that command would be far less code.

Share this post


Link to post
Share on other sites

Okay Demonized

Gotcha...

Now...

If you wouldn't mind... Correct & tell Me what is Wrong with this? :butbut:

Script...

_bSandBarrier.sqf

// Call: pAction = this addAction ["Place SandBarrier", "Kays_Scripts\bSandBarrier.sqf"];

_pos = getPos _player; // position of reference.

_dist = 1; //Distance from position of reference.

_offdir = 0; //Relative direction from position of reference 0 - 360. (0 = forward, 180 = backwards).

player playMove "AinvPknlMstpSlayWrflDnon_medic";

sleep 3.0;

_bSandBarrier = "Land_HBarrier1" createVehicle (position player);

//Find compass direction to spawn from position of reference.

_compassDir = ((getDir _player)+_offdir) mod 360;

//Find absolute coordinates by adding relative to position of reference.

_newX = (_pos select 0) + (sin _compassDir * _dist);

_newY = (_pos select 1) + (cos _compassDir * _dist);

_newPos = [_newX, _newY, 0]; // position found

_bSandBarrier setDir (getDir _player); // set objects direction to same as player, add + 90 to turn it sideways etc...

_bSandBarrier setPos _newPos; // place object of choice on new pos.

_dSandBarrier = _bSandBarrier addAction ["Remove Sand Barrier", "Kays_Scripts\dSandBarrier.sqf"];

_bSandBarrier setDir (getDir player);

sleep 3.0;

exit;

_dSandBarrier.sqf

//Remove Barrier Place by the bSandBarrier Script.

private ["_bSandBarrier","_dSandBarrier"];

_bSandBarrier = _this select 0;

player playMove "AinvPknlMstpSlayWrflDnon_medic";

sleep 3.0;

deleteVehicle _bSandBarrier;

exit;

Share this post


Link to post
Share on other sites

you need to define _player - single player you can change this for player.

or at start _player = _this select 0;

should work.

Share this post


Link to post
Share on other sites

Alright... Thanks Mikie Boy! :)

It Works now. lOL

Silly Me :D

I Did that Before... But I Was Slightly Wrong with how I Went about doing it.

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  

×