
Den.
Members-
Posts
64 -
Joined
-
Last visited
Everything posted by Den.
-
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)
-
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]
-
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)
-
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.
-
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)
-
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)
-
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)
-
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
-
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.
-
You can calculate a model's height using the following function: getElementDistanceFromCentreOfMassToBaseOfModel
-
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");
-
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.
-
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)
-
The zombieproof script you posted doesn't even work for colshapes, can't you read?. It checks for radar areas only.
-
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.
-
Go to the admin resource, then open admin_server.lua: Paste Cheez3D's function 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 put this in YOUR script: addEvent("onPlayerTeamChange"); I'm not sure if this will cause issues in the admin resource, but likely not as it's just triggering an event.
-
Okay, but which element should have the data zombieProof? the colshape? If so just add: setElementData(col, "zombieProof", true) after col is created.
-
The code I posted should work without creating a radar area.. But anyways: I removed the radar area...It was pretty obvious you needed to remove createRadarArea if you wanted to remove it.. addEventHandler("onColShapeHit", createColRectangle (2418.4255371094, -1735,121.6306152344,100), function(h)if not isElement(h) then return end if getElementData(h,"zombie") then killPed(h) end end)
-
Here: server-side: addEvent("dft:attach", true) addEventHandler("dft:attach", root, function(vehicle, ox, oy, oz) if isElement(source) and isElement(vehicle) then attachElements(vehicle, source, ox, oy, oz) --Attach both vehicles setElementRotation(vehicle, getElementRotation(source)) --Set rotation for our vehicle setElementData(vehicle, "dft:attached", true, false) --Set element data for unloading later. end end) addCommandHandler("unload", function(thePlayer) local veh = getPedOccupiedVehicle(thePlayer) if isElement(veh) and getElementData(veh, "dft:attached") then --If the vehicle is attached to a DFT detachElements(veh) --Detach it removeElementData(veh, "dft:attached") --Remove the elem data. end end) Client-side: function loadDFT() local x, y, z = getElementPosition(localPlayer) local veh = getPedOccupiedVehicle(localPlayer) if veh then local vehicles = getElementsByType("vehicle") for key, vehicle in ipairs(vehicles) do if getElementModel(vehicle) == 578 then local vx, vy, vz = getElementPosition(vehicle) if getDistanceBetweenPoints3D(x, y, z, vx, vy, vz) <= 15 then --He is close to a DFT local cx, cy, cz = getVehicleComponentPosition(vehicle, "chassis_dummy") --Get the DFT's back position local height = getElementDistanceFromCentreOfMassToBaseOfModel(veh) -- Get our vehicle's height triggerServerEvent("dft:attach", vehicle, veh, cx, cy-1.5, height - 0.235) --Trigger the server event to attach elements end end end end end addCommandHandler("load", loadDFT) This is a slightly longer script for a small task such as attaching elements, but I wanted to test some things while doing it.
-
Depends what zombie resource you are using to spawn the zombies. I'm not sure if onColShapeHit is triggered if a ped is created inside that col, test it, and if it does trigger then replace killPed with destroyElement. Note: May cause issues with the zombie resource, depending on how they handle destroying zombie elements.
-
Here: This will work if each zombie has the element data "zombie" set to a value other than nil. local col = createColRectangle (96, 1788, 184, 145) addEventHandler("onColShapeHit", col, function(hitElement) if getElementType(hitElement) == 'ped' and getElementData(hitElement, 'zombie') then killPed(hitElement) end end) Also: price wat r u doin, price, stahp
-
Read the wiki guiSetAlpha. The alpha given to this function should range from 0 to 1.
-
Because the element that hit the pickup would be the vehicle, not the player driving it. Try this: function pickedUpWeaponCheck ( hitElement ) local etype = getElementType(hitElement) local thePlayer = etype == 'player' and hitElement or false --If the element type is a player, then store the player in thePlayer var. if etype == 'vehicle' then --if it's a vehicle, get it's controller. thePlayer = getVehicleController(hitElement) end if thePlayer then outputChatBox ( "You have picked up a M4.", thePlayer ) end end addEventHandler ( "onPickupHit", aPickup, pickedUpWeaponCheck )
-
I believe it's not possible to do it server-side unless you have fixed positions in which you retrieved yourself; Client-side you can possibly do it using processLineOfSight, but you will need a player in stream range of the position the vehicle spawned in.
-
According to the wiki, you can't destroy server-side elements with client-side destroyElement.