Matevsz Posted December 22, 2015 Share Posted December 22, 2015 Hi, error in console: WARNING: JobWood\wood.lua:253: Bad argument @ ' addEventHandler ' Expected element at argument 2 got boolean chainsaw = createPickup(-503.60,-77.34,60.5, 9, 3000) addEventHandler("onPickupHit", chainsaw, function(element,dim) if not (getElementType(element) == "player") then return end giveWeapon(element, 9, 1) setPedWeaponSlot(element, 1) end) Link to comment
Enargy, Posted December 22, 2015 Share Posted December 22, 2015 You are getting invalid arguments. Check it out https://wiki.multitheftauto.com/wiki/CreatePickup Link to comment
#RooTs Posted December 22, 2015 Share Posted December 22, 2015 try this chainsaw = createPickup(-503.60,-77.34,60.5, 9, 3000) addEventHandler("onPickupHit", chainsaw, function() for _,v in pairs(getElementsByType("player")) do giveWeapon(v, 9, 1) setPedWeaponSlot(v, 1) end end) Link to comment
Matevsz Posted December 22, 2015 Author Share Posted December 22, 2015 The same error : ( Link to comment
#RooTs Posted December 22, 2015 Share Posted December 22, 2015 try this addEventHandler("onPickupHit", chainsaw, function(plr) for _, v in ipairs (getElementsByType ("player")) do if (plr and plr ~= v) then giveWeapon(v, 9, 1) setPedWeaponSlot(v, 1) end end end) Link to comment
Dealman Posted December 22, 2015 Share Posted December 22, 2015 try this chainsaw = createPickup(-503.60,-77.34,60.5, 9, 3000) addEventHandler("onPickupHit", chainsaw, function() for _,v in pairs(getElementsByType("player")) do giveWeapon(v, 9, 1) setPedWeaponSlot(v, 1) end end) ...This would give the weapon to all players on the server instead of only the guy picking it up. @Matevzsz I'd suggest you write your functions like this instead; function OnPickupHit_Handler(thePlayer) if(source == chainsaw) then giveWeapon(thePlayer, 9, 1) setPedWeaponSlot(thePlayer, 1) end end addEventHandler("onPickupHit", root, OnPickupHit_Handler) Link to comment
Matevsz Posted December 22, 2015 Author Share Posted December 22, 2015 The same : ( And so that work? function Saw(player) for _, v in ipairs(getElementsByType("player")) do if getElementType(player)=="player" then if source == chainsaw then giveWeapon(player, 9, 1) setPedWeaponSlot(player, 1) end end end end) addEventHandler("onPickupHit", getRootElement, Saw) Link to comment
1LoL1 Posted December 22, 2015 Share Posted December 22, 2015 The same : ( And so that work? function Saw(player) for _, v in ipairs(getElementsByType("player")) do if getElementType(player)=="player" then if source == chainsaw then giveWeapon(player, 9, 1) setPedWeaponSlot(player, 1) end end end end) addEventHandler("onPickupHit", getRootElement, Saw) This is for all player in server... for _, v in ipairs(getElementsByType("player")) do Link to comment
Dealman Posted December 22, 2015 Share Posted December 22, 2015 Using my code, what error are you getting? That code doesn't make all too much sense, why are you looping through all the players? for _, v in ipairs(getElementsByType("player")) do if getElementType(player)=="player" then This if statement serves no purpose as it will always pass. getElementsByType will return all the player elements, so there is no need to check if the element type is player. addEventHandler("onPickupHit", getRootElement, Saw) Should be addEventHandler("onPickupHit", getRootElement(), Saw) Link to comment
Matevsz Posted December 22, 2015 Author Share Posted December 22, 2015 Bad argument @ 'addEventHandler ' expected element at argument 2 got nil -- triggerClientEvent("setObjectBreakable", source, false) addEvent("setObjectBreakable", true) addEventHandler("setObjectBreakable", resouceRoot, function(state) setObjectBreakable(source, state) end) And Attempt to call global 'bindKey' (a nil value) local function checkForklift() local v=getPedOccupedVehicle(localPlayer) if not v then return end if getElementModel(v)~=530 then return end local ap=getVehicleadjustableProperty(v) if ap>0 then return end if czyForkliftWiezieObiekty(v) then triggerServerEvent("forklift_opusc", v) else triggerServerEvent("forklift_podnies", v) end end bindKey("special_control_up", "up", checkForklift) bindKey("special_control_down", "up", checkForklift) what's wrong? : / Link to comment
Addlibs Posted December 22, 2015 Share Posted December 22, 2015 Show the code with 'bindKey' function. Link to comment
Matevsz Posted December 22, 2015 Author Share Posted December 22, 2015 Server side: local pila = createPickup(-537.5,-98.599998474121,63.3, 9, 3000) createBlip(-510.68,-100.19,62.98,42,2,255,0,0,255,0,600) -- sciete 1463 (dyn) -- 984, 3275, -- -438.73,-206.80,73.98,15.3 -- -586.51,-28.07,64.32,105.8 local strefa=createColCuboid(-586,-206, 50, 160, 198, 40) setElementID(strefa,"tartak:cs") addEventHandler("onColShapeHit", strefa, function(el,md) if not md then return end if getElementType(el)~="player" then return end end) addEventHandler("onColShapeLeave", strefa, function(el,md) if not md then return end if getElementType(el)~="player" then return end takeWeapon(el,9) end) local maleDrzewa={ 618, 617, 700} -- te tez sie nadaja 776, 732, 730, 729 local duzeDrzewa={ 616, 615, 734, 733, 726} local scieteDrzewa={ 848, 847, 834, 832, 831 } local punkty={ {-461.52,-148.38,73.47}, {-457.87,-154.04,74.61}, {-455.41,-163.37,76.78}, {-448.47,-159.67,75.40}, {-447.23,-139.58,70.04}, {-452.06,-129.05,66.13}, {-444.39,-122.48,64.11}, {-451.17,-107.18,61.60}, {-447.29,-99.55,60.25}, {-455.83,-92.08,59.58}, {-458.88,-83.95,59.76}, {-452.16,-81.03,59.51}, {-448.80,-74.99,59.41}, {-440.93,-79.68,59.05}, {-439.28,-91.01,58.91}, {-439.66,-104.82,60.75}, {-448.12,-118.93,63.36}, {-463.11,-50.33,59.96}, {-458.94,-46.21,59.94}, {-464.86,-43.94,59.96}, {-473.19,-51.01,60.12}, {-479.17,-41.73,60.00}, {-490.81,-46.27,60.29}, {-495.38,-49.95,60.42}, {-519.18,-40.83,61.54}, {-524.98,-47.41,62.14}, {-532.10,-43.61,62.62}, {-538.22,-46.68,63.08}, {-543.03,-44.82,63.38}, {-551.88,-38.86,63.93}, {-528.71,-39.62,62.27}, {-519.95,-50.17,61.80}, {-457.65,-138.68,70.13}, {-468.58,-141.06,71.56}, {-474.94,-149.34,74.34}, {-477.03,-139.00,71.09}, {-485.12,-134.01,69.43}, {-488.93,-141.82,72.75}, {-494.08,-138.39,71.59}, {-496.39,-132.94,69.49}, {-493.71,-124.51,66.74}, {-497.99,-117.62,65.06}, {-494.35,-113.84,64.47}, {-482.84,-112.51,63.77}, {-524.48,-114.92,65.32}, {-539.14,-116.10,66.27}, {-546.40,-107.43,63.89}, {-547.81,-98.72,63.48}, {-554.42,-75.63,63.63}, {-563.47,-74.26,64.17}, {-578.66,-38.70,65.03}, {-571.41,-41.95,64.71}, {-563.26,-38.35,64.40}, {-553.67,-43.80,63.96}, {-546.08,-39.96,63.62}, {-526.75,-26.69,60.45}, {-533.78,-19.86,61.31}, {-544.67,-23.69,63.14}, {-551.14,-16.59,63.12}, {-563.09,-22.91,63.64}, {-580.88,-15.88,63.61}, {-590.11,-35.18,64.25}, {-590.01,-19.22,63.48}, {-521.32,-15.93,59.24}, {-493.14,-17.21,56.79}, {-528.17,-129.33,69.44}, {-528.17,-129.33,69.44}, {-534.15,-137.96,73.15}, {-543.51,-131.48,70.93}, {-555.05,-132.30,71.76}, {-566.87,-150.80,77.32}, } local function czyMaleDrzewo(obiekt) local model=getElementModel(obiekt) for i,v in ipairs(maleDrzewa) do if v==model then return true end end return false end local function czyScieteDrzewo(obiekt) local model=getElementModel(obiekt) for i,v in ipairs(scieteDrzewa) do if v==model then return true end end return false end local function moznaSadzic(x,y,z) local cs=createColSphere(x,y,z,2) local el=getElementsWithinColShape(cs) destroyElement(cs) if #el>0 then return false end return true end local function drzewaSpool() for i,v in ipairs(punkty) do if math.random(1,4)==1 then if not v.obiekt or not isElement(v.obiekt) or getElementType(v.obiekt)~="object" then if moznaSadzic(v[1],v[2],v[3]-0.5) then local oid=maleDrzewa[math.random(1,#maleDrzewa)] v.obiekt=createObject(oid, v[1],v[2],v[3]-1.3) setObjectScale(v.obiekt,0.4) end elseif czyMaleDrzewo(v.obiekt) then local skala=getObjectScale(v.obiekt) if skala<0.99 then setObjectScale(v.obiekt,skala+0.2) else local oid=duzeDrzewa[math.random(1,#duzeDrzewa)] setElementModel(v.obiekt,oid) -- setElementData(v.obiekt,"customAction",{label="Zetnij",resource="lss-tartak",funkcja="menu_zetnij",args={drzewo=v.obiekt}}) setElementData(v.obiekt,"tartak:drzewo", true) end elseif czyScieteDrzewo(v.obiekt) then destroyElement(v.obiekt) v.obiekt=nil end end end end --setTimer(drzewaSpool, 120000,0) setTimer(drzewaSpool, 41000,0) addCommandHandler("drzewaspool", drzewaSpool) -- triggerServerEvent("scieteDrzewo", scinane_drzewo) addEvent("scieteDrzewo", true) addEventHandler("scieteDrzewo", resourceRoot, function() local x,y,z=getElementPosition(source) destroyElement(source) local obiekt=createObject(1463,x,y,z+0.-- s8) --> setElementData(obiekt, "tartak:wood:owner", client) triggerClientEvent("setObjectBreakable", obiekt, false) triggerServerEvent("setPedAnimation", localPlayer, localPlayer) setPedAnimation(client) setTimer(function(obiekt) if obiekt and (getElementType(obiekt)=="object") then setElementData(obiekt, "tartak:wood:owner", false) end end, 60000, 1, obiekt) end) -- triggerServer("forklift_podnies", v, obiekty[1]) addEvent("forklift_podnies", true) addEventHandler("forklift_podnies", root, function() -- szukamy obiektu do podniesienia local x,y,z=getElementPosition(source) local _,_,rz=getElementRotation(source) local rrz=math.rad(rz+180) local x= x - (2*math.sin(-rrz)) local y= y - (2*math.cos(-rrz)) local strefa=createColSphere(x,y,z,1) local obiekty=getElementsWithinColShape(strefa,"object") destroyElement(strefa) -- outputDebugString(#obiekty) if #obiekty~=1 then return end if getElementModel(obiekty[1])~=1463 then return end local plr = getVehicleOccupant(source) if not plr then return end local owner = getElementData(obiekty[1], "tartak:wood:owner") or false if (owner) and (owner~=plr) then return end attachElements(obiekty[1],source, 0,1.2,0.3) -- attachRotationAdjusted(obiekty[1],source) end) addEvent("forklift_opusc", true) addEventHandler("forklift_opusc", root, function() local elementy=getAttachedElements(source) for i,v in ipairs(elementy) do if getElementType(v)=="object" then detachElements(v,source) local x,y,z=getElementPosition(source) local _,_,rz=getElementRotation(source) local rrz=math.rad(rz+180) local x= x - (2*math.sin(-rrz)) local y= y - (2*math.cos(-rrz)) setElementPosition(v,x,y,z-0.3) end end end) local CONTAINER_ID=2462 local ITEMID=67 local m=createMarker(-488.08,-179.94,77.21,"cylinder", 4.5,100,100,100,100) local m2=createMarker(-536.98,-74.41,61.86,"cylinder", 4.5, 100,100,100,100) local m3=createMarker(-528.71,-60.98,61.97,"cylinder", 4.5, 100,100,100,100) local m4=createMarker(-472.82,-180.96,77.21,"cylinder", 4.5, 100,100,100,100) local function znajdzWiezioneDrzewo(p) local elementy=getAttachedElements(p) for i,v in ipairs(elementy) do if getElementType(v)=="object" and getElementModel(v)==1463 then return v end end return nul end local function przyjecieDrzewa(el,md) if not md then return end if getElementType(el)~="vehicle" then return end if getElementModel(el)~=530 then return end local drzewo=znajdzWiezioneDrzewo(el) if not drzewo then return end destroyElement(drzewo) triggerEvent("broadcastCaptionedEvent", getVehicleController(el), getPlayerName(getVehicleController(el)).."", 4, 10, true) setElementFrozen(el,true) setTimer(function(el) local money = math.random(10,25) givePlayerMoney(el, money) setElementFrozen(el,false) end, 5000, 1, el) 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