Jump to content

ds1-e

Scripting Moderators
  • Posts

    636
  • Joined

  • Days Won

    8

Everything posted by ds1-e

  1. ds1-e

    xml vs json

    Hmm, but i heard that XML isn't that efficient, is that related in anyway with saving player settings in cache? Or this doesn't change anything? I mean in server efficienty.
  2. ds1-e

    xml vs json

    Yes, i will try it out, if i wouldn't understand something, i'll give you answer in this topic.
  3. Use loop. An example, of course it can be done better, but you should learn how to use some things. local playerReports = {} function reportFunction(thePlayer, _,...) local word = {...} local message = table.concat(word, " ") local players = getElementsByType("player") for i = 1, #players do local account = getPlayerAccount(players[i]) if isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Admin")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Moderator")) then outputChatBox("Report from "..getPlayerName(thePlayer)..": "..message, players[i], 255, 255, 255, true) playerReports[getPlayerName(thePlayer)] = message end end end addCommandHandler("reportmessage", reportFunction) function checkReports() for k, v in pairs(playerReports) do outputChatBox("Player name: "..k..", reports: "..v) end end addCommandHandler("reports", checkReports) I suggest you to read tutorials:
  4. If script wouldn't be restarted, i would use tables to store them, it's fast + efficient, temporary storage (script keeps data, and after restart it recreates a table)
  5. It's edited function from some chat script. -- meta.xml <meta> <script src="server.lua" type="server"/> </meta> -- server.lua function reportFunction(thePlayer, _,...) local word = {...} local message = table.concat(word, " ") local players = getElementsByType("player") for i = 1, #players do local account = getPlayerAccount(players[i]) if isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Admin")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Moderator")) then outputChatBox("Report from "..getPlayerName(thePlayer)..": "..message, players[i], 255, 255, 255, true) end end end addCommandHandler("reportmessage", reportFunction) Should work, do not forget to implement antiflood thing for this. And about gui, i can't help you with that, i don't like to make it
  6. ds1-e

    xml vs json

    I will need just save a few settings for player, nothing big. I'll try it out, thank you guys for answers.
  7. ds1-e

    xml vs json

    Hey. As title says, which thing is better, xml or json? I want to save player settings in player cache. - What is more efficient? - What is easier to use? If you can, i would like to see an example how to use both.
  8. Hey, i'm gonna try do it soon, if i could figure out how to use this shader
  9. But this is good way to do it, or it's a better soluton for it?
  10. I have found this, it's called grayscale, probably this is what i'm looking for, but i don't know how can i use it. And probably there's no possibility to change intensity of it by script. texture GrayscaleTexture; sampler screenSampler = sampler_state { Texture = <GrayscaleTexture>; }; float4 main(float2 uv : TEXCOORD0) : COLOR0 { float4 Color; Color = tex2D( screenSampler , uv); Color.rgb = round((Color.r+Color.g+Color.b)*10.0f)/30.0f; Color.r=Color.rgb; Color.g=Color.rgb; Color.b=Color.rgb; return Color; }; technique Grayscale { pass P1 { PixelShader = compile ps_2_0 main(); } }
  11. Hey, i'm creating temporary data system for player, with tables. What's the good and efficient way to check if table contains something. For example in table like that: playerTable = { playerItems = {} } table.insert(playerTable.playerItems, {"Item", 1}) for k, v in pairs(playerTable.playerItems) do outputChatBox("item: "..v[1]..", count: "..v[2]) -- item: Item, count: 1 end How i could check if table contains an item called "Item" and count of it?
  12. ds1-e

    Drag'n'Drop

    I have already fixed it, and i fixed a bit that with drawing rectangle if item isn't marked. Now, i need to check somehow, if i user is holding an "row", and if he drops it on button. Any suggestions, for now excluding isCursorOnElement? function onClientGUIMouseDown(button, absoluteX, absoluteY) if button == "left" then if getElementType(source) == "gui-gridlist" then --local itemSelected = guiGridListGetItemText(source, guiGridListGetSelectedItem(source), 1) local itemSelected = guiGridListGetSelectedItem(source) if itemSelected and itemSelected >= 0 then posX = absoluteX posY = absoluteY isHolding = true end end end end addEventHandler("onClientGUIMouseDown", inventoryGridlist["inventory"], onClientGUIMouseDown) function onClientKey(button, press) if not press and button == "mouse1" then isHolding = false end end addEventHandler("onClientKey", getRootElement(), onClientKey) function onClientCursorMove(cursorX, cursorY, absoluteX, absoluteY, worldX, worldY, worldZ) if isHolding then posX = absoluteX posY = absoluteY end end addEventHandler("onClientCursorMove", getRootElement(), onClientCursorMove) function onClientRender() if not isHolding then return end dxDrawRectangle(posX, posY, 200, 15, tocolor(74, 94, 183, 255), true) end addEventHandler("onClientRender", getRootElement(), onClientRender)
  13. ds1-e

    Drag'n'Drop

    Sorry for double post, i can't edit my post above. Updated code: local posX local posY local isHolding = false function onClientGUIMouseDown(button, absoluteX, absoluteY) if button == "left" then if getElementType(source) == "gui-gridlist" then local itemSelected = guiGridListGetItemText(source, guiGridListGetSelectedItem(source), 1) if itemSelected then posX = absoluteX posY = absoluteY isHolding = true end end end end addEventHandler("onClientGUIMouseDown", inventoryGridlist["inventory"], onClientGUIMouseDown) function onClientKey(button, press) if not press and button == "mouse1" then isHolding = false end end addEventHandler("onClientKey", getRootElement(), onClientKey) function onClientCursorMove(cursorX, cursorY, absoluteX, absoluteY, worldX, worldY, worldZ) if isHolding then posX = absoluteX posY = absoluteY end end addEventHandler("onClientCursorMove", getRootElement(), onClientCursorMove) function onClientRender() if not isHolding then return end dxDrawRectangle(posX, posY, 100, 15, tocolor(74, 94, 183, 255), true) end addEventHandler("onClientRender", getRootElement(), onClientRender) Fixed that rectangle doesn't hide after leaving mouse1 click. But following problem still exist: - Rectangle draws, even if item isn't selected. I think i could fix not showing title, but i don't have idea, what i can do with things above.
  14. ds1-e

    Drag'n'Drop

    Thanks but it's not that what i need. Functions which i send above, it's working and it's a good example, what i want to create. I have made some changes in code, changed creating GUI window to dxDrawRectangle to simulate (not moving it in fact) holding a marked row (within OnClientRender). So for now i need to resolve my problems: - How to get where i dropped row? I thought to use isCursorOnElement. - Creating rectangle even if row isn't marked, it shouldn't be like that. - Item title isn't showing all the time.
  15. ds1-e

    Drag'n'Drop

    bump, make it works. but for some reason it creates a window, even if gui item isn't marked, and not always shows title of marked item. local bindWindow local isHolding = false function onClientGUIMouseDown(button, absoluteX, absoluteY) if button == "left" and getElementType(source) == "gui-gridlist" then local itemSelected = guiGridListGetItemText(source, guiGridListGetSelectedItem(source), 1) if itemSelected then bindWindow = guiCreateWindow(absoluteX, absoluteY, 2, 0.2, itemSelected, false) isHolding = true end end end addEventHandler("onClientGUIMouseDown", inventoryGridlist["inventory"], onClientGUIMouseDown) function onClientGUIMouseUp(button, absoluteX, absoluteY) if button == "left" then if isHolding then isHolding = false if isElement(bindWindow) then destroyElement(bindWindow) end end end end addEventHandler("onClientGUIMouseUp", getRootElement(), onClientGUIMouseUp) function onClientCursorMove(cursorX, cursorY, absoluteX, absoluteY, worldX, worldY, worldZ) if bindWindow and isHolding then guiSetPosition(bindWindow, absoluteX, absoluteY, false) end end addEventHandler("onClientCursorMove", getRootElement(), onClientCursorMove)
  16. -- meta.xml <meta> <info author="srslyyyyy" version="1.0" name="Test" type="script"/> <script src="test.lua" type="server"/> </meta> local allowedAuthor = {["srslyyyy"] = true} function testFunction() local author = getResourceInfo(getThisResource(), "author") local allowed_author = allowedAuthor[author] if allowed_author then outputDebugString("Everything okey.") else outputDebugString("Failed to load script.") cancelEvent() end end addEventHandler("onResourceStart", resourceRoot, testFunction) Check, should work, this is for server side, but i think you could do the same on client-side, with OnClientResourceStart. ps: fajny nick
  17. bump. attached_ped = {} attached_bone = {} attached_x = {} attached_y = {} attached_z = {} attached_rx = {} attached_ry = {} attached_rz = {} function attachElementToBone(element,ped,bone,x,y,z,rx,ry,rz) if not (isElement(element) and isElement(ped)) then return false end if getElementType(ped) ~= "ped" and getElementType(ped) ~= "player" then return false end bone = tonumber(bone) if not bone or bone < 1 or bone > 20 then return false end x,y,z,rx,ry,rz = tonumber(x) or 0,tonumber(y) or 0,tonumber(z) or 0,tonumber(rx) or 0,tonumber(ry) or 0,tonumber(rz) or 0 attached_ped[element] = ped attached_bone[element] = bone attached_x[element] = x attached_y[element] = y attached_z[element] = z attached_rx[element] = rx attached_ry[element] = ry attached_rz[element] = rz if setElementCollisionsEnabled then setElementCollisionsEnabled(element,false) end if script_serverside then triggerClientEvent("boneAttach_attach",root,element,ped,bone,x,y,z,rx,ry,rz) end return true end function detachElementFromBone(element) if not element then return false end if not attached_ped[element] then return false end clearAttachmentData(element) if setElementCollisionsEnabled then setElementCollisionsEnabled(element,true) end if script_serverside then triggerClientEvent("boneAttach_detach",root,element) end return true end function isElementAttachedToBone(element) if not element then return false end return isElement(attached_ped[element]) end function getElementBoneAttachmentDetails(element) if not isElementAttachedToBone(element) then return false end return attached_ped[element],attached_bone[element], attached_x[element],attached_y[element],attached_z[element], attached_rx[element],attached_ry[element],attached_rz[element] end function setElementBonePositionOffset(element,x,y,z) local ped,bone,ox,oy,oz,rx,ry,rz = getElementBoneAttachmentDetails(element) if not ped then return false end return attachElementToBone(element,ped,bone,x,y,z,rx,ry,rz) end function setElementBoneRotationOffset(element,rx,ry,rz) local ped,bone,x,y,z,ox,oy,oz = getElementBoneAttachmentDetails(element) if not ped then return false end return attachElementToBone(element,ped,bone,x,y,z,rx,ry,rz) end if not script_serverside then function getBonePositionAndRotation(ped,bone) bone = tonumber(bone) if not bone or bone < 1 or bone > 20 then return false end if not isElement(ped) then return false end if getElementType(ped) ~= "player" and getElementType(ped) ~= "ped" then return false end if not isElementStreamedIn(ped) then return false end local x,y,z = getPedBonePosition(ped,bone_0[bone]) local rx,ry,rz = getEulerAnglesFromMatrix(getBoneMatrix(ped,bone)) return x,y,z,rx,ry,rz end end ------------------------------------ function clearAttachmentData(element) attached_ped[element] = nil attached_bone[element] = nil attached_x[element] = nil attached_y[element] = nil attached_z[element] = nil attached_rx[element] = nil attached_ry[element] = nil attached_rz[element] = nil end function forgetDestroyedElements() if not attached_ped[source] then return end clearAttachmentData(source) end addEventHandler(script_serverside and "onElementDestroy" or "onClientElementDestroy",root,forgetDestroyedElements) function forgetNonExistingPeds() local checkedcount = 0 while true do for element,ped in pairs(attached_ped) do if not isElement(ped) then clearAttachmentData(element) end checkedcount = checkedcount+1 if checkedcount >= 1000 then coroutine.yield() checkedcount = 0 end end coroutine.yield() end end clearing_nonexisting_peds = coroutine.create(forgetNonExistingPeds) --setTimer(function() coroutine.resume(clearing_nonexisting_peds) end,1000,0) --[[setTimer(function() if not clearing_nonexisting_peds or coroutine.status(clearing_nonexisting_peds) == "dead" then clearing_nonexisting_peds = coroutine.create(forgetNonExistingPeds) end coroutine.resume(clearing_nonexisting_peds) end, 1000, 0)]] setTimer(function() if coroutine.status (clearing_nonexisting_peds) == "dead" then clearing_nonexisting_peds = coroutine.create(forgetNonExistingPeds) end coroutine.resume(clearing_nonexisting_peds) end, 10000, 0) attach_func.lua:105: invalid key to 'next' [string "?"]
  18. Ah so, functions have own limit and file have own limit, yes?
  19. What if script file will reach locals variables limit? I saw script with 300 + local variables, and it was working well.
  20. Hey, i need some shader for modify player screen colors (more or less faded).
  21. ds1-e

    Drag'n'Drop

    I have found this event: onClientGUIMouseDown - This event is fired when the user clicks certain mouse button on a GUI element. And example for it: -- This example show how to add very basic click'n'drag feature for GUI elements (only for those which parent element is gui-root) addEventHandler( "onClientGUIMouseDown", getRootElement( ), function ( btn, x, y ) if btn == "left" then clickedElement = source; -- store the clicked element in a global variable local elementPos = { guiGetPosition( source, false ) }; offsetPos = { x - elementPos[ 1 ], y - elementPos[ 2 ] }; -- get the offset position end end ); addEventHandler( "onClientGUIMouseUp", getRootElement( ), function ( btn, x, y ) if btn == "left" then clickedElement = nil; end end ); addEventHandler( "onClientCursorMove", getRootElement( ), function ( _, _, x, y ) if clickedElement then guiSetPosition( clickedElement, x - offsetPos[ 1 ], y - offsetPos[ 2 ], false ); end end ); Those three events should work for row(s)? After some changes. UPD: @Ab-47 i will try it.
  22. But when variables are saved in local table, it's really big difference in it comparing to define variable as local?
  23. What about packing variables in local table? Shouldn't result be similar to define variable as local? And still it should be faster than global variable, atleast i think so. (For let you know i have small count of global variables.)
×
×
  • Create New...