Advertisement
FocusedWolf

AttachmentPoints 2.0

Jul 15th, 2011
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.73 KB | None | 0 0
  1. local marineModelName = "models/marine/male/male.model"
  2. local marineSpecialModelName = "models/marine/male/male_special.model"
  3. local skulkModelName = "models/alien/skulk/skulk.model"
  4. local lerkModelName = "models/alien/lerk/lerk.model"
  5. local fadeModelName = "models/alien/fade/fade.model"
  6. local gorgeModelName = "models/alien/gorge/gorge.model"
  7. local eggModelName = "models/alien/egg/egg.model"
  8.  
  9. //Thanks goes to Feha for this technique: http://www.unknownworlds.com/ns2/forums/index.php?s=&showtopic=114164&view=findpost&p=1860412
  10. local playerModelAttachmentPoints = {}
  11. // playerModelAttachmentPoints[modelName] = attachmentPoint, nameOffset, imageOffset
  12. playerModelAttachmentPoints[marineModelName] = { "JetPack", Vector(-0.02, -0.35, -0.32), Vector(0, 0.20, -0.37) }
  13. playerModelAttachmentPoints[marineSpecialModelName] = playerModelAttachmentPoints[marineModelName]
  14. playerModelAttachmentPoints[skulkModelName] = { "Bone_Tongue", Vector(0, -0.30, 0), Vector(0, 0, -0.37) }
  15. playerModelAttachmentPoints[lerkModelName] = { "Head_Tongue_02", Vector(0, 0.25, 0), Vector(0, 0, -0.37) }
  16. playerModelAttachmentPoints[fadeModelName] = { "fade_tongue2", Vector(0, 0.46, -0.40), Vector(0, -0.14, -0.37) }
  17. playerModelAttachmentPoints[gorgeModelName] = { "Head", Vector(0, 0.45, 0), Vector(0, 0.14, 0) }
  18. playerModelAttachmentPoints[eggModelName] = { "target", Vector(0, 0.55, 0), Vector(0, 0.10, 0) }
  19.  
  20. function GUIPlayerBlips:GetModelAttachmentPoints(modelName)
  21.     local value = playerModelAttachmentPoints[modelName]
  22.     if not value then
  23.         //PT("Invalid index:", modelName)
  24.         return
  25.     end
  26.  
  27.     return unpack(value)
  28. end
  29.  
  30. local playerAngles = Angles()
  31. function GUIPlayerBlips:GetPlayerNameAndImageAttachmentPoints(playerEntity)
  32.     local nameAttachmentPoint
  33.     local imageAttachmentPoint
  34.  
  35.     local playerEntityModelName = playerEntity:GetModelName()
  36.     //if playerEntityModelName == "" then
  37.     //    PT("entity has no model")
  38.     //    return
  39.     //end
  40.  
  41.     local attachmentPoint, nameOffset, imageOffset = self:GetModelAttachmentPoints(playerEntityModelName)
  42.     local attachPointCoords = playerEntity:GetAttachPointCoords(attachmentPoint)
  43.  
  44.     // This weird looking if-else structure was necessary to work around the weird rotations of the attachment point axes.
  45.     // Some models use x,y,z attachPointCoords.axes to represant the x-axis, y-axis, and z-axis.
  46.     // Other models used random attachPointCoords.axes to represant the x,y,z directions.
  47.     // If that doesn't make sense then just search this code for all instances of "attachPointCoords.xAxis".
  48.  
  49.     if playerEntityModelName == marineModelName or playerEntityModelName == marineSpecialModelName or playerEntityModelName == eggModelName then
  50.         nameAttachmentPoint = attachPointCoords.origin + nameOffset.x * attachPointCoords.xAxis +
  51.                                                          nameOffset.y * attachPointCoords.yAxis +
  52.                                                          nameOffset.z * attachPointCoords.zAxis
  53.  
  54.         imageAttachmentPoint = attachPointCoords.origin + imageOffset.x * attachPointCoords.xAxis +
  55.                                                           imageOffset.y * attachPointCoords.yAxis +
  56.                                                           imageOffset.z * attachPointCoords.zAxis
  57.  
  58.     elseif playerEntityModelName == skulkModelName then
  59.  
  60.         //hackish workaround for the problem the skulk attachment-point has when wall walking where it rises high above the skulk.
  61.     //THIS PROBLEM IS FIXED IN NS2 version 181!!!
  62.         playerAngles:BuildFromCoords(playerEntity:GetCoords())
  63.         if math.abs(playerAngles.roll) > 0.01 then //if wallwalking
  64.             local distanceFromAttachPoint = 1
  65.             local startPoint = attachPointCoords.origin - attachPointCoords.xAxis * distanceFromAttachPoint
  66.             local endPoint = attachPointCoords.origin + attachPointCoords.xAxis * distanceFromAttachPoint
  67.  
  68.             local trace = fTraceRay(startPoint, endPoint, PhysicsMask.Bullets, nil)
  69.             local hitDistance = (startPoint - trace.endPoint):GetLength()
  70.  
  71.             //that number is the distance i get on the ground
  72.             attachPointCoords.origin = attachPointCoords.origin + (hitDistance - 0.81078) * attachPointCoords.xAxis //it's really a y-axis for the skulk
  73.         end
  74.  
  75.         nameAttachmentPoint = attachPointCoords.origin + nameOffset.x * attachPointCoords.zAxis +
  76.                                                          nameOffset.y * attachPointCoords.xAxis +
  77.                                                          nameOffset.z * attachPointCoords.yAxis
  78.  
  79.         imageAttachmentPoint = attachPointCoords.origin + imageOffset.x * attachPointCoords.zAxis +
  80.                                                           imageOffset.y * attachPointCoords.xAxis +
  81.                                                           imageOffset.z * attachPointCoords.yAxis
  82.  
  83.     elseif playerEntityModelName == lerkModelName or playerEntityModelName == fadeModelName or playerEntityModelName == gorgeModelName then
  84.         nameAttachmentPoint = attachPointCoords.origin + nameOffset.x * attachPointCoords.yAxis +
  85.                                                          nameOffset.y * attachPointCoords.zAxis +
  86.                                                          nameOffset.z * attachPointCoords.xAxis
  87.  
  88.         imageAttachmentPoint = attachPointCoords.origin + imageOffset.x * attachPointCoords.yAxis +
  89.                                                           imageOffset.y * attachPointCoords.zAxis +
  90.                                                           imageOffset.z * attachPointCoords.xAxis
  91.     //else
  92.     //    PT("Unknown model name:", playerEntityModelName)
  93.     end
  94.  
  95.     return nameAttachmentPoint,imageAttachmentPoint
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement