Setting a Weapon Pickup with Cost.

Started by JhonDude, Oct 03, 2022, 02:29 PM

Previous topic - Next topic

JhonDude

Hello Guys!
Im tryna set a Weapon Pickup with some conditions:
1 - When a player touch the pickup, if he's had money, he buy it.
Otherwise, the message: "You need more money" appears.
2 - If player already have the Weapon, the message:
"You do not need buy this weapon again" appears.

The idea is simple, but if the player change the weapon slot,
he buy the same weapon again, even already in use.

How can i fix this?
I try the "player.SetWeaponAtSlot( )" but withouth succes.

My code is something like this:
function onPickupPickedUp( player, pickup )
{
  if( pickup.Model == 366 ) 
{
if(player.Cash < 500) MessagePlayer("[#00cc00] Need enough money!",player);
else{
 player.SetWeapon( 10, 999 );
MessagePlayer(" You got a Pump-Shotgun",player);
}
}

PSL

function onPickupPickedUp( player, pickup )
{
  if( pickup.Model == 366 ) 
{
if(player.Cash < 500) MessagePlayer("[#00cc00] Need enough money!",player);
else if(player.GetWeaponAtSlot(4)==10) MessagePlayer("[#00cc00] It's a weapon you already have!",player);
else{
 player.SetWeapon( 10, 999 );
MessagePlayer(" You got a Pump-Shotgun",player);
}
}

This link may help you: http://wiki.adtec.ovh/wiki/Scripting/Squirrel/Functions/Player.GetWeaponAtSlot

JhonDude

Quote from: PSL on Oct 04, 2022, 03:18 AMfunction onPickupPickedUp( player, pickup )
{
  if( pickup.Model == 366 ) 
{
if(player.Cash < 500) MessagePlayer("[#00cc00] Need enough money!",player);
else if(player.GetWeaponAtSlot(4)==10) MessagePlayer("[#00cc00] It's a weapon you already have!",player);
else{
 player.SetWeapon( 10, 999 );
MessagePlayer(" You got a Pump-Shotgun",player);
}
}

This link may help you: http://wiki.adtec.ovh/wiki/Scripting/Squirrel/Functions/Player.GetWeaponAtSlot

Thankyou so much man!
So, the correct syntax is: player.GetWeaponAtSlot( slot )
Can't wait for test this one!

And tnx for the wiki link!
The site content will help me a lot!

I coming soon for show you the results!

JhonDude

Thank you so much man! It works!
I just create the pickups i wanted in Ammu-Nation, like armor, pistol, and rifles.
It´s a simple Touch N' Buy system.

The code exemple:
PickupPickedUp( player, pickup )
{
  if( pickup.Model == 280 ) 
{
if(player.Cash < 1200) MessagePlayer("[#00cc00] You need $1200 to buy an M4 Rifle!",player);
else if(player.GetWeaponAtSlot(6)==26) MessagePlayer("[#00cc00] You don't need to buy this weapon again!",player);
else{
 player.SetWeapon( 26, 120 );
MessagePlayer(" You buy an M4 Rifle! Thank you!",player);
}
}

The same code works fine to other stuffs like grenades, knifes or Health pickups!
Thanks PSL dude!
CLOSED!