Jump to content
Sign in to follow this  
Liamsmith

Sleep & Vehicle Spawn

Recommended Posts

Hi, so i`m making an script where you press a button,eg f2, to spawn an vehicle. I was looking for help as you can easily spam it and blow the vehicles up. Also, i`m going to have multiple vehicles that will be able spawn and so if one vehicle spawns give it a delay before a different one is.  Would be great if you died you had no delay and could spawn in a vehicle straight away.

 

Vehicle_Spawn.sqf

 

0 = [] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown", {
    if(_this select 1 == 0x3C) 
    then {
    createVehicle ["O_MRAP_02_F",player getPos [15,getDir player], [], 0, "CAN_COLLIDE"];
    };
}];
};

 

Something Like This For The End Result

 

0 = [] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown", {
    if(_this select 1 == 0x3C) 
    then {
    createVehicle ["O_MRAP_02_F",player getPos [15,getDir player], [], 0, "CAN_COLLIDE"];
    };
}];
};

0 = [] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown", {
    if(_this select 1 == 0x3C) 
    then {
    createVehicle ["O_MRAP_02_F",player getPos [15,getDir player], [], 0, "CAN_COLLIDE"];
    };
}];
};

---------------------------

Update when i spawn in the ifrits 2 spawn so they blow up.

Share this post


Link to post
Share on other sites

Replace "CAN_COLLIDE" with "NONE", or any of the other options depending on your needs. Have a look at the alternative syntax - createVehicle - and look at what is said about "CAN_COLLIDE".

Share this post


Link to post
Share on other sites

Out of interest how could i pause the script so the vehicle is spam spawn and lags everyone out. Thanks

Share this post


Link to post
Share on other sites
3 minutes ago, Liamsmith said:

Out of interest how could i pause the script so the vehicle is spam spawn and lags everyone out. Thanks

 

Doubt you will get an answer to that, since it disrupts gameplay.

 

Cheers

Share this post


Link to post
Share on other sites

Do you mean you want to avoid people spamming the script? Because your question translates as you wanting to lag everyone out. 

  • Like 1

Share this post


Link to post
Share on other sites

Yes, is there anyway to rework the script so you can only spawn a vehicle once every life time or anything just to stop spamming it.

Share this post


Link to post
Share on other sites
2 hours ago, Liamsmith said:

Yes, is there anyway to rework the script so you can only spawn a vehicle once every life time or anything just to stop spamming it.

 

You could restrict it to only allow spawning once every n seconds, but a better approach would be to allow spawning only if the player is a certain distance away from the last spawned vehicle.

Something like this:

 

0 = [] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown", {

	_lastVehPos = player getVariable ["TAG_fnc_lastSpawnedVehPos",[0,0,0]];

    if(_this select 1 == 0x3C AND player distance _lastVehPos > 15) 
    then {
    _veh = createVehicle ["O_MRAP_02_F",player getPos [15,getDir player], [], 0, "NONE"];
	player setVariable ["TAG_fnc_lastSpawnedVehPos",getposATL _veh];
    };
}];
}; 

Cheers

Share this post


Link to post
Share on other sites
23 minutes ago, Grumpy Old Man said:

 

You could restrict it to only allow spawning once every n seconds, but a better approach would be to allow spawning only if the player is a certain distance away from the last spawned vehicle.

Something like this:

 


0 = [] spawn {
    waitUntil {!isNull(findDisplay 46)};
    (findDisplay 46) displayAddEventHandler ["KeyDown", {

	_lastVehPos = player getVariable ["TAG_fnc_lastSpawnedVehPos",[0,0,0]];

    if(_this select 1 == 0x3C AND player distance _lastVehPos > 15) 
    then {
    _veh = createVehicle ["O_MRAP_02_F",player getPos [15,getDir player], [], 0, "NONE"];
	player setVariable ["TAG_fnc_lastSpawnedVehPos",getposATL _veh];
    };
}];
}; 

Cheers

When i spawn in vehicles 2 spawn instead of 1. The anitspam is perfect now.

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  

×