Jump to content

Den.

Members
  • Posts

    64
  • Joined

  • Last visited

Den.'s Achievements

Snitch

Snitch (10/54)

0

Reputation

  1. I think once the calculation 2+2 is done, the result (4) is stored in memory under 'x'. If you access x afterwards, its value will be fetched from memory regardless of what calculation produced its result. Example: function add(left, right) outputChatBox("Adding") return left[1] + right[1] end addCommandHandler('test1', function() local t1 = {1} local t2 = {2} setmetatable(t1, {__add = add}) local x = t1 + t2 outputChatBox("Result1: "..tostring(x)) outputChatBox("Result2: "..tostring(x)) end)
  2. Den.

    XML loading

    I think to actually create an xml file successfully you need to use xmlCreateFile in conjunction with xmlSaveFile, so like this: xmlClientSettingsFile = xmlLoadFile ( "files/settings.xml" ) if xmlClientSettingsFile then outputChatBox ( "File Loaded" ) elseif not xmlClientSettingsFile then xmlClientSettingsFile = xmlCreateFile ( "files/settings.xml", "settings" ) if xmlClientSettingsFile then outputChatBox ( "Works dawg" ) --Complete your work on the file here. xmlSaveFile(xmlClientSettingsFile) --Save it permanently. xmlUnloadFile(xmlClientSettingsFile) --Unload it from memory when you are done. else outputChatBox ( "Nope" ) end end If you are using xmlCreateFile server-side then the file will be saved in [MTA directory]/server/resources/[your resource/path here]. If you are using it client-side then it will be saved on the client's computer, in [MTA directory]/mods/deathmatch/resources/[your resource/path here]
  3. I think you're giving dxDrawText the width and height of the rectangle, instead of it's right and bottom absolute coordinates. Try this? dxDrawText("Map: Unknown", x*0.2, y*0.4, (x*0.2)+x1, (y*0.4)+(y*0.1),tocolor(255,255,255,255), 1, DxFont, "left", "top",true,false,true,true,true)
  4. triggerClientEvent will return true even if the event is not added client-side I think. Your issue may be in the resource's meta.xml. Make sure the client file has the type attribute set to "client". Also, The event handler that calls createRegisterWindow is attached to root, when it should be attached to resourceRoot. Attaching it to root will cause the event to be triggered when ANY resource is started, not just this one. So like this: addEventHandler("onClientResourceStart", resourceRoot, createRegisterWindow) For future cases, put an outputChatBox in the function called by an event triggered from the server instead of checking if triggerClientEvent returned true or not.
  5. There is no function that forces the localPlayer to aim with a weapon at a specific point/target. I don't think this is possible. You can easily determine which ped to actually aim/focus on by a combination of getting the closest ped by distance, and least rotation change to face the ped. The following code draws the circles ontop of the ped that should have the aim/focus (untested btw): Doesn't scale, or check for Line of sight. local function getPedsOnScreen() local peds = {} for key, ped in ipairs(getElementsByType("ped", root, true)) do if isElementOnScreen(ped) then table.insert(peds, ped) end end return peds end local function dxDrawCircle(posX, posY, radius, width, angleAmount, color, postGUI) radius = radius or 50 width = width or 5 angleAmount = angleAmount or 1 color = color or tocolor(255, 255, 255, 200) postGUI = postGUI or false for i=0,360,angleAmount do local _i = i*(math.pi/180) dxDrawLine(math.cos(_i)*(radius-width)+posX, math.sin(_i)*(radius-width)+posY, math.cos(_i)*(radius+width)+posX, math.sin(_i)*(radius+width)+posY, tocolor(255, 0, 0), width, postGUI) end return true end local function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end local function sortbyrot(a, b) local _, _, rz = getElementRotation(localPlayer) local x, y = getElementPosition(localPlayer) local ax, ay = getElementPosition(a) local bx, by = getElementPosition(b) local arz = findRotation(x, y, ax, ay) arz = math.abs(rz - arz) local brz = findRotation(x, y, bx, by) brz = math.abs(rz - brz) return arz < brz end addEventHandler("onClientRender", root, function() local weapon = getPedWeapon(localPlayer) if weapon and weapon > 0 then local peds = getPedsOnScreen() if #peds > 0 then table.sort(peds, sortbyrot) local chosen = peds[1] local hx, hy, hz = getPedBonePosition(chosen, 6) local sx, sy = getScreenFromWorldPosition(hx, hy, hz) if sx then dxDrawCircle(sx, sy) end end end end)
  6. I have no idea if this will work, and it's not related to processLineOfSight but maybe you can extend it to make it work: addEventHandler("onClientRender", root, function() if getPedWeapon(localPlayer) then --He has a weapon local sx, sy, sz = getPedTargetStart(localPlayer) -- local tx, ty, tz = getPedTargetCollision(localPlayer) --Can be replaced by getPedWeaponMuzzlePosition if it doesn't work. if sx and tx then local dist = getDistanceBetweenPoints3D(sx, sy, sz, tx, ty, tz) if dist < 1.5 then --Blocked by a close object. You need to figure out the distance here. --BLOCKED. end end end end)
  7. spawnPlayer(thePlayer,NearestHospital[1],NearestHospital[2],NearestHospital[3], theSkin, 0, 0, theTeam) Rotation comes before skin in the order of arguments in spawnPlayer, so correct it to: spawnPlayer(thePlayer,NearestHospital[1],NearestHospital[2],NearestHospital[3], 0, theSkin, 0, 0, theTeam)
  8. Use relative values, and guiGetScreenSize as D&G suggested: local sx, sy = guiGetScreenSize() local width, height = 0.5 * sx, 0.5 * sy local x, y = (0.5 * sx) - width/2, (0.5 * sy) - height/2
  9. Den.

    playerblips

    Just add if isElement(element): for k,element in ipairs(attached) do if isElement(element) and getElementType ( element ) == "blip" then destroyElement ( element ) end end That ensures that the element in the loop is a valid element, not an already destroyed one. D&G: You're trying to get the element type of a table or possibly a boolean value.
  10. You can calculate a model's height using the following function: getElementDistanceFromCentreOfMassToBaseOfModel
  11. No.. Follow the instructions I posted. Go to the admin resource, open admin_server.lua and paste the code below into there: local _setPlayerTeam = setPlayerTeam; setPlayerTeam = function(player,team) local PreviousTeam = getPlayerTeam(player); local Result = _setPlayerTeam(player,team); if Result then triggerEvent("onPlayerTeamChange",player,PreviousTeam,team); end; return Result; end; THEN go to your script, and paste the code below right before addEventHandler("onPlayerTeamChange"): addEvent("onPlayerTeamChange");
  12. If landingMarker is called by the event onClientGUIClick, source is the GUI element clicked. The player who clicks it is always going to be localPlayer.
  13. Den.

    [HELP] Please

    Simply like this: local texts = {{"My text here", x, y, z}, {"My second text", x, y, z}} --x, y, z denotes the world position of the text addEventHandler("onClientRender", root, function() local x, y, z = getElementPosition(localPlayer) for key, text in ipairs(texts) do local str, tx, ty, tz = unpack(text) local distance = getDistanceBetweenPoints3D(x, y, z, tx, ty, tz) if distance <= 50 then local sx, sy = getScreenFromWorldPosition(tx, ty, tz) if sx then local scale = math.min(15/distance, 1.4) dxDrawText(str, sx, sy, sx, sy, nil, scale) end end end end)
  14. Den.

    HELP me Please..

    The zombieproof script you posted doesn't even work for colshapes, can't you read?. It checks for radar areas only.
  15. Den.

    [HELP] Please

    Just have a table called texts in the above example at the beginning of the script: local texts = {{"My text here", x, y, z}, {"My second text", x, y, z}} --x, y, z denotes the world position of the text I don't understand your second question, please be clear.
×
×
  • Create New...