2013martin1212 Posted August 14, 2015 Share Posted August 14, 2015 I cant figure out what i make wrong please help money = { {31, -16, 4 }, {14, 7, 4 }, {19, 1, 3 } } local randomra = createPickup (math.random (#money) , 3, 1274, 20 ) function pickupUse ( player ) givePlayerMoney ( player, 1000 ) end addEventHandler ( "onPickupUse", randomra, pickupUse ) Link to comment
KariiiM Posted August 14, 2015 Share Posted August 14, 2015 The table "money" is for cordinations? X, Y ,Z? Link to comment
KariiiM Posted August 14, 2015 Share Posted August 14, 2015 So, try that money = { [1]={31, -16, 4}, [2]={14, 7, 4}, [3]={19, 1, 3} } local pos = money[math.random(#money)] local x,y,z = unpack ( pos ) local randomra = createPickup (x,y,z, 3, 1274, 20 ) function pickupUse ( player ) givePlayerMoney ( player, 1000 ) end addEventHandler ( "onPickupUse", randomra, pickupUse ) Link to comment
2013martin1212 Posted August 14, 2015 Author Share Posted August 14, 2015 its works,but alway put in the same cordinates, and when i restart the resource then change the cordinates Link to comment
KariiiM Posted August 14, 2015 Share Posted August 14, 2015 Working perfectly, you have to restart the script to change the cordinations. or use setTimer to change the locations with a timer, i added a blip to see it changing the place money = { [1]={31, -16, 4}, [2]={14, 7, 4}, [3]={19, 1, 3} } local pos = money[math.random(#money)] local x,y,z = unpack ( pos ) local randomra = createPickup (x,y,z, 3, 1274,20) local myBlip = createBlipAttachedTo (randomra,52) function pickupUse ( player ) givePlayerMoney ( player, 1000 ) end addEventHandler ( "onPickupUse", randomra, pickupUse) Link to comment
2013martin1212 Posted August 14, 2015 Author Share Posted August 14, 2015 So if i want to make it with set timer then i need to make it like this ? money = { [1]={31, -16, 4}, [2]={14, 7, 4}, [3]={19, 1, 3} } local pos = money[math.random(#money)] local x,y,z = unpack ( pos ) local randomra = createPickup (x,y,z, 3, 1274,20) local myBlip = createBlipAttachedTo (randomra,52) function pickupUse ( player ) givePlayerMoney ( player, 1000 ) end addEventHandler ( "onPickupUse", randomra, pickupUse) setTimer( randomra, 30000, 1) Link to comment
t3wz Posted August 14, 2015 Share Posted August 14, 2015 So if i want to make it with set timer then i need to make it like this ?[...] Nope, you have to destroy the 'old' pickup, create another one and re-add the event handler. also use numeric indexes in the table isn't necessary. this might work: money = { { 31, -16, 4 }, { 4, 7, 4 }, { 19, 1, 3 } } local pickup, blip -- variables that will store the pickup and the blip function generatePickup ( ) -- function that will generate a new pickup -- Check if old pickup exists if pickup and isElement ( pickup ) then destroyElement ( pickup ) -- destroy the pickup destroyElement ( blip ) -- destroy the blip end -- get a position local pos = math.random ( 1, #money ) local x, y, z = unpack ( money[pos] ) -- Create a new pickup and store him in the 'pickup' variable pickup = createPickup ( x, y, z, 3, 1274, 20 ) -- Create the blip... blip = createBlipAttachedTo ( pickup, 52 ) end function pickupUse ( player ) -- Check if source is the pickup created in this script if source == pickup then givePlayerMoney ( player, 1000 ) end end addEventHandler ( "onPickupUse", root, pickupUse) -- for every pickup add the event handler generatePickup() -- call the function to create a pickup for the first time setTimer ( generatePickup, 1 * 60000, 0 ) -- every 1 minute the timer will call the function again, infinite times 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