onPickupPickedUp doesnt work

Started by Kewun, Aug 07, 2016, 09:56 AM

Previous topic - Next topic

Kewun

function onPickupPickedUp(player,pickup)
{
if (pickup.Model == 262)
{
pickup.Respawn();
player.GiveWeapon(4,1)
return 1;
}
if ( pickup.Model == 274)
{
if (player.Cash < 250)
{
MessagePlayer("[#ffffff]You dont have enought cash to buy colt45, need $250",player)
pickup.Respawn();
return false;
}
player.GiveWeapon(17,250)
player.Cash -= 250;
SaveAccount(player)
pickup.Respawn()
return 1;
}
if ( pickup.Model == 277)
{
if (player.Cash < 250)
{
MessagePlayer("[#ffffff]You dont have enought cash to buy shotgun, need $900",player)
pickup.Respawn();
return false;
}
player.GiveWeapon(19,70)
player.Cash -= 900;
SaveAccount(player)
pickup.Respawn()
return 1;
}
if (pickup.Model==366)
{
player.Health = 100;
return 1;
}
if (pickup.Model ==368)
{
player.Armour = 100
return 1;
}
if ( pickup.Model == 283)
{
if (player.Cash < 250)
{
MessagePlayer("[#ffffff]You dont have enought cash to buy uzi, you need $500",player)
pickup.Respawn();
return false;
}
player.GiveWeapon(24,200)
player.Cash -= 500;
pickup.Respawn()
SaveAccount(player)
return 1;
}
return 1;
}

doesnt work, i cant pickup the pickups still. no errors in the console

Mötley

Can you describe a little more as to why you can not pick them up?

if (pickup.Model == 262)
 {
 pickup.Respawn();

Why are you doing that :o ?

Kewun

why not? i just cant pick them up, i walk in them, they dont disaper and i dont get weps

Mötley

#3
Okay I will script something for you, I might change that entire code, Also you can not remove weapon pickups. you can set the alpha. give me a few. I will send a "Untested code" and see if it helps



Pretty lazy with scripting this, But test this and see what happens....

//------------------------------------------------------------------------------

function onPickupPickedUp(player, pickup) {

    local cash = player.Cash, iModel = pickup.Model;
    switch( iModel ) {
 
    //Nigtht Stick Pickup
    case 262:
      player.SetWeapon(4,1);
      break;
    //Colt Pickup
    case 274:
      if (cash < 250) {
         MessagePlayer("[#ffffff]You dont have enought cash to buy colt45, need $250",player);
         return false;
      }
      player.SetWeapon(17,250);
      break;
    //Chrome Shotgun Pickup
    case 277:
      if (cash < 250) {
         MessagePlayer("[#ffffff]You dont have enought cash to buy shotgun, need $250",player);
         return false;
      }
      player.SetWeapon(19,70)
      break;
    }
    return true;
}

//------------------------------------------------------------------------------

jayant

pickup.Remove() it will remove, to respawn pickup.RespawnTime = time in milliseconds

Mötley

#5
Thanks @jayant!

 :P
                    /*Weapon Script "Alpha"*/

//------------------------------------------------------------------------------

function RespawnPickups(model, x, y, z, respawn=500) {
  local iWeapon = CreatePickup(model, Vector(x, y, z));
  iWeapon.RespawnTime = respawn;
 
  return iWeapon;
}

//------------------------------------------------------------------------------

function onScriptLoad() {
  RespawnPickups(262, -1111.0, 111.0, 10.0);//Nigtht Stick Pickup
  RespawnPickups(274, -1111.0, 111.0, 10.0);//Colt Pickup
  RespawnPickups(277, -1111.0, 111.0, 10.0);//Chrome Shotgun Pickup
 
  ::print("Weapon.nut loaded");
 
  return true;
}

//------------------------------------------------------------------------------

function onPickupPickedUp(player, pickup) {

    local cash = player.Cash, iModel = pickup.Model;
    switch( iModel ) {
 
    //Nigtht Stick Pickup
    case 262:
      player.SetWeapon(4,1);
      pickup.Remove();
      break;
    //Colt Pickup
    case 274:
      if (cash < 250) {
         MessagePlayer("[#ffffff]You dont have enought cash to buy colt45, need $250",player);
         return false;
      }
      player.SetWeapon(17,250);
      pickup.Remove();
      break;
    //Chrome Shotgun Pickup
    case 277:
      if (cash < 250) {
         MessagePlayer("[#ffffff]You dont have enought cash to buy shotgun, need $250",player);
         return false;
      }
      player.SetWeapon(19,70);
      pickup.Remove();
      break;
 
 
    }

return true;
}

//------------------------------------------------------------------------------

Kewun

ill test after 5 days, im not  home now, im in czech republic.

Mötley

Okay :). I'm a little rusty on knowledge BUT on the create weapon function you might need to add iWeapon.Life = 599; maybe @Doomkill3r or @KAKAN will respond to correct me and view that script.

DizzasTeR

Just use the following syntax to create weapon pickups which will give you the ammo/gun, this was taken from this topic. You can fill your own values in it:
CreatePickup( 258 + weapon_ID, world, ammo, position 255, true )
You can also add pickup.RespawnTime = time_in_miliseconds to make the pickup respawn after the desired time

Mötley

#9
But what about proper removal? That's what I would really like to see. Of does that function cover it? I've done almost exactly similar but the weapons never refreshed. That's why I think iWeapon.Life will help if placed in the right area. Either on player pickup or on weapon function

KAKAN

@Kewun, check your onPickupClaimPicked function.
Check whether it returns true or false. And too, if it has nothing it, just add a return 1; to it or simply add your code to that function.
oh no

Kewun


Mötley

Well @Kewun feel free to play with my version as well as if you can not recreate the weapons after removal there is one more opportunity,

You could create a loop method, Create some arrays, or you could use a class. And for each weapon pickup create an array so that the server can check the values on that specific weapon model pickup,. If that value is not zero Set that array to 0 and create the weapon pickups for the array values that returned 1.

Depending on how many weapon pickups you have will determine how many arrays you will need and how many  times you will use CreatePickup for each array, This is slightly tricky, But if you need help I can help you build this with this, Hopefully with help from others from the VCMP community.


It's more complicating to explain but I already know how I would need to do it.

Kewun

k, wait 5 days. im in czech republic ;c

Kewun