Jump to content

Backsage

Members
  • Posts

    168
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Backsage

  1. Client side: addEventHandler("onClientResourceStart", resourceRoot, function() object = createObject(1318, 0, 0, 4) moveObject(object, 5000, 0, 0, 20) end ) local movingData_ = movingData function movingData (...) local movingData = {...} moveObject(unpack(movingData_)) setElementData(movingData[1], "moveObjectEndTime", getTickCount() + movingData[2], false) end local screenWidth, screenHeight = guiGetScreenSize () -- Get the screen resolution function thing() if getElementData(object,"moveObjectEndTime") > getTickCount() then state = "moving" else state = "idling" end -- Write our state string to the lower left corner of the screen dxDrawText ( "You are " .. state .. "!", 40, screenHeight - 40, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "default" ) end addEventHandler("onClientRender", root, thing) Edit: I seem to have fixed the issue. The problem was the data was not being properly passed to the function. Thank you IIYAMA for your help. Now I know it's possible to detect if a object is moving from moveObject. Client side: addEventHandler("onClientResourceStart", resourceRoot, function() object = createObject(1318, 0, 0, 4) time = 5000 local x, y, z = 0, 0, 20 moveObject(object, time, x, y, z) --local table1 = {object, time, x, y, z} --outputChatBox(tostring(unpack(table1))) movingData(object, time, x, y, z) end ) function movingData (...) movingData1 = {...} --moveObject(unpack(movingData1)) outputChatBox(tostring(unpack(movingData1))) setElementData(movingData1[1], "moveObjectEndTime", getTickCount() + movingData1[2], false) end addCommandHandler("test1", function() if getElementData(movingData1[1], "moveObjectEndTime") then outputChatBox(tostring((getElementData(movingData1[1], "moveObjectEndTime")))) elseif not getElementData(movingData1[1], "moveObjectEndTime") then outputChatBox("Not properly set") end end ) local screenWidth, screenHeight = guiGetScreenSize () -- Get the screen resolution function thing() if getElementData(object,"moveObjectEndTime") > getTickCount() then state = "moving" else state = "idling" end dxDrawText ( "You are " .. state .. "!", 40, screenHeight - 40, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "default" ) end addEventHandler("onClientRender", root, thing)
  2. Ok, well the thing is I've already added the function source in my code and I'm trying to detect if an object is moving from moveObject, but isElementMoving doesn't return anything from the object. You can try it yourself and you will see the state always returning idling. function isElementMoving(theElement) if isElement(theElement)then --First check if the given argument is an element local x, y, z = getElementVelocity(theElement) --Get the velocity of the element given in our argument if x == 0 and y == 0 and z == 0 then --When there is no movement on X, Y or Z return false because our element is not moving return false else return true end end end local screenWidth, screenHeight = guiGetScreenSize () -- Get the screen resolution (width and height) function idleCheck () local state = "Unknown" local element = getPedOccupiedVehicle ( localPlayer ) or localPlayer or object1 -- Check whether the player is moving or not. if isElementMoving ( element ) then state = "moving" else state = "idling" end -- Write our state string to the lower left corner of the screen dxDrawText ( "You are " .. state .. "!", 40, screenHeight - 40, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "default" ) end -- Keep the text visible with onClientRender. addEventHandler ( "onClientRender", root, idleCheck ) addCommandHandler("test2", function() local x, y, z = getElementPosition(localPlayer) object1 = createObject(1318, x, y, z) attachElements(localPlayer, object1) moveObject(object1, 20000, 100, y, z) end )
  3. Does isElementMoving work with objects that are moving from moveObject?
  4. Thanks man. Now it works with no problems.
  5. addEventHandler("onClientResourceStart", resourceRoot, function() marker = createMarker(0, 0, 2, "arrow", 1, 255, 0, 6) player1 = getPlayerFromName("[NSM]Backsage") object = createObject(1318, 0, 0, 4) attachElements(player1, object) x, y, z = getElementPosition(marker) setElementData(marker,"originalZ",z) setElementAlpha(object, 0) setTimer(function() destroyElement(object) end, 1000, 1) moveObject(object, 1000, 0, 0, 5) end ) addEventHandler("onClientElementDestroy", resourceRoot, function() x, y, z = getElementPosition(object) if z >= 4.8 then object = createObject(1318, x, y, z) setTimer(function() destroyElement(object) end, 1000, 1) setElementAlpha(object, 0) attachElements(player1, object) moveObject(object, 1000, 0, 0, 2) elseif z >= 2 then object = createObject(1318, x, y, z) setTimer(function() destroyElement(object) end, 1000, 1) setElementAlpha(object, 0) attachElements(player1, object) moveObject(object, 1000, 0, 0, 5) end end ) function escapeMe () local x, y, z = getElementPosition(marker) outputChatBox("" .. x .. ", " .. y .. ", " .. z) if isElementWithinMarker(player1, marker) then outputChatBox("Marker's moving") end end addCommandHandler ( "test2", escapeMe ) _moveObject = moveObject function moveObject(element, time, x, y, z) if isElement(element) then local hasMoved = _moveObject ( element, time, x, y, z ) if ( hasMoved ) then triggerEvent("onElementPositionChanged", element, x, y, z) return true end end end addEvent("onElementPositionChanged", true) addEventHandler("onElementPositionChanged", root, function(model, x, y, z) local model = getElementType(source) -- source is the element that has changed his position outputChatBox("The "..model.."'s position was changed to: "..x..", "..y..", ".. z) end)
  6. Kinda works, except that it says that z is a nil value. If I remove z, it'll say "The object's position was changed to: 0, 2" and "The object's position was changed to: 0, 5" because 5 and 2 are the z positions I wanted the objects to move. It's not returning the actual x value. And I don't know why that function has to be called moveObject in order for it to work.
  7. Erm, can you give an example? I understand to use timers, but I don't know what event to use. It would be cool if something like onElementPositionChanged existed though.
  8. Is there any such event on the MTA wiki? Something like that might be useful. I wanna try to make a marker (and object) move up and down using moveObject and I wanna do something so that when the position has changed, I can do something else (e.g. move it down).
  9. Yes, I wanted to move the marker only. But I guess I have to use attachElements first. And I've tested it and it works. Thanks guys.
  10. Hi. I have seen on some server where the marker can move up and down and I wanted to see if I can achieve the same effect. I used runcode. I've tried creating a marker and then tried to move it with moveObject, but it doesn't work. It always return false. So does moveObject only work with objects and not other elements like markers and players? If so, what can I do to make that marker move?
  11. Oh, this only works on moving elements. Something like this will probably only work on cars. Nvm.
  12. Ok, so I looked up getElementSpeed and setElementSpeed. I put their function source in a server.lua file and now when I try setting the speed from the command, I get The code is server side. function getElementSpeed(theElement, unit) -- Check arguments for errors assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")") assert(getElementType(theElement) == "player" or getElementType(theElement) == "ped" or getElementType(theElement) == "object" or getElementType(theElement) == "vehicle", "Invalid element type @ getElementSpeed (player/ped/object/vehicle expected, got " .. getElementType(theElement) .. ")") assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)") -- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit)) -- Setup our multiplier to convert the velocity to the specified unit local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456) -- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit return (Vector3(getElementVelocity(theElement)) * mult).length end function setElementSpeed(element, unit, speed) if (unit == nil) then unit = 0 end if (speed == nil) then speed = 0 end speed = tonumber(speed) local acSpeed = getElementSpeed(element, unit) if (acSpeed~=false) then -- if true - element is valid, no need to check again local diff = speed/acSpeed if diff ~= diff then return end -- if the number is a 'NaN' return end. local x,y,z = getElementVelocity(element) setElementVelocity(element,x*diff,y*diff,z*diff) return true end return false end addCommandHandler("setmyspeed", function (player, cmd, arg1) local veh = getPedOccupiedVehicle(player) if (veh) then setElementSpeed(veh, "kph", tonumber(arg1)) else outputChatBox("You have to sit in vehicle", player) end end ) And when I change it to a number addCommandHandler("setmyspeed", function (player, cmd, arg1) local veh = getPedOccupiedVehicle(player) if (veh) then setElementSpeed(veh, 2, tonumber(arg1)) else outputChatBox("You have to sit in vehicle", player) end end ) I get
  13. Just so you know, I didn't make the missiontimer resource. Talidan did. And also this: It's going by the syntax of setTimer, theFunction, timeInterval, timesToExecute, and then the arguments (which is the syntax of triggerEvent).
  14. What does that have to do with anything? The parentheses is just a coding convention. It has no effect, at least in Lua, on how the code works. Anyway, I'm still getting the same errors.
  15. Code here. I already put it in my second post: addEventHandler("onResourceStart", root, function() test = exports.missiontimer:createMissionTimer (5000,true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255) end ) addEventHandler("onMissionTimerElapsed", root, function() destroyElement(test) end ) addCommandHandler("tdmdt", function () if ( test ) then destroyElement(test) end end )
  16. I was only posting my code, where I try to create a missiontimer. But I guess it seems like missiontimer itself is bugged. missiontimer_client.lua Client side code: rootElement = getRootElement() thisResource = getThisResource() missionTimers = {} bool = { [false]=true, [true]=true } addEvent ( "onClientMissionTimerElapsed", true ) addEventHandler("onClientResourceStart",resourceRoot, function() triggerServerEvent ( "onClientMissionTimerDownloaded", getLocalPlayer() ) end ) addEventHandler ("onClientResourceStop",rootElement, function() for i,timer in ipairs(getElementsByType("missiontimer",source)) do destroyElement(timer) end end ) function createMissionTimer ( duration, countdown, timerFormat, x, y, bg, font, scale, r, g, b ) sourceResource = sourceResource or thisResource local element = createElement ( "missiontimer" ) setElementParent ( element, getResourceDynamicElementRoot(sourceResource) ) setupMissionTimer ( element, duration, countdown, timerFormat, x, y, bg, font, scale, r, g, b ) return element end function setupMissionTimer ( element, duration, countdown, timerFormat, x, y, bg, font, scale, r, g, b ) if missionTimers[element] then return end addEventHandler ( "onClientElementDestroy", element, onMissionTimerDestroy ) missionTimers[element] = {} missionTimers[element].x = tonumber(x) or 0 missionTimers[element].y = tonumber(y) or 0 missionTimers[element].countdown = countdown missionTimers[element].duration = duration missionTimers[element].originalTick = getTickCount() missionTimers[element].timerFormat = type( timerFormat ) == "string" and timerFormat or "%m:%s:%cs" missionTimers[element].bg = (bool[bg] == nil and true) or bg missionTimers[element].font = font or "default-bold" missionTimers[element].scale = tonumber(scale) or 1 missionTimers[element].hurrytime = 15000 missionTimers[element].formatWidth = dxGetTextWidth(missionTimers[element].timerFormat, missionTimers[element].scale, missionTimers[element].font) missionTimers[element].colour = (r and g and b) and tocolor(r, g, b) or tocolor(255,255,255) missionTimers[element].timer = setTimer ( triggerEvent, duration, 1, "onClientMissionTimerElapsed", element ) end function setMissionTimerTime ( timer, time ) if missionTimers[timer] then missionTimers[timer].duration = tonumber(time) or missionTimers[timer].remaining missionTimers[timer].originalTick = getTickCount() if isTimer( missionTimers[timer].timer ) then killTimer ( missionTimers[timer].timer ) end missionTimers[timer].timer = setTimer ( triggerEvent, missionTimers[timer].duration, 1, "onClientMissionTimerElapsed", element ) return true end return false end function getMissionTimerTime ( timer ) if missionTimers[timer] then if missionTimers[timer].countdown then return math.max(missionTimers[timer].duration - (getTickCount() - missionTimers[timer].originalTick),0) else return (getTickCount() - missionTimers[timer].originalTick) end end return false end function setMissionTimerFrozen ( timer, frozen ) if frozen == not not missionTimers[timer].frozen then return false end if missionTimers[timer] and bool[frozen] then missionTimers[timer].frozen = frozen or nil if frozen then if isTimer( missionTimers[timer].timer ) then killTimer ( missionTimers[timer].timer ) end missionTimers[timer].timer = nil missionTimers[timer].duration = getMissionTimerTime ( timer ) else missionTimers[timer].timer = setTimer ( triggerEvent, missionTimers[timer].duration, 1, "onClientMissionTimerElapsed", timer ) missionTimers[timer].originalTick = getTickCount() end return true end return false end function isMissionTimerFrozen ( timer ) return not not missionTimers[timer].frozen end function setMissionTimerHurryTime ( timer, time ) missionTimers[timer].hurrytime = tonumber(time) or 15000 end function setMissionTimerFormat( timer, timerFormat ) if type( timerFormat ) ~= "string" then return false end if missionTimers[timer] then missionTimers[timer].timerFormat = timerFormat missionTimers[timer].formatWidth = dxGetTextWidth(missionTimers[timer].timerFormat, missionTimers[timer].scale, missionTimers[timer].font) end end function onMissionTimerDestroy() for i,timer in ipairs(getTimers()) do if timer == missionTimers[source].timer then killTimer ( timer ) break end end missionTimers[source] = nil en
  17. When using this code: addEventHandler("onResourceStart", root, function() test = exports.missiontimer:createMissionTimer (5000,true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255) end ) addEventHandler("onMissionTimerElapsed", root, function() destroyElement(test) end ) addCommandHandler("tdmdt", function () if ( test ) then destroyElement(test) end end ) I get these errors. Client side: And when I try using the /tdmdt to destroy the server, I get this. Server side: Why is missiontimer bugging for me? missiontimer_client.lua Client side code: rootElement = getRootElement() thisResource = getThisResource() missionTimers = {} bool = { [false]=true, [true]=true } addEvent ( "onClientMissionTimerElapsed", true ) addEventHandler("onClientResourceStart",resourceRoot, function() triggerServerEvent ( "onClientMissionTimerDownloaded", getLocalPlayer() ) end ) addEventHandler ("onClientResourceStop",rootElement, function() for i,timer in ipairs(getElementsByType("missiontimer",source)) do destroyElement(timer) end end ) function createMissionTimer ( duration, countdown, timerFormat, x, y, bg, font, scale, r, g, b ) sourceResource = sourceResource or thisResource local element = createElement ( "missiontimer" ) setElementParent ( element, getResourceDynamicElementRoot(sourceResource) ) setupMissionTimer ( element, duration, countdown, timerFormat, x, y, bg, font, scale, r, g, b ) return element end function setupMissionTimer ( element, duration, countdown, timerFormat, x, y, bg, font, scale, r, g, b ) if missionTimers[element] then return end addEventHandler ( "onClientElementDestroy", element, onMissionTimerDestroy ) missionTimers[element] = {} missionTimers[element].x = tonumber(x) or 0 missionTimers[element].y = tonumber(y) or 0 missionTimers[element].countdown = countdown missionTimers[element].duration = duration missionTimers[element].originalTick = getTickCount() missionTimers[element].timerFormat = type( timerFormat ) == "string" and timerFormat or "%m:%s:%cs" missionTimers[element].bg = (bool[bg] == nil and true) or bg missionTimers[element].font = font or "default-bold" missionTimers[element].scale = tonumber(scale) or 1 missionTimers[element].hurrytime = 15000 missionTimers[element].formatWidth = dxGetTextWidth(missionTimers[element].timerFormat, missionTimers[element].scale, missionTimers[element].font) missionTimers[element].colour = (r and g and b) and tocolor(r, g, b) or tocolor(255,255,255) missionTimers[element].timer = setTimer ( triggerEvent, duration, 1, "onClientMissionTimerElapsed", element ) end function setMissionTimerTime ( timer, time ) if missionTimers[timer] then missionTimers[timer].duration = tonumber(time) or missionTimers[timer].remaining missionTimers[timer].originalTick = getTickCount() if isTimer( missionTimers[timer].timer ) then killTimer ( missionTimers[timer].timer ) end missionTimers[timer].timer = setTimer ( triggerEvent, missionTimers[timer].duration, 1, "onClientMissionTimerElapsed", element ) return true end return false end function getMissionTimerTime ( timer ) if missionTimers[timer] then if missionTimers[timer].countdown then return math.max(missionTimers[timer].duration - (getTickCount() - missionTimers[timer].originalTick),0) else return (getTickCount() - missionTimers[timer].originalTick) end end return false end function setMissionTimerFrozen ( timer, frozen ) if frozen == not not missionTimers[timer].frozen then return false end if missionTimers[timer] and bool[frozen] then missionTimers[timer].frozen = frozen or nil if frozen then if isTimer( missionTimers[timer].timer ) then killTimer ( missionTimers[timer].timer ) end missionTimers[timer].timer = nil missionTimers[timer].duration = getMissionTimerTime ( timer ) else missionTimers[timer].timer = setTimer ( triggerEvent, missionTimers[timer].duration, 1, "onClientMissionTimerElapsed", timer ) missionTimers[timer].originalTick = getTickCount() end return true end return false end function isMissionTimerFrozen ( timer ) return not not missionTimers[timer].frozen end function setMissionTimerHurryTime ( timer, time ) missionTimers[timer].hurrytime = tonumber(time) or 15000 end function setMissionTimerFormat( timer, timerFormat ) if type( timerFormat ) ~= "string" then return false end if missionTimers[timer] then missionTimers[timer].timerFormat = timerFormat missionTimers[timer].formatWidth = dxGetTextWidth(missionTimers[timer].timerFormat, missionTimers[timer].scale, missionTimers[timer].font) end end function onMissionTimerDestroy() for i,timer in ipairs(getTimers()) do if timer == missionTimers[source].timer then killTimer ( timer ) break end end missionTimers[source] = nil end
  18. Hello guys. I'm interested in using mission timer. However, there is an issue. addEventHandler("onClientResourceStart", root, function() ATimer = exports.missiontimer:createMissionTimer (5000,true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255) end ) addEventHandler("onClientMissionTimerElapsed", ATimer, function() destroyElement(ATimer) end ) It's not working for the variable ATimer. For some reason, it's only working when I do this: I would like to know why this is only working for root and not something else. Edit: And I would also like to know how to make a mission timer appear on another client's screen with the time synced.
  19. Whenever I try checking Enable 3D Acceleration, it makes my VM crash. And it'll do this for any kind of Windows 7 64 bit install I do. I don't know why.
  20. Edit 4: I was able to get Single Player and MTA to work in VMware from here: https://forum.multitheftauto.com/viewtopic.php?f=91&t=31891 3D Acceleration was activated in VMware. For some reason, I was not able to get 3D Acceleration to work in VirtualBox. Maybe I needed another OS like Windows 7 Home Basic? Because that's what I'm using in VMware (13/02/2016). It's kinda laggy, but it's better than not working at all.
  21. Someone has helped me find the new server, which is irc.gtanet.com! And now I can go to #mta.scripting.
  22. I'm having the exact same problem. Testing ports... Port 22126 UDP is open. Port 22003 UDP is open. Port 22005 TCP is closed. Players can not download! I have no idea what's going on. I used to have all the ports working in the past. And now all of a sudden when I try configuring the 22005 TCP port in my router's settings, it's not working. And to think, it just coincided with problems with my Windows 7 HomeGroup not discovering other HomeGroup computers and the printer not working. 11/07/2016 Edit: I seem to have solved the issue by first going to my router and adding the ports through Port Forwarding. Then I went to Mcafee Firewall, Port Services, and added a new Port Service and added the ports there and then selected Open ports to: All PCs. And boom! Started working again!
  23. I don't even know if they have an IRC 'cause I can't find it. EDIT: I guess I only get them if I kill someone. They don't even say that in the rules!
  24. Guys, I'm playing on a server called GTO (Grand Theft Online). How do I earn skill points for my weapons? I keep asking in chat and no one is answering. And I can't go to their forum 'cause they're not accepting registering new accounts.
  25. Hello. I'm trying to set the player's walking style based on the skin, but it doesn't work. Server side: function skate() local maleSkin = 99 local femSkin = 92 local skin = getElementModel(source) if (skin == 92) or (skin == 99) then setPedWalkingStyle(source,138) end end addEventHandler("onResourceStart",root,skate) It only works via runcode when I do /run setPedWalkingStyle(root, 138) I think it might be because of source, but I'm not sure what I should replace it with. Edit: it's fixed. Just had to specify the players. Edit 2: little bug function skate2(_, newModel) if (newModel == 99) then setPedWalkingStyle(source,138) elseif (newModel == 92) then setPedWalkingStyle(source,138) end end addEventHandler("onElementModelChange",root,skate2) It works when I change it to the girl skin via the F1 freerom panel, but not for the guy skin.
×
×
  • Create New...