Jump to content
Sign in to follow this  
ravsun

Random weapon/ammo with Gamelogic Using Weaponholder

Recommended Posts

So I was looking for a script that can spawn/respawn weapons and ammo on the ground.

_ammobox = _this select 0;

       //create a random number
_rNumber = ceil (random 10);

       //add _rNumber * 10 magazines....so 10 for each gun
_ammobox addMagazineCargo ["20Rnd_556x45_Stanag",_rNumber * 10];

       //add _rNumber weapons to the box 
_ammobox addWeaponCargo ["m16a4",_rNumber];

sleep 8800;
}

Error in log:

Description of unexpected vehicle:

Any way around this? Or a better script?

Thanks

Ravsun

Share this post


Link to post
Share on other sites

I remove it.

Im calling the script with:

ammobox = "WeaponHolder" createVehicle getPos this; nul = [this] execVM "fillammobox.sqf";

still cant get it to work.

Share this post


Link to post
Share on other sites

Try

ammobox = "WeaponHolder" createVehicle getPos this; nul = [ammobox] execVM "fillammobox.sqf";

Share this post


Link to post
Share on other sites

Seems a little funky, but this works:

myammobox = "WeaponHolder" createVehicle getPos this; nul = [myammobox] execVM "fillammobox.sqf";

Make sure you're not using [this] in the execVM since you don't want it running on the Game Logic but on the weapon holder instead.

Also make sure your gamelogic isn't grouped with any other modules. I ran into that problem, the Game Logic was moving to be "in formation" with whatever other module it had grouped with. So select "None" or ungroup it to make sure it stays where you wanted it.

That sleep in your script doesn't do anything either, since it's not looping. You'd want to wrap it in something like a while alive check.

Share this post


Link to post
Share on other sites

Still doesent work.

fillammobox.sqf

_ammobox = _this select 0;

while {alive _ammobox} do {

//clear the ammo box
clearweaponcargo _ammobox;
clearmagazinecargo _ammobox;

//create a random number
_rNumber = ceil (random 10);

//add _rNumber * 10 magazines....so 10 for each gun
_ammobox addMagazineCargo ["20Rnd_556x45_Stanag",_rNumber * 10];

//add _rNumber weapons to the box 
_ammobox addWeaponCargo ["m16a4",_rNumber];

sleep 8800;

Game logic init:

ammobox = "WeaponHolder" createVehicle getPos this; nul = [ammobox] execVM "fillammobox.sqf";

Share this post


Link to post
Share on other sites

Seems clearWeaponCargo or clearMagazineCargo is actually deleteing the weaponholder. Try this:

GameLogic init:

nul = [this] execVM "fillammobox.sqf";

fillammobox.sqf:

private ["_ammobox","_loc"];

_loc = _this select 0;
_ammobox = "WeaponHolder" createVehicle getPos _loc;

while {alive _ammobox} do {


//create a random number
_rNumber = ceil (random 2);

//add _rNumber * 10 magazines....so 10 for each gun
_ammobox addMagazineCargo ["20Rnd_556x45_Stanag",_rNumber * 10];

//add _rNumber weapons to the box 
_ammobox addWeaponCargo ["m16a4",_rNumber];

sleep 8800;

//clear the ammo box
clearweaponcargo _ammobox;
clearmagazinecargo _ammobox;
nul = [_loc] execVM "fillammobox.sqf";

};

Share this post


Link to post
Share on other sites

I am also trying to get these to spawn in buildings.. I am having trouble setting the height.

this setPos [getPos this select 0, getPos this select 1,<height>];

In init I think is being overwritten by:

_ammobox = "WeaponHolder" createVehicle getPos _loc;

I tryed adding :

_loc setPos [getPos _loc select 0, getPos _loc select 1,2];

but it doesent work..

Thanks

Share this post


Link to post
Share on other sites

To place an object inside a building you need to use the full version of createvehicle

_ammobox = createVehicle [ "WeaponHolder",[getPos _loc select 0, getpos _loc select 1,2],[], 0, "can_collide"];

Share this post


Link to post
Share on other sites

Scripts works great now.

Thanks!!!

---------- Post added at 18:46 ---------- Previous post was at 18:03 ----------

I have one other issue..

I have an object with an addaction on it.. now it works outside but every time i move it into a building the addaction stops working.

Any Ideas?

this addAction["Take Canned Beans", "scripts\takef.sqf"]; this setPos [getPos this select 0, getPos this select 1,0.4];

Share this post


Link to post
Share on other sites

Some items can't be seen inside buildings from what I can tell such as "can", "baseball" other items can be seen "dog tags", "bucket".

Even cursortarget won't return anything but the building for some items, the only work around I can think of is to place the can on an object that can be detected and add the action to that.

Place beans on top of a table or tv.

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  

×