aintaro Posted June 9, 2014 Share Posted June 9, 2014 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
Den. Posted June 9, 2014 Share Posted June 9, 2014 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
aintaro Posted June 9, 2014 Author Share Posted June 9, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now