[DooD]Heavyair Posted May 19, 2008 Share Posted May 19, 2008 i have been trying to make a moving SAM SITE based on vercetti 1010s SAM SITE script so far i have tried to attach a collision sphere to an object and then move the object but this doesnt move the collision sphere i have also tried moving the collision sphere itself with moveObject but that didnt work either setElementPosition will move it but i need the collision to stay active while it moves and setElementPosition just takes it from one place and puts it in another but its not active while its moving ace_gambit said he has moved on to using math to calculate line of sight for his sam site but i dont even know how to start doing that so i need to get this working i can post the scripts i have tried but i dont think they are much help any ideas / advice really appreciated Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 i have been trying to make a moving SAM SITE based on vercetti 1010s SAM SITE script so far i have tried to attach a collision sphere to an object and then move the object but this doesnt move the collision sphere i have also tried moving the collision sphere itself with moveObject but that didnt work either setElementPosition will move it but i need the collision to stay active while it moves and setElementPosition just takes it from one place and puts it in another but its not active while its moving ace_gambit said he has moved on to using math to calculate line of sight for his sam site but i dont even know how to start doing that so i need to get this working i can post the scripts i have tried but i dont think they are much help any ideas / advice really appreciated Link to comment
robhol Posted May 19, 2008 Share Posted May 19, 2008 I'm not sure if this works the way I think, but isn't it as simple as to calculate the distance to the SAM site? Formula for 2d distance: x = sqrt( (Xa -Xb)^2 + (Ya-Yb)^2 ) Will return the distance in map units. This is only a description, you need to Lua-ize it yourself Link to comment
robhol Posted May 19, 2008 Share Posted May 19, 2008 I'm not sure if this works the way I think, but isn't it as simple as to calculate the distance to the SAM site? Formula for 2d distance: x = sqrt( (Xa -Xb)^2 + (Ya-Yb)^2 ) Will return the distance in map units. This is only a description, you need to Lua-ize it yourself Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 thanx for the help but i have no idea about the math stuff i kind of understand what your saying about calculating the distance but how to actually use it i have no idea at all i have looked at the way math is used in other script ( interstae 69 for the minigun and stuff ) but it just confuses me completely which is why im trying to use the collision sphere i think i might just have to live with stationery sam sites and come up with another way of doing this thanx again Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 thanx for the help but i have no idea about the math stuff i kind of understand what your saying about calculating the distance but how to actually use it i have no idea at all i have looked at the way math is used in other script ( interstae 69 for the minigun and stuff ) but it just confuses me completely which is why im trying to use the collision sphere i think i might just have to live with stationery sam sites and come up with another way of doing this thanx again Link to comment
Ace_Gambit Posted May 19, 2008 Share Posted May 19, 2008 I am not a big fan of maths either. In fact I really suck at it but I have some basic understanding of angles and came up with this. function testTargetAngleAgainstLoS(source, target, traceAngle, minDepth, maxDepth, minOffsetZ, maxOffsetZ) local oX, oY, oZ = getElementPosition(source) local rotX, rotY, rotZ = getObjectRotation(source) local tX, tY, tZ = getElementPosition(target) local targetDist2D = getDistanceBetweenPoints2D(oX, oY, tX, tY) local losX, losY, losZ = oX, oY, oZ local btX, btY, btZ = oX, oY, oZ local btDist2D = 0 local pX2D, pY2D = 0, 0 local pDist2D = 0 local ptotDist2D = 0 local angle = 0 if (targetDist2D < minDepth or targetDist2D > maxDepth or tZ < (oZ - minOffsetZ) or tZ > (oZ + maxOffsetZ)) then return end losX = losX - math.sin(math.rad(rotZ)) * targetDist2D losY = losY + math.cos(math.rad(rotZ)) * targetDist2D btX = btX - math.sin(math.rad(rotZ + 180)) * targetDist2D btY = btY + math.cos(math.rad(rotZ + 180)) * targetDist2D btDist2D = getDistanceBetweenPoints2D(btX, btY, tX, tY) if (tX > losX) then pX2D = tX - (math.abs(tX - losX) / 2) else pX2D = losX - (math.abs(losX - tX) / 2) end if (tY > losY) then pY2D = tY - (math.abs(tY - losY) / 2) else pY2D = losY - (math.abs(losY - tY) / 2) end pDist2D = getDistanceBetweenPoints2D(oX, oY, pX2D, pY2D) ptotDist2D = getDistanceBetweenPoints2D(pX2D, pY2D, tX, tY) angle = math.deg(math.tan(ptotDist2D / pDist2D)) * 2 return (angle > 0 and angle < traceAngle and targetDist2D < btDist2D) end What it does is return true if a target is within the field of sight (angle between line of sight and target vector). Link to comment
Ace_Gambit Posted May 19, 2008 Share Posted May 19, 2008 I am not a big fan of maths either. In fact I really suck at it but I have some basic understanding of angles and came up with this. function testTargetAngleAgainstLoS(source, target, traceAngle, minDepth, maxDepth, minOffsetZ, maxOffsetZ) local oX, oY, oZ = getElementPosition(source) local rotX, rotY, rotZ = getObjectRotation(source) local tX, tY, tZ = getElementPosition(target) local targetDist2D = getDistanceBetweenPoints2D(oX, oY, tX, tY) local losX, losY, losZ = oX, oY, oZ local btX, btY, btZ = oX, oY, oZ local btDist2D = 0 local pX2D, pY2D = 0, 0 local pDist2D = 0 local ptotDist2D = 0 local angle = 0 if (targetDist2D < minDepth or targetDist2D > maxDepth or tZ < (oZ - minOffsetZ) or tZ > (oZ + maxOffsetZ)) then return end losX = losX - math.sin(math.rad(rotZ)) * targetDist2D losY = losY + math.cos(math.rad(rotZ)) * targetDist2D btX = btX - math.sin(math.rad(rotZ + 180)) * targetDist2D btY = btY + math.cos(math.rad(rotZ + 180)) * targetDist2D btDist2D = getDistanceBetweenPoints2D(btX, btY, tX, tY) if (tX > losX) then pX2D = tX - (math.abs(tX - losX) / 2) else pX2D = losX - (math.abs(losX - tX) / 2) end if (tY > losY) then pY2D = tY - (math.abs(tY - losY) / 2) else pY2D = losY - (math.abs(losY - tY) / 2) end pDist2D = getDistanceBetweenPoints2D(oX, oY, pX2D, pY2D) ptotDist2D = getDistanceBetweenPoints2D(pX2D, pY2D, tX, tY) angle = math.deg(math.tan(ptotDist2D / pDist2D)) * 2 return (angle > 0 and angle < traceAngle and targetDist2D < btDist2D)end What it does is return true if a target is within the field of sight (angle between line of sight and target vector). Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 AWESOME it seems that im missing a lot of commands ( like that getDistanceBetweenTwoPoints thing are all the commands listed anywhere or are they all on the wiki and im just being dumb i think a lot of my problems are not knowing how to tell the script what i want it to do can someone tell me where i can find them all THANX AGAIN robhol and ace_gambit i have had a quick look at your script ace_gambit and id like to see if im getting the idea should i add an event handler that will fire when your testtargetangleagainstLOS returns true not sure if i worded that right what i mean is if something flys into the line of sight your function will return true and then i should have an event handler that fires a missle / bomb when your function returns true hope that makes some sense Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 AWESOME it seems that im missing a lot of commands ( like that getDistanceBetweenTwoPoints thing are all the commands listed anywhere or are they all on the wiki and im just being dumb i think a lot of my problems are not knowing how to tell the script what i want it to do can someone tell me where i can find them all THANX AGAIN robhol and ace_gambit i have had a quick look at your script ace_gambit and id like to see if im getting the idea should i add an event handler that will fire when your testtargetangleagainstLOS returns true not sure if i worded that right what i mean is if something flys into the line of sight your function will return true and then i should have an event handler that fires a missle / bomb when your function returns true hope that makes some sense Link to comment
Ace_Gambit Posted May 19, 2008 Share Posted May 19, 2008 You could try something like this: oSAM = getElementByID("bla bla") -- SAM site object previousTick = getTickCount() function callbackClientRender() if (testTargetAngleAgainstLoS(oSAM, getLocalPlayer(), 35, 15, 100, 5, 200) and getTickCount() > (previousTick + 1500)) then previousTick = getTickCount() outputChatBox("Uh-oh") -- fire rocket end end addEventHandler("onClientRender", getRootElement(), callbackClientRender) Link to comment
Ace_Gambit Posted May 19, 2008 Share Posted May 19, 2008 You could try something like this: oSAM = getElementByID("bla bla") -- SAM site objectpreviousTick = getTickCount() function callbackClientRender() if (testTargetAngleAgainstLoS(oSAM, getLocalPlayer(), 35, 15, 100, 5, 200) and getTickCount() > (previousTick + 1500)) then previousTick = getTickCount() outputChatBox("Uh-oh") -- fire rocket endend addEventHandler("onClientRender", getRootElement(), callbackClientRender) Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 i think im beginning to understand this now i will see what i can do and post any decent results THANX ACE_GAMBIT with the oSAM = getElementByID("bla bla") -- SAM site object line do i just put the objectID of what im using for the sam site i assume that it would then run the line of sight check on all my sam sites well ill give it a go and see what happens sorry takin up so much of your time ace_gambit but now im really confused i cant seem to figure out how to use this in a script with the oSAM = getElementByID("bla bla") -- SAM site object line i looked at the wiki and it says getElementByID will look for the objectID stated in the .map file but when i have created objects with the .map file before i messed up the objectID part <object model="4866" posX="-542.96350097656" posY="886.63665771484" posZ="2.7947807312012" rotX="0.5" rotY="0.5" rotZ="75"/> this is how i put in objects and this is how i do vehicles <vehicle id="BladeBackShed" model="536" posX="-676.43225097656" posY="962.98449707031" posZ="12.507791519165" rotX="0.041015625" rotY="0.002777099609375" rotZ="92.063659667969" upgrades="1010 1087 1104 1103 1107 1108 1181 1183" paintjob="1" plate="PIMPED"/> but from what i can see in the wiki i need to give the objects an ID like samsite1 or something but when ive tried to do this in the past the map file wont load | | <objectID="samsite1" object model="4866" posX="-542.96350097656" posY="886.63665771484" posZ="2.7947807312012" rotX="0.5" rotY="0.5" rotZ="75"/> so im not sure how to tell the function what it should calculate the line of sight for again i hope that makes sense edit ; suddenly feel stupid looking at second script i think if i set oSAM to createObject( sam site stuff ) it should set where the source is and then set target as getLocalPlayer will give me the target going to try it now back soon thank u very very much for your PATIENCE AND HELP u r great EDIT 2 : still no joy i think im going to look for some lua tutorials and see if i can expand my knowledge a bit because is beyond me at the moment but I'LL BE BACK Link to comment
[DooD]Heavyair Posted May 19, 2008 Author Share Posted May 19, 2008 i think im beginning to understand this now i will see what i can do and post any decent results THANX ACE_GAMBIT with the oSAM = getElementByID("bla bla") -- SAM site object line do i just put the objectID of what im using for the sam site i assume that it would then run the line of sight check on all my sam sites well ill give it a go and see what happens sorry takin up so much of your time ace_gambit but now im really confused i cant seem to figure out how to use this in a script with the oSAM = getElementByID("bla bla") -- SAM site object line i looked at the wiki and it says getElementByID will look for the objectID stated in the .map file but when i have created objects with the .map file before i messed up the objectID part this is how i put in objects and this is how i do vehicles but from what i can see in the wiki i need to give the objects an ID like samsite1 or something but when ive tried to do this in the past the map file wont load | | so im not sure how to tell the function what it should calculate the line of sight for again i hope that makes sense edit ; suddenly feel stupid looking at second script i think if i set oSAM to createObject( sam site stuff ) it should set where the source is and then set target as getLocalPlayer will give me the target going to try it now back soon thank u very very much for your PATIENCE AND HELP u r great EDIT 2 : still no joy i think im going to look for some lua tutorials and see if i can expand my knowledge a bit because is beyond me at the moment but I'LL BE BACK Link to comment
Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 You got the syntax wrong. ID is a separate parameter and should be defined as follows: "samsite1" object model="4866" posX="-542.96350097656" posY="886.63665771484" posZ="2.7947807312012" rotX="0.5" rotY="0.5" rotZ="75"/> Notice the id instead of objectID. This should work. This is also correct: oSAM = createObject(3884, x, y, z) -- SAM site object Edit: You can use the testTargetAngleAgainstLoS as a 2D look at function as well. Just add angle as return value to get the rotation needed to make an object face a particular target. Link to comment
Ace_Gambit Posted May 20, 2008 Share Posted May 20, 2008 You got the syntax wrong. ID is a separate parameter and should be defined as follows: "samsite1" object model="4866" posX="-542.96350097656" posY="886.63665771484" posZ="2.7947807312012" rotX="0.5" rotY="0.5" rotZ="75"/> Notice the id instead of objectID. This should work. This is also correct: oSAM = createObject(3884, x, y, z) -- SAM site object Edit: You can use the testTargetAngleAgainstLoS as a 2D look at function as well. Just add angle as return value to get the rotation needed to make an object face a particular target. Link to comment
[DooD]Heavyair Posted May 20, 2008 Author Share Posted May 20, 2008 ive gotta learn all this syntax stuff that objectID in map file has messed up quite a few things ive been trying to do thanx so much ace_gambit EDIT : with the map file entry i found u only need one "object" <object id="lossamsite" model="3885" posX="-711" posY="957" posZ="30" rotX="0" rotY="0" rotZ="0"/> map is workin now just gotta get the rest now just dont seem to be able to make sense of this for some reason i know what i want it to do but i just cant figure it out i have looked at a few lua tutorials and they make perfect sense but they dont tell me what i need i understand how the function works ( just about ) but i just cant figure out how to implement it i thought if i told the function what the sam site is oSAM = getElementByID("lossam") -- SAM site object i put object id "lossam" in the map file so it gets any samsites ive made in the map file but i dont understand how to make the ( testTargetAngleAgainstLoS ) function attach to the sam sites so it knows where to look for the target and then trigger the firing event i thought that the getElementByID would make the function work for all sam sites made with the map file but when i fly around the sam site i dont get the Uh-Oh message sorry about taking up so much of your time ace_gambit as i dont seem to be getting very far with this scripting stuff i really dont know what else to try to get a better understanding of how lua works because just looking at the scripts and stuff seems to make me even more confused i think i understand most of the functions but just dont know how to tie them all together im going to try the wiki again and see if theres any better tutorials out there EDIT ::: EDIT ::: ace_gambit i have tried running the script u put above oSAM = getElementByID("lossamsite") -- SAM site object previousTick = getTickCount() function testTargetAngleAgainstLoS(source, target, traceAngle, minDepth, maxDepth, minOffsetZ, maxOffsetZ) local oX, oY, oZ = getElementPosition(source) local rotX, rotY, rotZ = getObjectRotation(source) local tX, tY, tZ = getElementPosition(target) local targetDist2D = getDistanceBetweenPoints2D(oX, oY, tX, tY) local losX, losY, losZ = oX, oY, oZ local btX, btY, btZ = oX, oY, oZ local btDist2D = 0 local pX2D, pY2D = 0, 0 local pDist2D = 0 local ptotDist2D = 0 local angle = 0 if (targetDist2D < minDepth or targetDist2D > maxDepth or tZ < (oZ - minOffsetZ) or tZ > (oZ + maxOffsetZ)) then return end losX = losX - math.sin(math.rad(rotZ)) * targetDist2D losY = losY + math.cos(math.rad(rotZ)) * targetDist2D btX = btX - math.sin(math.rad(rotZ + 180)) * targetDist2D btY = btY + math.cos(math.rad(rotZ + 180)) * targetDist2D btDist2D = getDistanceBetweenPoints2D(btX, btY, tX, tY) if (tX > losX) then pX2D = tX - (math.abs(tX - losX) / 2) else pX2D = losX - (math.abs(losX - tX) / 2) end if (tY > losY) then pY2D = tY - (math.abs(tY - losY) / 2) else pY2D = losY - (math.abs(losY - tY) / 2) end pDist2D = getDistanceBetweenPoints2D(oX, oY, pX2D, pY2D) ptotDist2D = getDistanceBetweenPoints2D(pX2D, pY2D, tX, tY) angle = math.deg(math.tan(ptotDist2D / pDist2D)) * 2 return (angle > 0 and angle < traceAngle and targetDist2D < btDist2D) end function callbackClientRender() if (testTargetAngleAgainstLoS(oSAM, getLocalPlayer(), 35, 15, 100, 5, 200) and getTickCount() > (previousTick + 1500)) then previousTick = getTickCount() outputChatBox("Uh-oh") end end addEventHandler("onClientRender", getRootElement(), callbackClientRender) i thought it would give me the Uh oH message when i went around the lossamite object oSAM = getElementByID("lossamsite") -- SAM site object but nothing im really sorry but i have been looking at assorted tutorials and the wiki but i just dont get it do u have any idea if i will be able to move the collision shapes when DP3 is done thanx for all your help but i think i will just have to keep things simple for a while longer yet Link to comment
[DooD]Heavyair Posted May 20, 2008 Author Share Posted May 20, 2008 ive gotta learn all this syntax stuff that objectID in map file has messed up quite a few things ive been trying to do thanx so much ace_gambit EDIT : with the map file entry i found u only need one "object" map is workin now just gotta get the rest now just dont seem to be able to make sense of this for some reason i know what i want it to do but i just cant figure it out i have looked at a few lua tutorials and they make perfect sense but they dont tell me what i need i understand how the function works ( just about ) but i just cant figure out how to implement it i thought if i told the function what the sam site is oSAM = getElementByID("lossam") -- SAM site object i put object id "lossam" in the map file so it gets any samsites ive made in the map file but i dont understand how to make the ( testTargetAngleAgainstLoS ) function attach to the sam sites so it knows where to look for the target and then trigger the firing event i thought that the getElementByID would make the function work for all sam sites made with the map file but when i fly around the sam site i dont get the Uh-Oh message sorry about taking up so much of your time ace_gambit as i dont seem to be getting very far with this scripting stuff i really dont know what else to try to get a better understanding of how lua works because just looking at the scripts and stuff seems to make me even more confused i think i understand most of the functions but just dont know how to tie them all together im going to try the wiki again and see if theres any better tutorials out there EDIT ::: EDIT ::: ace_gambit i have tried running the script u put above oSAM = getElementByID("lossamsite") -- SAM site objectpreviousTick = getTickCount() function testTargetAngleAgainstLoS(source, target, traceAngle, minDepth, maxDepth, minOffsetZ, maxOffsetZ) local oX, oY, oZ = getElementPosition(source) local rotX, rotY, rotZ = getObjectRotation(source) local tX, tY, tZ = getElementPosition(target) local targetDist2D = getDistanceBetweenPoints2D(oX, oY, tX, tY) local losX, losY, losZ = oX, oY, oZ local btX, btY, btZ = oX, oY, oZ local btDist2D = 0 local pX2D, pY2D = 0, 0 local pDist2D = 0 local ptotDist2D = 0 local angle = 0 if (targetDist2D < minDepth or targetDist2D > maxDepth or tZ < (oZ - minOffsetZ) or tZ > (oZ + maxOffsetZ)) then return end losX = losX - math.sin(math.rad(rotZ)) * targetDist2D losY = losY + math.cos(math.rad(rotZ)) * targetDist2D btX = btX - math.sin(math.rad(rotZ + 180)) * targetDist2D btY = btY + math.cos(math.rad(rotZ + 180)) * targetDist2D btDist2D = getDistanceBetweenPoints2D(btX, btY, tX, tY) if (tX > losX) then pX2D = tX - (math.abs(tX - losX) / 2) else pX2D = losX - (math.abs(losX - tX) / 2) end if (tY > losY) then pY2D = tY - (math.abs(tY - losY) / 2) else pY2D = losY - (math.abs(losY - tY) / 2) end pDist2D = getDistanceBetweenPoints2D(oX, oY, pX2D, pY2D) ptotDist2D = getDistanceBetweenPoints2D(pX2D, pY2D, tX, tY) angle = math.deg(math.tan(ptotDist2D / pDist2D)) * 2 return (angle > 0 and angle < traceAngle and targetDist2D < btDist2D)end function callbackClientRender() if (testTargetAngleAgainstLoS(oSAM, getLocalPlayer(), 35, 15, 100, 5, 200) and getTickCount() > (previousTick + 1500)) then previousTick = getTickCount() outputChatBox("Uh-oh") endend addEventHandler("onClientRender", getRootElement(), callbackClientRender) i thought it would give me the Uh oH message when i went around the lossamite object oSAM = getElementByID("lossamsite") -- SAM site object but nothing im really sorry but i have been looking at assorted tutorials and the wiki but i just dont get it do u have any idea if i will be able to move the collision shapes when DP3 is done thanx for all your help but i think i will just have to keep things simple for a while longer yet 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