Jump to content

Vehicle hit pickup


aintaro

Recommended Posts

Hello,

How can i make that when a player is in a vehicle and hits a pickup he gets a reward for it.

I tried using the event : onPickupHit (server sided) but I do not get the message "you have picked up a m4"; why is that?

I used the wiki code :

local aPickup = createPickup ( 10.0, 10.0, 10.0, 2, 31, 3000, 50 ) --Create an M4 weapon pickup when script starts 
  
function pickedUpWeaponCheck ( player ) 
   outputChatBox ( "You have picked up a M4.", player ) --Display this message in the chat box 
end 
addEventHandler ( "onPickupHit", aPickup, pickedUpWeaponCheck ) 

thanks in advance,

greetz Aintaro

Link to comment

Because the element that hit the pickup would be the vehicle, not the player driving it.

Try this:

function pickedUpWeaponCheck ( hitElement ) 
   local etype = getElementType(hitElement) 
   local thePlayer = etype == 'player' and hitElement or false --If the element type is a player, then store the player in thePlayer var. 
   if etype == 'vehicle' then --if it's a vehicle, get it's controller. 
        thePlayer = getVehicleController(hitElement) 
  end 
  if thePlayer then 
     outputChatBox ( "You have picked up a M4.", thePlayer ) 
  end 
end 
addEventHandler ( "onPickupHit", aPickup, pickedUpWeaponCheck ) 

Link to comment
Because the element that hit the pickup would be the vehicle, not the player driving it.

Try this:

function pickedUpWeaponCheck ( hitElement ) 
   local etype = getElementType(hitElement) 
   local thePlayer = etype == 'player' and hitElement or false --If the element type is a player, then store the player in thePlayer var. 
   if etype == 'vehicle' then --if it's a vehicle, get it's controller. 
        thePlayer = getVehicleController(hitElement) 
  end 
  if thePlayer then 
     outputChatBox ( "You have picked up a M4.", thePlayer ) 
  end 
end 
addEventHandler ( "onPickupHit", aPickup, pickedUpWeaponCheck ) 

ahh that makes sense, thanks it worked!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...