Dzsozi (h03)

Members
  • Content count

    582
  • Joined

  • Last visited

  • Days Won

    1

Dzsozi (h03) last won the day on December 25 2017

Dzsozi (h03) had the most liked content!

Community Reputation

54 Popular

About Dzsozi (h03)

  • Rank
    Mack

Details

  • Location
    Hungary

Recent Profile Visitors

2,827 profile views
  1. Dzsozi (h03)

    Save and load data with JSON

    I don't really want to use setElementData, I rather prefer tables on client side for this, if is that possible. Probably it is, since the script works right now, I just need to know how to store the vehicles' data when I stop/start/restart the resource. But I don't think that I need element datas on server side for that, since this is not something like I would need to be aware of to people change it's data value with cheat engine or something.
  2. Dzsozi (h03)

    Save and load data with JSON

    If I save the data in a file how should I do that? Every vehicle’s data in a new line? Or how should I get which vehicle has the data? Database seems a bit more complicated and also I don’t want to get it on server side. I am looking for the best performance for my scripts. What do you think which is the most performance friendly solution for that?
  3. Dzsozi (h03)

    Save and load data with JSON

    Hello! I would like to use tables for my vehicle system to save data, since I really want to have a good performance. Whatever, so I tried using toJSOn and fromJSON but I don't really understand how that works. I want to save every vehicles' blinker state/side when the resource stops and set it back when the resource starts. How can I do that with tables? Here's my current code, I tried lots of different ways but couldn't manage to get it working. I would appreciate if someone could help me out! local function toggleIndicator(key,keyState) if isTimer(spamTimer) then return end for k, vehicle in pairs(getElementsByType("vehicle")) do local driver = getVehicleOccupant(vehicle) if driver == localPlayer then if (keyState == "down") then spamTimer = setTimer(function() spamTimer = nil end, 1000, 1) indicatorInfo[vehicle] = indicatorInfo[vehicle] or {} local indicatorState = indicatorInfo[vehicle]["side"] or nil if indicatorState then --removeEventHandler("onClientRender", getRootElement(), startIndicator) indicatorInfo[vehicle]["side"] = nil handleIndicatorLights() return end if key == blinkerLeft then indicatorInfo[vehicle] = { ["side"] = "left", } elseif key == blinkerRight then indicatorInfo[vehicle] = { ["side"] = "right", } else indicatorInfo[vehicle] = { ["side"] = "both", } end end end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() bindKey(blinkerLeft, "down", toggleIndicator) bindKey(blinkerRight, "down", toggleIndicator) bindKey(blinkerBoth, "down", toggleIndicator) for k, vehicle in pairs(getElementsByType("vehicle")) do indicatorInfo[vehicle] = indicatorInfo[vehicle] or {} indicatorInfo[vehicle]["side"] = fromJSON(data) end end ) addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), function() for k, vehicle in pairs(getElementsByType("vehicle")) do if indicatorInfo[vehicle] then local data = toJSON({indicatorInfo[vehicle]["side"] or nil}) end end end ) I get this error with the current code, but I don't know how to fix it: Bad argument @ 'fromJSON' [Expected string at argument 1, got nil]
  4. Dzsozi (h03)

    Spook-o-meter

    You will definitely need getDistanceBetweenPoints3D (or 2D if you want to disable the distance check on the Z axis), onClientRender I guess, maybe some easy math for calculations, also you will have to define the element you want to keep the distance away from, at least this is how I would do it. So you may also need setElementData as well, but there are other ways to do it without that. If you want to recreate the meter bar as well, probably dxDrawText and dxDrawRectangle will be also needed for your work. This is all I can think of right now.
  5. Dzsozi (h03)

    Get perfect positions based on rotation

    Sorry for bringing up this topic again, but I have another problem that I can't solve. How can I make the drawn lights always lay on the surface (or at least always face the vehicle's top correctly)? Since right now when I go up on a hill with a light shadow attached to my vehicle it looks like this: How can I make it work like the default headlights on surface? Just to make sure, here's my current calculations again: addEventHandler("onClientPreRender", root, function() local cameraX, cameraY, cameraZ = getElementPosition(getCamera()) for groundLightShadow, info in pairs(attachedGroundLightShadows) do local x, y, z = getPositionFromElementOffset(info.element, info.pos.x, info.pos.y, info.pos.z) setElementPosition(groundLightShadow, x, y, z) end for k, data in pairs(groundLightShadows) do if data.lightShadow and isElement(data.lightShadow) then local worldX, worldY, worldZ = getElementPosition(data.lightShadow) local groundPosition = getGroundPosition(worldX, worldY, worldZ) local fixedGroundPosition = groundPosition+0.05 local onScreenX, onScreenY = getScreenFromWorldPosition(worldX, worldY, fixedGroundPosition, 20) if onScreenX and onScreenY then local distance = getDistanceBetweenPoints3D(worldX, worldY, fixedGroundPosition, cameraX, cameraY, cameraZ) if distance <= lightShadowVisibleDistance then if isLineOfSightClear(cameraX, cameraY, cameraZ, worldX, worldY, fixedGroundPosition, true, false, false, false, false, true) then local lightColor = data.color local matching = attachedGroundLightShadows[data.lightShadow] if matching then local elementX, elementY, elementZ = getElementPosition(matching.element) local rx, ry, rz = getElementRotation(matching.element) --local facez = getGroundPosition(elementX, elementY, elementZ + 5000000) local x, y, z = getPositionFromElementOffset(matching.element, matching.pos.x, matching.pos.y, matching.pos.z) local xa, ya, za = getPositionFromElementOffset(matching.element,matching.pos.x, matching.pos.y+data.size, matching.pos.z) local xb, yb, zb = getPositionFromElementOffset(matching.element,matching.pos.x, matching.pos.y-data.size, matching.pos.z) if elementZ <= fixedGroundPosition+2 then dxSetBlendMode("add") dxDrawMaterialLine3D(xa, ya, fixedGroundPosition, xb, yb, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), (xa+xb)/2, (ya+yb)/2, z) dxSetBlendMode("blend") end else dxSetBlendMode("add") dxDrawMaterialLine3D(xa, ya, fixedGroundPosition, xb, yb, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), (xa+xb)/2, (ya+yb)/2, z) dxSetBlendMode("blend") end end end end end end end, true, "low-10" )
  6. Dzsozi (h03)

    Send a return string data from server to client

    Got it working and now I understand how it works. Thank you!
  7. Dzsozi (h03)

    Send a return string data from server to client

    But on client side I need to use the function like on server side, so I need to call the function and then return the value given on server side, I want to use it inside a render function so like accountState = getPlayerAccountState(localPlayer), and then based on that I can disable or enable the register button, change it's color, add tooltip, whatever.
  8. Dzsozi (h03)

    MTA Animations tutorial

    You can use Naturalmotion's Endorphin to make custom animations, you can find several tutorials about in online and then use GTA Anim Manager to create custom IFP files and replace animations.
  9. Dzsozi (h03)

    Send a return string data from server to client

    That doesn't really help me out.
  10. Hello! I would like to get the current account state variable on client side, so I can adjust my login interface based on that (if the player already has an account disable the register button, etc.). My problem is I don't know how to do that, could somebody help me out? I need to call the function on client side, so I can't use element datas (as far as I know). Here's my server side script: function getPlayerAccountState(playerSource) if (playerSource) then local accountState = "canCreate" local selectQuery = dbPoll(dbQuery(connection, "SELECT * FROM accounts"), -1) if (selectQuery) then for k, v in ipairs(selectQuery) do if (tostring(v["username"]):upper() == tostring(playerUsername):upper()) then accountState = "haveUsername" break end if not (getServerOwners(playerSerial)) then if (tostring(v["serial"]):upper() == tostring(playerSerial):upper()) then accountState = "haveAccount" break end end end end return accountState end end
  11. Dzsozi (h03)

    Vehicles cant be pushed by on foot.

    I suggest you using https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision
  12. Dzsozi (h03)

    [Poll?]What would you like to see in a new map editor?

    A possibility to change/replace some object textures and some default extra stuff like walls from SA:MP or something like that to make custom interior and house mapping more supported? I would really like to see that advanced mapping oppurtinity in MTA:SA and that would be really useful for custom stuff.
  13. Dzsozi (h03)

    checkpoint

    Try it this way, since you are trying to make the marker disappear in a vehicle on the picture, but the hitElement must be the localPlayer based on the previous code. addEventHandler( "onClientMarkerHit", resourceRoot, function (hitElement, dim) if (curMarker and source == curMarker and (hitElement == localPlayer or hitElement == getPedOccupiedVehicle(localPlayer)) and dim) then ID = ID + 1 if ID > #markers then ID = 1 end createCheckpoint( ID ) -- create the next checkpoint end end ) Or just try deleting it and then test if and see if it works. addEventHandler( "onClientMarkerHit", resourceRoot, function (hitElement, dim) if (curMarker and source == curMarker and dim) then ID = ID + 1 if ID > #markers then ID = 1 end createCheckpoint( ID ) -- create the next checkpoint end end )
  14. Dzsozi (h03)

    Get perfect positions based on rotation

    Thank you, I managed to fix it that way: local xa, ya, za = getPositionFromElementOffset(matching.element,matching.pos.x, matching.pos.y+data.size, 0) local xb, yb, zb = getPositionFromElementOffset(matching.element,matching.pos.x, matching.pos.y-data.size, 0)
  15. Dzsozi (h03)

    Get perfect positions based on rotation

    This is not working out really well. Here's my full code, it would be awesome if you could help me! Client: local lightShadowVisibleDistance = 50 --local tailLightShadow = dxCreateTexture("files/images/groundLightShadow.png") local lightShadowTypes = { ["pointlight"] = dxCreateTexture("files/images/pointlight.png"), ["taillight"] = dxCreateTexture("files/images/taillight.png"), } local groundLightShadows = {} local attachedGroundLightShadows = {} function createLightShadow(x, y, z, shadowType, size, r,g,b,a) local vehicleLightShadow = createElement("vehicleLightShadow") local groundPosition = getGroundPosition(x, y, z) setElementPosition(vehicleLightShadow, x, y, groundPosition+0.03) if not r then r = 255 end if not g then g = 255 end if not b then b = 255 end if not a then a = 255 end if not size then size = 2 end if not shadowType then shadowType = "normal" end local array = {} array.color = {r,g,b,a} array.size = size --local renderTarget = dxCreateRenderTarget(512, 512, true) --[[dxSetRenderTarget(renderTarget, true) local width, height = dxGetMaterialSize(renderTarget) dxSetBlendMode("add") dxDrawImage(width, height, width-width*2, height-height*2, tailLightShadow, 0, 0, 0, tocolor(255,255,255,255)) dxSetBlendMode("blend") dxSetRenderTarget()]] --array.texture = renderTarget --if array.texture and isElement(array.texture) then -- setElementParent(array.texture, vehicleLightShadow) --end array.lightShadow = vehicleLightShadow array.lightShadowType = shadowType groundLightShadows[vehicleLightShadow] = array return vehicleLightShadow end function attachGroundLightShadow(lightShadow, element, pos) attachedGroundLightShadows[lightShadow] = { lightShadow = lightShadow, element = element, pos = pos } addEventHandler("onClientElementDestroy", lightShadow, function() attachedGroundLightShadows[lightShadow] = nil end) addEventHandler("onClientElementDestroy", element, function() attachedGroundLightShadows[lightShadow] = nil end) return true end local function getPositionInFront(element,meters,component) local x,y,z = getVehicleComponentPosition(element, component, "world") local a,b,r = getVehicleComponentRotation(element, component, "world") x = x - math.sin(math.rad(r)) * meters y = y + math.cos(math.rad(r)) * meters return x,y end addEventHandler("onClientPreRender", root, function() local cameraX, cameraY, cameraZ = getCameraMatrix() for groundLightShadow, info in pairs(attachedGroundLightShadows) do local x, y, z = getPositionFromElementOffset(info.element, info.pos.x, info.pos.y, info.pos.z) setElementPosition(groundLightShadow, x, y, z) end for k, data in pairs(groundLightShadows) do if data.lightShadow and isElement(data.lightShadow) then local worldX, worldY, worldZ = getElementPosition(data.lightShadow) local groundPosition = getGroundPosition(worldX, worldY, worldZ) local fixedGroundPosition = groundPosition+0.03 local onScreenX, onScreenY = getScreenFromWorldPosition(worldX, worldY, fixedGroundPosition, 20) if onScreenX and onScreenY then local lightColor = data.color local distance = getDistanceBetweenPoints3D(worldX, worldY, fixedGroundPosition, cameraX, cameraY, cameraZ) if distance <= lightShadowVisibleDistance then if isLineOfSightClear(cameraX, cameraY, cameraZ, worldX, worldY, fixedGroundPosition, true, false, false, false, false, true) then --local renderTarget = data.texture --dxSetRenderTarget(renderTarget, true) --local width, height = dxGetMaterialSize(renderTarget) --dxSetBlendMode("add") --dxDrawImage(width, height, width-width*2, height-height*2, tailLightShadow, 0, 0, 0, tocolor(255,255,255,255)) --dxSetBlendMode("blend") --dxSetRenderTarget() --local width, height = dxGetMaterialSize(data.texture) --dxSetRenderTarget(data.renderTarget, true) --dxSetBlendMode("add") --dxDrawImage(0, 0, width, height, data.texture, 0, 0, 0, tocolor(255,255,255,255)) --dxSetBlendMode("blend") --dxSetRenderTarget() local matching = attachedGroundLightShadows[data.lightShadow] if matching then local elementX, elementY, elementZ = getElementPosition(matching.element) local rx, ry, rz = getElementRotation(matching.element) local facez = getGroundPosition(elementX, elementY, elementZ + 5000000) local x, y, z = getPositionFromElementOffset(matching.element, matching.pos.x, matching.pos.y, facez) if elementZ <= fixedGroundPosition+2 then dxSetBlendMode("add") dxDrawMaterialLine3D(worldX, worldY-data.size, fixedGroundPosition, worldX, worldY+data.size, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), x, y, z) dxSetBlendMode("blend") end else dxSetBlendMode("add") dxDrawMaterialLine3D(worldX, worldY-data.size, fixedGroundPosition, worldX, worldY+data.size, fixedGroundPosition, lightShadowTypes[data.lightShadowType], data.size*2, tocolor(lightColor[1],lightColor[2],lightColor[3],lightColor[4]), x, y, z) dxSetBlendMode("blend") end end end end end end end, true, "low-1" ) function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end collectgarbage("collect") --local xddd = createLightShadow(1957.5991210938,-2288.2802734375,13.546875, 245,140,20,255) And here are the images I am currently using: https://imgur.com/a/MUYXbnq My problem is that the images doesn't rotate with the vehicle when I use the "attachGroundLightShadow" function in an other script. I would like to make the attached light shadows rotate with the vehicle in the direction the vehicle facing, or it would be even better if I could change the rotation when calling the "createLightShadow" function. Hope you understand me and you can help me.