DzMG-LV Posted July 8, 2015 Share Posted July 8, 2015 (edited) Hey so i want to make lumberjack job, what functions i need to use? I want to i can destroy tree only with chainsaw, so getcontrolstate? Offcourse createObject, moveObject but i want to make about 20-40 tree's so i need make tables, how? Edited July 10, 2015 by Guest Link to comment
xXMADEXx Posted July 9, 2015 Share Posted July 9, 2015 You can just use a for loop, and then insert the created tree into an array/table... See my tutorial to learn about loops & tables. Link to comment
DzMG-LV Posted July 9, 2015 Author Share Posted July 9, 2015 So i made table and tree spawner, trees spawn and everything work's fine but now what i need to do to destroy trees only with chainsaw? And i can destroy individualy tree's so if i destroy one tree, them all doesn't destroy Link to comment
Dealman Posted July 9, 2015 Share Posted July 9, 2015 Umm, I think there's already a resource that lets you do this - so you'd be best off looking at that I guess. I don't know whether it's compiled or not. Personally though, I'd probably attach something like a collision box or cylinder to each tree, and check if a player is near it. If a player is near it, then check if he's wielding a chainsaw. If he is wielding a chainsaw, then you can check whether the player is performing a certain action and/or animation. If all of the above are true, you can do whatever you want. Decrease the "health" of the tree or simply make it fall over. Link to comment
DzMG-LV Posted July 9, 2015 Author Share Posted July 9, 2015 Umm, I think there's already a resource that lets you do this - so you'd be best off looking at that I guess. I don't know whether it's compiled or not.Personally though, I'd probably attach something like a collision box or cylinder to each tree, and check if a player is near it. If a player is near it, then check if he's wielding a chainsaw. If he is wielding a chainsaw, then you can check whether the player is performing a certain action and/or animation. If all of the above are true, you can do whatever you want. Decrease the "health" of the tree or simply make it fall over. I found one resource, but it's destroy only trees that allready is on map, but i want when i can destroy only trees what i make. That resource: local length = 3 function onClientPlayerWeaponSwitch( prevSlot, newSlot ) if getPedWeapon( localPlayer, newSlot ) == 9 then addEventHandler( "onClientPreRender", root, onClientChainsawRender ) else removeEventHandler( "onClientPreRender", root, onClientChainsawRender ) end end function onClientChainsawRender() local x, y, z = getElementPosition( localPlayer ) local _, _, rz = getElementRotation( localPlayer ) local tx = x + - ( length ) * math.sin( math.rad( rz ) ) local ty = y + length * math.cos( math.rad( rz ) ) local tz = z if getControlState( "fire" ) and getPedWeapon( localPlayer ) == 9 then local hit, hitX, hitY, hitZ, hitElement, normalX, normalY, normalZ, material, lighting, piece, worldID, worldX, worldY, worldZ, worldRX, worldRY, worldRZ, worldLODID = processLineOfSight( x, y, z, tx, ty, tz, true, false, false, true, true, false, false, false, localPlayer, true, false ) if worldID and not startwoodtick and treelist[worldID] then local treename = treelist[worldID].name local interior = getElementInterior( localPlayer ) if not startwoodtick then local anora = findDaVowel( treename ) startwoodtick = getTickCount() triggerServerEvent( "onPlayerChopTree", localPlayer, worldID, worldX, worldY, worldZ, worldRX, worldRY, worldRZ, worldLODID, interior ) outputChatBox( "You chopped down " .. anora .. " " .. treename, 0, 150, 0, false ) end end if worldID then --dxDrawText( worldID, 300, 300 ) end end if startwoodtick then currenttick = getTickCount() - startwoodtick if currenttick >= 2000 then chopping = false startwoodtick = nil end --dxDrawText( currenttick, 300, 300 ) end --dxDrawLine3D( x, y, z, tx, ty, tz ) end function findDaVowel( string ) if vowels[string.sub( string:lower(), 1, 1 )] then return "an" else return "a" end end addEventHandler( "onClientPlayerWeaponSwitch", localPlayer, onClientPlayerWeaponSwitch ) addEvent( "onPlayerChopTree", true ) function onPlayerChopTree( worldID, worldX, worldY, worldZ, worldRX, worldRY, worldRZ, worldLODID, interior ) removeWorldModel( worldID, 3, worldX, worldY, worldZ, interior ) removeWorldModel( worldLODID, 3, worldX, worldY, worldZ, interior ) local _, _, rz = getElementRotation( client ) local tree = createObject( worldID, worldX, worldY, worldZ, worldRX, worldRY, worldRZ ) setTimer( setElementCollisionsEnabled, 1000, 1, tree, false ) moveObject( tree, 4000, worldX, worldY, worldZ, 0, 87, 0, "OutBounce" ) setTimer( destroyElement, 4000, 1, tree ) end addEventHandler( "onPlayerChopTree", root, onPlayerChopTree ) vowels = { ["a"] = true, ["e"] = true, ["i"] = true, ["o"] = true, ["u"] = true } treelist = { -- Palm trees [712] = { name = "Sabal Palm" }, [621] = { name = "Mexican Palmetto" }, [620] = { name = "Alexandra Palm" }, [740] = { name = "King Palm" }, [645] = { name = "Nameless Palm" }, [739] = { name = "Nameless Palm" }, --[1308] = { name = "Lamppost" }, --[3244] = { name = "fucking Powerline" }, } Link to comment
DzMG-LV Posted July 10, 2015 Author Share Posted July 10, 2015 This is how look's my code: local trees = { [1] = {-484.4150390625, 255.3173828125, 10.426992034912}, [2] = {-463.896484375, 237.416015625, 8.895622634888}, [3] = {-482.517578125, 239.1279296875, 8.625471115112}, [4] = {-472.65234375, 228.0791015625, 8.8162612915039}, [5] = {-470.142578125, 256.544921875, 11.23747253418}, [6] = {-478.2216796875, 247.34375, 10.336027145386}, [7] = {-458.5439453125, 247.8505859375, 10.141387939453}, [8] = {-464.2568359375, 252.0986328125, 10.779546737671} } function spawnTrees() for i, tree in ipairs(trees) do local x, y, z = tree[1], tree[2], tree[3] object = createObject(726, x, y, z, 0, 0, 0 ) setElementData(object, "tree", true) end end spawnTrees() How can i destroy them only with chainsaw? And individualy? Link to comment
DzMG-LV Posted July 10, 2015 Author Share Posted July 10, 2015 So i made new version, but how can i make when if player hit tree with chainsaw only, the tree fall? local tree1 = createColRectangle ( -471.30078125, 246.748046875, 10.449155807495, 0.012 ) function onPlayerChopTree2 () triggerClientEvent("playTreeSound", source) setTimer( function() moveObject(treeObj2, time, -471.30078125, 246.748046875, 10.449155807495, 100, 0, 0, "OutBounce" ) koks2 = createObject ( 1463, -468.6875, 246.5205078125, 10.9, 0, 0, 0 ) end, 2000, 1 ) setTimer( function() destroyElement(treeObj2) end, 15000, 1 ) destroyElement(tree1) end addEventHandler ( "onColShapeHit", tree1, onPlayerChopTree2) Link to comment
Calculador Posted July 10, 2015 Share Posted July 10, 2015 So i made new version, but how can i make when if player hit tree with chainsaw only, the tree fall? local tree1 = createColRectangle ( -471.30078125, 246.748046875, 10.449155807495, 0.012 ) function onPlayerChopTree2 () triggerClientEvent("playTreeSound", source) setTimer( function() moveObject(treeObj2, time, -471.30078125, 246.748046875, 10.449155807495, 100, 0, 0, "OutBounce" ) koks2 = createObject ( 1463, -468.6875, 246.5205078125, 10.9, 0, 0, 0 ) end, 2000, 1 ) setTimer( function() destroyElement(treeObj2) end, 15000, 1 ) destroyElement(tree1) end addEventHandler ( "onColShapeHit", tree1, onPlayerChopTree2) Specifies if the player entered with chainsaw weapon. Link to comment
DzMG-LV Posted July 10, 2015 Author Share Posted July 10, 2015 What's wrong here? Trees spawn, but it doesn't destroy. Client: ae=addEvent aeh=addEventHandler tse=triggerServerEvent lp=localPlayer sendtick = getTickCount() local trees = {} local peds = {} local blips = {} ae("recTree",true) aeh("recTree",lp,function(tree) table.insert(trees,tree) local x,y,z = getElementPosition(tree) blips[tree] = createBlip(x,y,z,0) end) ae("remTree",true) aeh("remTree",lp,function(tree) for k,v in pairs(trees) do if v == tree then table.remove(trees,k) destroyElement(blips[tree]) end end end) ae("treeFall",true) aeh("treeFall",lp,function( ... ) local tree = createObject( ... ) local x,y,z = getElementPosition(tree) --[[setTimer(function() local rx = getElementRotation(tree) local x,y,z = getElementPosition(tree) setElementPosition(tree,x,y,z-0.3) setElementRotation(tree,rx-1,0,0) end,50,111)--]] setElementCollisionsEnabled(tree,false) moveObject(tree,6000,x,y,z-10,0,90,90) setTimer(function() local x,y,z = getElementPosition(tree) moveObject(tree,5000,x,y,z-5) setTimer(destroyElement,5000,1,tree) --if blips[tree] then destroyElement(blips[tree]) end end,6000,1) end) aeh("onClientPedDamage",root,function(atk,wep) if getElementData(source,"l") and wep ~= 9 then cancelEvent() end end) Server: local treeE = {} local peds = {} local trees = {} local made = {} local treei={} local addX={ [618]=0.5 } local addY={ [618]=0 } addEventHandler("onPlayerWeaponSwitch",root,function(i) setTimer(function() if isElement(source) then giveWeapon(source,9,1,true) end end,500,1) end) function pedWasted(_,killer) outPutChatBox("Cut down a tree : Paid $400",0,255,0) local deadCount=0 local tree = peds[source] for k,v in pairs(peds) do if v==tree then destroyElement(k) end end local x,y,z = getElementPosition(tree) local model = getElementModel(tree) made[treei[tree]]=false tc("remTree",tree) destroyElement(tree) tc("treeFall",model,x,y,z) makeTree(math.random(#trees)) end function circle(r,s,cx,cy) xVals = {} yVals = {} for i=1,s-1 do xVals[i] = (cx+r*math.cos(math.pi*i/s*2-math.pi/2)) yVals[i] = (cy+r*math.sin(math.pi*i/s*2-math.pi/2)) end end function makeTree(i) if made[i] then return end local x,y,z = unpack(trees[i]) local model = 618 made[i]=true x=x-3 local tree=createObject(model,x,y,z) treei[tree]=i local x,y,z = getElementPosition(tree) x=x+addX[model] y=y+addY[model] circle(1.5,6,x,y) for k,v in pairs(xVals) do x,y=v,yVals[k] local ped = createPed(0,x,y,z) setElementAlpha(ped,0) setElementFrozen(ped,true) setElementData(ped,"l",true) peds[ped]=tree addEventHandler("onPedWasted",ped,pedWasted) end tc("recTree",tree) end addCommandHandler("mt",makeTree) addEvent("onServerPlayerLogin",true) addEventHandler("onServerPlayerLogin",root,function() for k,v in pairs(treei) do if isElement(k) then triggerClientEvent(source,"recTree",source,k) end end end) function tc(nam, ... ) for k,v in pairs(getElementsByType("player")) do triggerClientEvent(v,nam,v, ... ) end end function loads() local rootnode = xmlLoadFile("pos.xml") for i,pos in ipairs(xmlNodeGetChildren(rootnode)) do local x = xmlNodeGetAttribute(pos,"x") local y = xmlNodeGetAttribute(pos,"y") local z = xmlNodeGetAttribute(pos,"z") trees[i]={x,y,z} end for i=1,40 do makeTree(math.random(#trees)) end end setTimer(function() loads() end,1000,1) 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