Auto-Removing Pickups

Started by 3416, May 13, 2020, 08:58 PM

Previous topic - Next topic

3416

Hello everyone, hope you have a nice day.
I want the pickup created to be auto-removed in about 5 seconds if it stays idle and nobody touches it.
If a pickup is created like this:
function onPlayerCommand ( player, cmd, text )
if ( cmd == "pick" )
{
CreatePickup(368, player.World, 50, Vector(player.Pos.x, player.Pos.y, player.Pos.z), 255, true);
}


Please give an example, I will try my best to implement.

umar4911

Explain a bit more. You create a pickup using the command. If no one enters the pickup within 5 seconds, it is auto removed. Right na?
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

3416

Quote from: umar4911 on May 15, 2020, 08:24 AMExplain a bit more. You create a pickup using the command. If no one enters the pickup within 5 seconds, it is auto removed. Right na?
Yes!

umar4911

Quote from: 3416 on May 15, 2020, 09:26 AM
Quote from: umar4911 on May 15, 2020, 08:24 AMExplain a bit more. You create a pickup using the command. If no one enters the pickup within 5 seconds, it is auto removed. Right na?
Yes!
If you are doing with only 1 pickup:
Store the pickup id in an array/table with a false value when creating the pickup. Create a Timer to check the pickup
PickupEntered <- [];
 function onPlayerCommand ( player, cmd, text )
if ( cmd == "pick" )
{
local pic = CreatePickup(368, player.World, 50, Vector(player.Pos.x, player.Pos.y, player.Pos.z), 255, true);
PickupEntered <- [pic.ID, false];
NewTimer("checkpickup", 5000, 1);
}
On the event OnPickupPickedUp, change the value of false to true;
function onPickupPickedUp( player, pickup )
{
if(pickup.ID == PickupEntered[0])
{
PickupEntered[1] <- true;
}
}

The function checkpickup
function checkpickup()
{
 if(PickupEntered[1] == false)
{
local pickup = FindPickup(PickupEntered[0]);
if(pickup) pickup.Remove();
}
}
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

habi

#4
i will post my version. Before that i want to tell you
Vector(player.Pos.x, player.Pos.y, player.Pos.z) equals as player.Pos

here is my version.
function onPlayerCommand ( player, cmd, text )
if ( cmd == "pick" )
{
local pickup = CreatePickup(368, 0, 50, player.Pos, 254, true);
NewTimer( "check", 5000, 1, pickup.ID );
}
Note that 254
function check( id )
{
      local pickup=FindPickup(id);
      if( pickup )pickup.Remove();
}
function onPickupPickedUp( player, pickup )
{
      if(pickup.Alpha==254)pickup.Remove();
}
Again, note that 254

I hope you understood. There is a problem in this. The player is typing command "pick" and pickup is created. Where is the pickup created? Exactly where the player is standing. So what happens. It gets pickup up by the player automatically.

Or you can try
local pickup = CreatePickup(368, 0, 50, player.Pos+Vector(10,0,0), 254, true);to create pickup at a distance 10 meters.

=RK=MarineForce

if ( cmd == "pick" )
{
hp <- CreatePickup(368, Vector(-1195.89, 108.588, 11.1278));
NewTimer( "hp", 5000, 1, pickup.ID );
}
function onPickupPickedUp( player, pickup )
{
  if( pickup.Model == 368 ) 
{
hp.Remove();

}
 }

function hp( player, pickup ){
    if( pickup.Model == 368 ) {
    hp.Remove();
}}

hp.Remove(); // to remove

3416

Thanks for the help everyone. I got the idea from habi's example :) . And other ones were helpful too.