Hello everyone, I know this is a really noobish question but
How do I make a timer start then I drop a weapon and if that weapon is not picked up before 5 mins it get deleted and if it gets picked up the timer gets removed??
In your drop-script ( which should be server-side ) do something like:
[lua]// OnDrop -- there should be a reference to the weapon entity, we'll assume variable is_w
if ( IsValid( _w ) ) then
// Give it a unique name; could be done with timer.Simple but if players drop 100 times, you'll have 100 timers, lets only create 1 max per weapon
timer.Create( "delete_dropped_weapon_" .. _w:EntIndex( ), 60 * 5, 1, function( )
// Make sure the weapon is still valid, and that it is still a weapon, and make sure there is no owner; self.Owner gets unset when dropped
if ( IsValid( _w ) && _w:IsWeapon( ) && !IsValid( self.Owner ) ) then
// If those conditions are true, then remove the entity ( this checks IsValid, etc too )..
SafeRemoveEntity( _w );
end
end );
end[/lua]
Also, since you have a static timer name, OnPickup you can simple do timer.Destroy( "delete_dropped_weapon" .. _w:EntIndex( ) ); to remove the timer..
Sorry, you need to Log In to post a reply to this thread.