Weapon pickups after kill

Started by Gudio, Apr 14, 2015, 07:35 AM

Previous topic - Next topic

Gudio

Requested by @4kUM45 and @Gulk.

First of all we need a function called random which accepts minimum and maximum values in its parameters:
function random( min, max )
{
if ( min < max )
return rand() % (max - min + 1) + min.tointeger();
else if ( min > max )
return rand() % (min - max + 1) + max.tointeger();
else if ( min == max )
return min.tointeger();
}

then we must add a table responsible for deleting pickups when they're picked up:
wepPickups <- {};
next we need a function which will be used in onPlayerDeath/onPlayerKill/onPlayerTeamKill events. (DIY)
function CreatePlayerWeaponPickups( player )
{
for ( local i = 0, world, pos, pickup, weapon; i < 7; i++ )
{
world = player.World;
weapon = player.GetWeaponAtSlot( i );
player.World = player.UniqueWorld;

if ( weapon > 0 && weapon != 16 )
{
pos = player.Pos;
pos.x = random( pos.x - 2, pos.x + 2 );
pos.y = random( pos.y - 2, pos.y + 2 );

pickup = CreatePickup( 258 + weapon, world, player.GetAmmoAtSlot( i ), pos, 255, true );
if ( pickup )
wepPickups.rawset( pickup.ID, pickup );
}
}
}

finally, onPlayerClaimPickup must return true:
function onPickupClaimPicked( player, pickup )
{
if ( player.Health > 0 && wepPickups.rawin( pickup.ID ) )
{
PlaySound( player.UniqueWorld, 78, player.Pos );

wepPickups.rawdelete( pickup.ID );
pickup.Remove();

return 1;
}

return 0;
}

_/
Feel free to add a timer to delete pickups after some time.

Gulk

w00t ye mang! thank you for this

EK.IceFlake

No need for the random function to be so big like that when you can do it all in one line: http://forum.vc-mp.org/?topic=246.0

Kratos_


You might noticed here that I was saying about something like AutoDestroyTimer . Actually , I was too thinking about creating a timer in squirrel native & then removing array/table ( container ) contents .
But , I faced a challenge here . The Challenge was :-



Suppose we create a timer of repeating unit of 10 seconds . Thus , this timer is supposed to delete the table contents after every interval of 10 seconds . Lets assume that there 5 kills occured in this course of 10 seconds & no one picked the pickups , ofcourse
we're creating timer for destroying unpicked pickups .



Kills & Timer Mechanism

=========================================================
   Pickup's Birth    |    Timer    |    Pickup's LifeTime             
=========================================================
1.            0s     |     10s     |      10s
2.            3s     |     10s     |       7s
3.            5s     |     10s     |       5s
4.            7s     |     10s     |       3s
5.           10s     |     10s     |       0s
=========================================================

So , each kind of pickup will have variable life span . Even the last one will cease to appear . I know creating an individual timer associated to each pickup will simply lag the server . We have Pickup.RespawnTimer which starts monitoring the pickup when they are picked up . I therefore want that its the server which will start monitoring pickups at the time when they are created & once their life gets passed , they will be destroyed by the server .

In the middle of chaos , lies opportunity.

4kUM45


W3aPoN^

Hello I am New Here And I Dont Understand What You say So can you please manke a VIDEO/PICTURE tutorial for this PLEASE i am New

Xmair

Quote from: razacharan on Jul 08, 2016, 10:25 AMHello I am New Here And I Dont Understand What You say So can you please manke a VIDEO/PICTURE tutorial for this PLEASE i am New

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

W3aPoN^

#7
P L E A S E - H E L P - M E - B R O :(
I - D O N'T - K N O W - H O W - T O - A D D - T H E M - P L E A S E - M A K E - A - V I D E O/P I C T U R E - T U T O R I A L

Murdock

Quote from: razacharan on Jul 08, 2016, 01:32 PM(spam)

You should not be touching any code, stick to playing