Jump to content

IIYAMA

Moderators
  • Posts

    6,097
  • Joined

  • Last visited

  • Days Won

    218

Everything posted by IIYAMA

  1. local allSkins = getValidPedModels() -- get all skins, (this only has to be executed one time) do -- DO this when pressing a button local index = 1 local skin = getElementModel(ped) local nextButtonUsed = true -- did I press right(true)? Or left(false) -- find the (new) skin index from the table for i=1, #allSkins do if allSkins[i] == skin then index = i + (nextButtonUsed and 1 or -1) break end end -- Index not matching the table? Adjust! if index < 1 then index = #allSkins elseif index > #allSkins then index = 1 end -- set the model setElementModel(ped, allSkins[index]) end
  2. @Tebex The event system is created for that purpose. Use the addCommandHandler in one resource and pass this information global around all the resources that need it. (Or even fire the event even without addCommandHandler) Event functions serverside: https://wiki.multitheftauto.com/wiki/Server_Scripting_Functions#Event_functions You can also use export functions. But you have to be very specific about: between which resources you are communicating(?) https://wiki.multitheftauto.com/wiki/Call
  3. Ah sorry, in case of hitting the vehicle, you need to use ped target start. But you are almost there.
  4. Using a named function directly as an anonymous function is not allowed in lua: setTimer(function trigger(player) (So remove trigger) local wantedLvl = getPlayerWantedLevel (root) Getting the wanted level of the root element, Hmm, is the root that evil? Maybe you would have more luck if you get it from each player? triggerClientEvent(player,"StartEvadeTimer",player) Triggering to a player in the server every 1 second? Should be fine if everybody does have fast internet and ping under the 50... but we both know that isn't the case in MTA. (No UDP trigger event support, /me crying...)
  5. Subtract the ped-target-start position from the ped-target-end postion(or hit position) https://wiki.multitheftauto.com/wiki/GetPedTargetStart https://wiki.multitheftauto.com/wiki/GetPedTargetEnd And then make a vector of it + normalize it: https://wiki.multitheftauto.com/wiki/Vector/Vector3#getNormalized If the vehicle is at a remote location, then use instead of the ped start position, the vehicle position and do the same steps. (You might want to consider using the hit location of the event instead of the ped-target-end position.)
  6. The first two lines should be on top of the script. The rest should be inside of the function which is called every frame. (Name: renderPulse)
  7. That will not help you understand what the code does, or do you have some magic for that? This code does: Defining the animation duration Calculate the time when the animation should end. Getting the time now. Calculate the amount of animation-time left. Calculate the progress of the animation. The progress is a value from 0 t/m 1. 0 = 0%, 0.5 = 50%, 1 = 100% Which you can multiply with the alpha: progress * 255 (alpha) Shouldn't be too hard to understand? After all, the variable names speak for them self.
  8. It is a very complex process. But the best way to do this is by using the "os time". https://wiki.multitheftauto.com/wiki/GetTickCount local duration = 5000 local futureTime = getTickCount() + duration local timeNow = getTickCount() local timeLeft = futureTime - timeNow if timeLeft > 0 then -- animation ran NOT out of time ? local progress = (duration - timeLeft) / duration if progress > 0.5 then else end end Try to understand this concept first . ------------------------------------------------------- Feel free to use my content animator. It might to be too complex for you, but maybe you find your answer in the code. (next page) Pre requirement: For the functions: addRenderEvent, removeRenderEvent Content animator: Example, this is an animated rectangle: Fill in: id duration delay func (function where you do the animation stuff) parameters (default/start values) animations (these will animate/change the values of the parameters) Warning: The animations do not wait for each other, that is where the delay setting comes in. setTimer(function () local sample = { id = "sample", -- optional duration = 5000, -- or "infinity" / "inf" delay = 1000, func = function (param) local rectangleSize = 100 * param.scaleFactorY dxDrawRectangle ( param.screenCenterX - rectangleSize / 2, param.screenCenterY - rectangleSize / 2, rectangleSize, rectangleSize, tocolor ( 255, 0, 0, param.opacityStart ) ) end, -- optional 1 parameters = { opacityStart = 0 }, -- optional 2 (requires optional 1) animations = { { parameter = "opacityStart", from = 0, to = 255, duration = 2000, delay = 0, -- optional 3 easingType = "OutInBounce", easingAmplitude = 1.0 -- }, { parameter = "opacityStart", from = 255, to = 0, duration = 2000, delay = 2000 } } } createAnimatedContent (sample) end, 100, 1)
  9. I am not sure how those rockets are created, but why not solve the issue at the source? local nextShootTime = 0 function vehicleWeaponFire(thePresser, key, keyState, vehicleFireType) local vehModel = getElementModel(getPedOccupiedVehicle(thePresser)) local timeNow = getTickCount() -- system time if (armedVehicles[vehModel]) and timeNow > nextShootTime then -- if system time is higher than nextShootTime nextShootTime = timeNow + 5000 -- system time + 5000 ms = nextShootTime triggerEvent("onVehicleWeaponFire", thePresser, vehicleFireType, vehModel) end end And regarding your last issue: I think it is this: player = source It is a global after all, other players can also change the player variable globally before the timer is finished. So: local player = source But even so, I am not sure if the toggleControl function can block the bindKey. I put my doubts on that.
  10. Add more comments! What does your code do? The word `character` means in English different things: https://dictionary.cambridge.org/dictionary/english/character A person? A letter from a word? Variable names can only partly clarify what the code does. Comments will have to do the rest! Learn some more about local and global variables:
  11. Yea that is a possibility. @koragg Just keep in mind that: (if this issue is still around) 1. if you were listening serverside with the event onResourceStart. 2. Trigger the resourceRoot of that specific resource to clientside. 3. That after validating, the resourceRoot is not available yet. (Just run these 3 steps and you will understand what this means) Send over the resourceName instead and wait for onClientResourceStart(with high addEventHandler priority)
  12. @Stealthy Serval Why not move this to serverside? As far as I can see your code is already starting there. local loopCount = 0 local character = {} character[1] = {} character[2] = {} character[3] = {} acq = sql:query("SELECT * FROM characters WHERE account=?",getElementData(source,"getPlayerUsername")) for i,c in ipairs(acq)do if(characterCount == 1)then if(loopCount == 0)then character[1].skin = tonumber(c.skin) character[1].name = c.name character[1].cash = c.cash character[1].bank = c.bank loopCount = loopCount+1 end elseif(characterCount == 2)then if(loopCount == 0)then character[1].skin = tonumber(c.skin) character[1].name = c.name character[1].cash = c.cash character[1].bank = c.bank loopCount = loopCount+1 elseif(loopCount == 1)then character[2].skin = tonumber(c.skin) character[2].name = c.name character[2].cash = c.cash character[2].bank = c.bank loopCount = loopCount+1 end elseif(characterCount == 3)then if(loopCount == 0)then character[1].skin = tonumber(c.skin) character[1].name = c.name character[1].cash = c.cash character[1].bank = c.bank loopCount = loopCount+1 elseif(loopCount == 1)then character[2].skin = tonumber(c.skin) character[2].name = c.name character[2].cash = c.cash character[2].bank = c.bank loopCount = loopCount+1 elseif(loopCount == 2)then character[3].skin = tonumber(c.skin) character[3].name = c.name character[3].cash = c.cash character[3].bank = c.bank loopCount = loopCount+1 end end end
  13. or/and this: https://wiki.multitheftauto.com/wiki/SetPedAnimationProgress
  14. New free health regeneration resource. Simple concept, but it is worth a try! Enjoy ?
    Might be an interesting addition for shooters and race gamemodes.

     

     

  15. @VazErn As long as it works, people are always happy. A few tips: A loop for this is not required, unless there are multiple similar database items. for i, id in pairs(queryTable) do setElementData(source, "ID", id["id"]) end setElementData(source, "ID", queryTable[1]["id"]) (untested, but should be working) ------------------------------------------------------------------------------------------------ The sky is the LIMIT If the database has already found what it is looking for, then why not stop looking for more? LIMIT 1 Read more / how to use: https://blog.udemy.com/sql-limit/ ------------------------------------------------------------------------------------------------ Timers are working asynchronous What would happen if a player leaves during those 3 or 14 seconds when the timers are still running? setTimer(setCameraTarget, 3000, 1, source, source) setTimer(triggerClientEvent, 14000, 1, source, "renderRoyalID", source) Just think about it. setTimer(function (element) if isElement(element) then -- do your thing end end, 3000, 1, source)
  16. If streamed in objects aren't a solution, then fixing the problem by the source might be a solution. Preparing: -- instead of setElementData local munkakuka = createElement("munkakuka") setElementParent(munkakuka, object) https://wiki.multitheftauto.com/wiki/CreateElement Creates the element munkakuka Sets the munkakuka element as child of the object. Using a map file instead of a script? (also possible) Looping: local munkakuka = getElementsByType( 'munkakuka') for k=1, #munkakuka do local v = getElementParent(munkakuka[k]) It gets all custom elements `munkakuka`. Get the parent of it. (which is the object) This should reduce the amount of loops of the code. You can also set the object as child of the munkakuka element + it can make the code faster if you limit the note scope. (requires to change the code a little bit)
  17. Looping through an object structure instead of an array structure is slower, even though you do not have to recreate the table. -- Object structure { [value1] = true, [value2] = true } -- Array structure { [1] = value1, [2] = value2 } -- Same as: {value1, value2}
  18. Too many objects? Optimizations you can do: Limit the amount of objects and faster looping for k, v in ipairs ( getElementsByType( 'object' )) do local objects = getElementsByType( 'object', root, true ) -- only streamed in objects! for k=1, #objects do -- A `for loop` is faster local v = objects[k] https://wiki.multitheftauto.com/wiki/GetElementsByType syntax: (client) getElementsByType ( string theType, [ element startat=getRootElement(), bool streamedIn=false ] ) Texture ftw! (argb texture) -- on top of your script! local objectBlipTexture = dxCreateTexture( "blips/1125.png") ---------------------------------------------------------------- -- now draw! dxDrawImage(blipX - blipSize/2, blipY - blipSize/2, blipSize, blipSize, objectBlipTexture, 0, 0, 0, tocolor(255,255,255,255)) This is a texture speed test on wiki. You are currently rendering from a path. Which is according to this test ~6,75x slower than just a pre created texture (argb). https://wiki.multitheftauto.com/wiki/DxCreateTexture
  19. Yea, I believe that describes the resource the best. And yet, it surprised me how many conditions (for critical gamemode scenario's) it required to work properly. ?
  20. Regeneration (health) This resource lets you regenerate player and vehicle* health. It is not an unique idea, I know... but there weren't good implementations for it at the community resource list. So that's why I share this with YOU. * Vehicle regeneration for the driver only. Version 1.0.0 Not compiled! Smooth health regeneration No UI, just the manager Settings (Admin panel) Settings Regeneration [on/off] (player/vehicle) Regeneration value (player/vehicle) Regeneration delay (player/vehicle) Regeneration [on/off] while the vehicle is burning Download link: https://community.multitheftauto.com/?p=resources&amp;s=details&amp;id=15757 Take a quick look into the source code (v1.0.0) Client Server Meta
  21. That are murderous tests :(, I wish you good luck!
  22. @koragg The resource type isn't synced in the first place.(afaik) All below is just a guess: If you are not going to use a resource to sync that information, then there is a possible way to figure out if that resource is using map files. Technically it should be possible with this function: https://wiki.multitheftauto.com/wiki/GetElementChildren https://wiki.multitheftauto.com/wiki/Element_tree The element tree is attaching map elements on the mapRoot. The mapRoot should be attached to the resourceRoot. If this mapRoot is synced + synced before the resource starts clientside, then yes you might figure out if this resource can be considered a map. The only problem is that every resource can serve map files. Next to that, you can maybe find some element data leftovers from those (sub)root elements: https://wiki.multitheftauto.com/wiki/GetAllElementData https://wiki.multitheftauto.com/wiki/GetElementID Let me know if you find something interesting!
  23. Why would I code something that is already there? People these days....
  24. nope, not an example. But there are of course examples on wiki: https://wiki.multitheftauto.com/wiki/EngineApplyShaderToWorldTexture https://wiki.multitheftauto.com/wiki/DxCreateRenderTarget If you merge those wiki codes, you probably get some results. If you want to have some specific information about these functions, feel free to ask. But make sure to check wiki first X 10. ( one uncertainty ) If render target textures can't be used for shaders directly, then you can also copy them to another texture. https://wiki.multitheftauto.com/wiki/DxGetTexturePixels https://wiki.multitheftauto.com/wiki/DxCreateTexture All required wiki examples: addEventHandler("onClientResourceStart", resourceRoot, function() myRenderTarget = dxCreateRenderTarget( 80, 100 ) -- Create a render target texture which is 80 x 100 pixels end ) addEventHandler( "onClientRender", root, function() if myRenderTarget then dxSetRenderTarget( myRenderTarget ) -- Start drawing on myRenderTarget dxDrawText ( "Hello", 10, 20 ) -- Draw a message dxSetRenderTarget() -- Stop drawing on myRenderTarget dxDrawImage( 50, 50, 100, 100, myRenderTarget ) -- Now use myRenderTarget as a material and draw it lots of times dxDrawImage( 150, 350, 150, 100, myRenderTarget ) dxDrawImage( 250, 250, 100, 150, myRenderTarget ) dxDrawImage( 350, 30, 150, 150, myRenderTarget ) end end ) local myRenderTarget = dxCreateRenderTarget(500, 500, true) -- -- Function to draw text to our render target with '''modulate_add''' blend mode when the 'r' key is pressed -- function updateRenderTarget() dxSetRenderTarget(myRenderTarget, true) dxSetBlendMode("modulate_add") -- Set 'modulate_add' when drawing stuff on the render target dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "clear") dxSetBlendMode("blend") -- Restore default blending dxSetRenderTarget() -- Restore default render target end bindKey("r", "down", updateRenderTarget ) theTechnique = dxCreateShader("shader.fx") explosionTexture = dxCreateTexture( "tex/Explosion.png") function replaceEffect() engineApplyShaderToWorldTexture(theTechnique, "fireball6") dxSetShaderValue (theTechnique, "gTexture", explosionTexture) end addEventHandler("onClientResourceStart",resourceRoot,replaceEffect) Shader texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } }
×
×
  • Create New...