sirrjohn
-
Posts
28 -
Joined
-
Last visited
-
Days Won
1
Posts posted by sirrjohn
-
-
I have a simple script that gets a .txt from my website, it fetches correctly the said key but takes awhile, making resources that uses that key fail to start as thats what the protection does, cancels onResourcesStart if it can't fetch the key or if it is wrong.
I've tried onResourcePreStart but no success, also download priority on meta.xml.
Is there a way to delay every other resource startup or dont make any of them load before it fetches?
Or another way to solve this?
Code below.
Credits to Lord Henry for 98% of the code, I just edited to make it fetch a file not an ip from web, and some other stuff, but pretty much all the code is from him.
P.s: if there is something wrong its my addition and my fault ok
function startIPChecking () fetchRemote ("http://***.com/key.txt", myCallback, "", false) end addEventHandler ("onResourceStart", resourceRoot, startIPChecking)
function myCallback (responseData, errors) if (errors == 0) then KEY = tostring(responseData) print("server authorized") else KEY = "error" print("server not authorized") end end function getKey() return KEY end
Protected script
addEventHandler("onResourceStart", resourceRoot, function() local keyy = exports["secur"]:getKey () if not keyy then return cancelEvent() end if keyy ~= "****" then return cancelEvent() else ---- code if verification OK ...
-
Since i cant edit:
Decided to do it a diff way, using imageSection
health = exports["extra_health"]:getElementExtraHealth(peds) local healthround = math.ceil(health) local life_pc = (health / 1000) * 100 local vida_atual = life_pc*1.28 dxDrawImage(sx-60, sy- 70, 128, 16, "healthbarbg.png") dxDrawImageSection(sx-60, sy- 70, vida_atual, 16, 0, 0, vida_atual, 16, "healthbar.png") dxDrawText(healthround,sx-40+25,sy-70,sx, sy,tocolor ( 255, 255, 255, 255 ), 1,"sans")
I just couldn't get the max health value so i had to put it manually, but it works.
Problem now is when ped health reaches 0 it doesnt die... i need to shoot him a few more times, using extra_health script
addEventHandler("onClientPedDamage", root, function(attacker, weapon, _, loss) if isElementInvulnerable(source) then cancelEvent() else local health = getElementExtraHealth(source) if health >= loss then setElementExtraHealth(source, health - loss) cancelEvent() end end end )
-
For some reason this script when ped is with high health (im using extra_health resource), when u shoot him its life bar only visually lowers after his life is low... if his health is high it wont even move or visually reduce the health bar.
PS: Health works fine issue is only with the bar.
I'm sure the code is wrong, I just need a little help with calculations here I believe... not sure.
local maxHealth = 1000000 local healthPercentage = health / maxHealth local lineLength = 150 * healthPercentage local healthBar = dxDrawRectangle(sx - 60, sy - 70, lineLength, 7, tocolor(255, 0, 0, 210))
Appreciate all the help, I'm trying to not bother you guys here and trying to do by myself but this issue got me.
-
13 hours ago, DiSaMe said:
There seems to be confusion between variables due to a poor choice of names. ped is a table of all peds while peds is the current ped in the iteration. Because of that, the sound handle inserted into the table in one iteration still gets overridden in the other - because ped is the same value between iterations (always refers to the table of all peds). So it's better to swap them. But with the current names, you're supposed to use spawnedSounds[peds] to refer to the current ped's sound, and pass peds to getElementData.
It works now, but with many DUPS...
spawnedSounds = {} function playZombieSounds() local ped = getElementsByType("ped") for theKey,peds in ipairs(ped) do if ped and isElement(peds) and isElementStreamedIn(peds) then local Zx,Zy,Zz = getElementPosition(peds) zedSound = playSound3D(zombiesounds[math.random(1,#zombiesounds)], Zx, Zy, Zz, false) spawnedSounds[peds] = zedSound for theKey,theSound in pairs(spawnedSounds) do if getElementData(peds,"deadzombie") then stopSound(theSound) end end end end end setTimer(playZombieSounds,6000,0)
-
13 hours ago, Addlibs said:
for theKey,peds in ipairs(ped) do if ped and isElement(peds) and isElementStreamedIn(peds) then local Zx,Zy,Zz = getElementPosition(peds) zedSound = playSound3D(zombiesounds[math.random(1,#zombiesounds)], Zx, Zy, Zz, false)
zedSound variable is overwritten for every ped. This means you're creating new sounds but discarding the pointer/reference/element handle for the old one. The old one will thus remain playing and you have no way* to delete it. What you need instead is a table of sounds you've spawned, and when you call stopSound, you should call it once per sound element in that table. This should stop all the sounds you've created.
Example:
-- when creating spawnedSounds = {} for theKey,peds in ipairs(ped) do if ped and isElement(peds) and isElementStreamedIn(peds) then local Zx,Zy,Zz = getElementPosition(peds) zedSound = playSound3D(zombiesounds[math.random(1,#zombiesounds)], Zx, Zy, Zz, false) -- do whatever with zedSound spawnedSounds[ped] = zedSound -- store the zedSound into a table for later when calling stopSound -- when stopping for theKey,theSound in pairs(spawnedSounds) do -- go through each sound in the table (note the use of pairs is -- essential if the keys of the table are not numerical and sequential: in this case they are elements so pairs, is needed) -- (also NB: some performance comparisons point out pairs is faster than ipairs even with sequential numeric tables -- so you can just blindly always use pairs instead of ipairs without performance impact) stopSound(theSound) -- stop the sound that is stored as the value of a key=value pair in each row of the table end
* You can still recover the pointer/reference/element handle though functions like getElementsByType for sound type but its going to be much harder to identify which one you want.
It seems its working, but how to stop sound only when ped is dead?
i tried this, didnt work
spawnedSounds = {} function playZombieSounds() local ped = getElementsByType("ped") for theKey,peds in ipairs(ped) do if ped and isElement(peds) and isElementStreamedIn(peds) then local Zx,Zy,Zz = getElementPosition(peds) zedSound = playSound3D(zombiesounds[math.random(1,#zombiesounds)], Zx, Zy, Zz, false) spawnedSounds[ped] = zedSound for theKey,theSound in pairs(spawnedSounds) do if getElementData(ped,"deadman") or getElementData(ped,"Muerto") then stopSound(theSound) end end end end end setTimer(playZombieSounds,6000,0)
-
please guys?
-
5 hours ago, Bishop_G said:
function playZombieSounds() local ped = getElementsByType("ped") for theKey,peds in ipairs(ped) do if ped and isElement(peds) and isElementStreamedIn(peds) then if getElementData(peds,"deadman") or getElementData(peds,"Muerto") return end local Zx,Zy,Zz = getElementPosition(peds) zedSound = playSound3D(zombiesounds[math.random(1,#zombiesounds)], Zx, Zy, Zz, false) setSoundMaxDistance(zedSound,5) end end end setTimer(playZombieSounds,6000,0)
Hey Bishop! Sadly it didnt work... I had the same code on a different zombie gamemode and there it worked fine... but on this one it doesnt.. zombies keep making sounds when dead
-
I get the following error
-- PLAY ZOMBIE SOUNDS local zombiesounds = { "Sonidos/zgroan (1).ogg", "Sonidos/zgroan (2).ogg", "Sonidos/zgroan (3).ogg", "Sonidos/zgroan (4).ogg", "Sonidos/zgroan (5).ogg", "Sonidos/zgroan (6).ogg", "Sonidos/zgroan (7).ogg", "Sonidos/zgroan (8).ogg", "Sonidos/zgroan (9).ogg", "Sonidos/zgroan (10).ogg", "Sonidos/zgroan (11).ogg", "Sonidos/zgroan (12).ogg", "Sonidos/zgroan (13).ogg", "Sonidos/zgroan (14).ogg", "Sonidos/zgroan (15).ogg", "Sonidos/zgroan (16).ogg", "Sonidos/zgroan (17).ogg", "Sonidos/zgroan (18).ogg", "Sonidos/zgroan (19).ogg", "Sonidos/zgroan (20).ogg", "Sonidos/zgroan (21).ogg", "Sonidos/zgroan (22).ogg", "Sonidos/zgroan (23).ogg", "Sonidos/zgroan (24).ogg", "Sonidos/zgroan (25).ogg", "Sonidos/zgroan (26).ogg", "Sonidos/zgroan (27).ogg", "Sonidos/zgroan (28).ogg", "Sonidos/zgroan (29).ogg", "Sonidos/zgroan (30).ogg", "Sonidos/zgroan (31).ogg", "Sonidos/zgroan (32).ogg", "Sonidos/zgroan (33).ogg", "Sonidos/zgroan (34).ogg", "Sonidos/zgroan (35).ogg", "Sonidos/zgroan (36).ogg", } zedSound = false function playZombieSounds() local ped = getElementsByType("ped") for theKey,peds in ipairs(ped) do if ped and isElement(peds) and isElementStreamedIn(peds) then local Zx,Zy,Zz = getElementPosition(peds) zedSound = playSound3D(zombiesounds[math.random(1,#zombiesounds)], Zx, Zy, Zz, false) setSoundMaxDistance(zedSound,5) end if getElementData(peds,"deadman") or getElementData(peds,"Muerto") then stopSound(zedSound) end end end setTimer(playZombieSounds,6000,0)
-
For anyone who needs:
For anyone who needs, put in clientside, tested and working
function mutePeds() local peds = getElementsByType("ped") for _, ped in ipairs(peds) do setPedVoice(ped, "PED_TYPE_DISABLED") end setPedVoice(localPlayer, "PED_TYPE_DISABLED") end addEventHandler("onClientResourceStart",root,mutePeds)
-
Hi, Is it possible to mute all peds from saying anything? including main player?
-
3 hours ago, FlorinSzasz said:
function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) else setElementData(source,"combattime",getAccountData(playerAccount,"combattime") or 0) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") -- exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setElementData(source,"combattime",0) end,5000,1,source) end addEvent("setAccount1",true) function setAccount1() if client then setElementData(client,"combattime",1) end end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount2", true) function setAccount2() if client then setElementData(client,"combattime",0) end end addEventHandler("setAccount2", root, setAccount2) function saveData() local a = getPlayerAccount(source); if a then outputDebugString(getElementData(source,"combattime")) setAccountData(a,"combattime",getElementData(source,"combattime")) end end addEventHandler("onPlayerQuit",getRootElement(),saveData)
Server Here,
Now client:
combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) if source == localPlayer then guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) triggerServerEvent("setAccount1", localPlayer) setTimer(function(localPlayer) triggerServerEvent("setAccount2", localPlayer) guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel, 17, 249, 5) end,10000,1,localPlayer) end end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog)
It should work is tested now.
Also when u trigger a server event always check for client because source can be some fake data and in more complicated scripts it can create problems. Thats why i used client when i trigger a server event!
Hey, same error
[18:37:14] ERROR: Client (Sirr) triggered serverside event setAccount1, but event is not added serverside
[18:37:24] ERROR: Client (Sirr) triggered serverside event setAccount2, but event is not added serversideI found out server was not even running thats why it says that message... i removed some other code i dont use from server.lua and it now works 100% !! thank you very much !!!!
- 1
-
didnt work but I think its something about "my" code thats not right...
like
[13:10:16] ERROR: Client (Sirr) triggered serverside event getAccount, but event is not added serverside
[13:10:26] ERROR: Client (Sirr) triggered serverside event setAccount2, but event is not added serversidewhy does it says that if both events are in my server.lua file? 100% sure as you can see in the script above
- 1
-
Hey guys, I know this code is a mess, I've been messing around with it trying to get it to work but its not 100% working
What does not work:
- When player leaves the server its not saving his new "combattime" AccountData value to db (which if he was in combat mode when he left, it should be 1 when he logs back in, but its always 0)
Appreciate any help
server
function spawn() setTimer(function(source) outputChatBox("This server is protected by BattlDayZ (V1.1), an anticheat system.",source,255,0,0) end,2000,1,source) local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,"combattime") == 1 then setTimer ( killhim, 7000, 1,source) end end addEventHandler("onPlayerLogin",root,spawn) function killhim(source) outputChatBox("you got killed for disconnecting during a fight!") exports.DayZ:setPlayerBlood(source,-5) setTimer(function(source) setAccountData(source,"combattime",0) end,5000,1,source) end function setAccount1(source) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount,"combattime",1) end addEventHandler("setAccount1", root, setAccount1) addEvent("setAccount1", true) function setAccount2(source) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount,"combattime",0) end addEventHandler("setAccount2", root, setAccount2) addEvent("setAccount2", true) function getAccount(source) local playerAccount = getPlayerAccount(source) getter = getAccountData(playerAccount,"combattime") end addEventHandler("getAccount", root, getAccount) addEvent("getAccount", true)
client
combatloglabel = guiCreateLabel(0.82, 0.00, 0.27, 0.04, "A", true) guiSetVisible(combatloglabel,false) function createLogLabel() guiSetVisible(combatloglabel,true) guiLabelSetColor(combatloglabel, 17, 249, 5) guiLabelSetHorizontalAlign(combatloglabel, "center", false) guiLabelSetVerticalAlign(combatloglabel, "center") guiSetText(combatloglabel,"[Out of combat]") end addEventHandler("onClientPlayerSpawn",localPlayer,createLogLabel) function onPlayerActivateCombatLog(attacker) triggerServerEvent("getAccount", source) outputChatBox("getAccount OK") if getter == 0 then guiSetText(combatloglabel,"[Out of combat]") guiLabelSetColor(combatloglabel,0,255,0) outputChatBox("getter == 0") else guiSetText(combatloglabel,"[In combat]\nDont disconnect or you will die") guiLabelSetColor(combatloglabel,255,0,0) outputChatBox("getter == 1") end setTimer(function(source) outputChatBox("timer") triggerServerEvent("setAccount2", source) end,10000,1,source) end addEventHandler("onClientPlayerDamage",root,onPlayerActivateCombatLog)
- 1
-
12 hours ago, Lord Henry said:
Se o script for server-side, o último parâmetro do createBlip é o jogador para quem ele será visível. Se não especificar esse parâmetro, ele será visível para todo mundo.
Mas não teria que ter uma verificação em cima do elementdata "owner" e só se o jogador for dono da base aparecer o blip dela para ele?
-
Olá pessoal, possuo um script de criação de bases para DayZ, e quando uso
local blipbase = createBlip(x, y, z-1, 56)
ele cria blips de todas as bases existentes no mapa
Eu gostaria de criar apenas os blips para as bases que o jogador possui, e apenas para ele especificamente, é possível?
function createBase(row) local id = tonumber(row['id']) local object = tonumber(row['object']) local owner = tostring(row['serialowner']) local x = tonumber(row['x']) local y = tonumber(row['y']) local z = tonumber(row['z']) local r = tonumber(row['r']) object = tonumber(object) if object == 2681 then zmin = -91.1 elseif object == 2754 then zmin = -80.5 elseif object == 2779 then zmin = -75.5 else outputChatBox("The base object ID is not valid!",source) return false end local base_o = createObject(object,x,y,zmin) setElementRotation(base_o,0,0,r) local marker = createMarker ( x, y, z-1, "cylinder", 3, 255, 255, 255, 20 ) -- Вход local marker2 = createMarker ( x,y,-95, "cylinder", 3, 255, 255, 255, 20 ) -- Выход setElementData(marker, "id", id) setElementData(marker2, "id", id) setElementData(marker, "bases", true) setElementData(marker2, "bases", true) setElementData(marker, "verh1niz2", 1) setElementData(marker2, "verh1niz2", 2) baseCol = createColTube(x,y,-125,120,90) setElementData(baseCol,"base",true) setElementData(baseCol,"base_o",base_o) setElementData(baseCol,"owner",owner) setElementData(baseCol,"id",id) setElementData(baseCol,"marker",marker) setElementData(baseCol,"marker2",marker2) end
-
Oi amigo seu código estava correto, é que estava gerando itens que nao existiam rs ai achava que nao tinha nenhum ou que nunca tinha mais de 1. mas na verdade eles eram criados mas sem existir por isso não apareciam.
Obrigado!! tudo ok.
-
21 minutes ago, gustavorn said:
Não há de que, amigo. Vamos tentar adicionar mais uma função para simular a alternância de 1 a 4 itens.
-- Função para adicionar de 1 a 4 itens da lista lootItems ao airdrop function addRandomItemsToAirdrop(avialColq) for i = 1, math.random(1, 4) do local item = lootItems[math.random(#lootItems)] local value = math.percentChance(item[2], 1) if value >= 1 then setElementData(avialColq, item[1], value) local ammoData, weapID = getWeaponAmmoType(item[1], true) if ammoData then local minBullets, maxBullets = math.floor(getAmmoPlus(ammoData) / 3), getAmmoPlus(ammoData) * 2 local ammoQuantity = math.random(minBullets, maxBullets) setElementData(avialColq, ammoData, ammoQuantity) end end end end function spawnAirdrop(player) -- Verifica se o jogador não é um administrador if isElement(player) and not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then return end -- Limpa objetos e timers antigos if isElement(productq) then destroyElement(productq) end if isElement(avialColq) then destroyElement(avialColq) end if isElement(blipq) then destroyElement(blipq) end if isElement(variavel) then destroyElement(variavel) end if isTimer(respawnAirdropTimer) then killTimer(respawnAirdropTimer) end -- Define um novo timer para respawn do airdrop respawnAirdropTimer = setTimer(spawnAirdrop, 120000, 1) -- Escolhe aleatoriamente uma localização para o airdrop local item_id = math.random(1, #spawnLocations) xq, yq, zq = spawnLocations[item_id][1], spawnLocations[item_id][2], spawnLocations[item_id][3] + 0.35 xpsq, ypsq, zpsq = xq, yq, zq + 7 xpvq, ypvq, zpvq = xq - 48, yq - 16, zq + 37 xsbq, ysbq, zsbq = xq - 48, yq - 16, zq + 41 xssq, yssq, zssq = xq - 528, yq + 2, zq + 141 xsdq, ysdq, zsdq = xq + 528, yq + 2, zq + 141 -- Cria um blip para o airdrop blipq = createBlip(xq, yq, zq, 5) -- Criação do avião e movimentação aviaNavaq = createObject(1683, xssq, yssq, zssq, 0, 0, 0) moveObject(aviaNavaq, 8000, xsbq, ysbq, zsbq) -- Criação do paraquedas setTimer(function() parasProdq = createObject(2903, xpvq, ypvq, zpvq, 0, 0, 0) moveObject(aviaNavaq, 8000, xsdq, ysdq, zsdq) moveObject(parasProdq, 15000, xpsq, ypsq, zpsq) triggerClientEvent("playAirdropSound", getRootElement()) outputChatBox("#ff0000[AIRDROP] #ffffffUM PACOTE COM LOOT MILITAR FOI LANÇADO AO CHÃO. SEU MAPA FOI MARCADO COM O LOCAL.", getRootElement(), 255, 255, 255, true) end, 8000, 1) -- Define um timer para destruir o avião setTimer(destroyElement, 16100, 1, aviaNavaq) -- Cria o conteúdo do airdrop setTimer(function() destroyElement(parasProdq) destroyElement(variavel) productq = createObject(2669, xq, yq, zq, 0, 0, 0) variavel = createObject(2060, xq, yq, zq + 1.3, 1, 0, 0) setElementFrozen(productq, true) avialColq = createColSphere(xq, yq, zq, 2) attachElements(avialColq, productq, 0, 0, 0) setElementData(avialColq, "parent", object) setElementData(avialColq, "hospitalbox", true) setElementData(avialColq, "MAX_Slots", 5000) -- Chama a função para adicionar itens aleatórios addRandomItemsToAirdrop(avialColq) end, 23100, 1) end
Não tenho mais o jogo instalado mas acredito que funcione. Espero que ajude, abraços!
Não deu certo está dando 0 itens, eu vou postar o script inteiro ok pode ser isso, talvez está em outro lugar o problema
spawnLocations = { {314.83642578125,2506.2631835938,16.484375}, --1 {2617.6479492188,825.74291992188,5.3157968521118}, --2 {1576.1378173828,1447.9056396484,10.831636428833}, --3 {1691.6828613281,1448.0660400391,10.76537322998}, --4 {2004.66015625,1544.4243164063,13.590750694275}, --5 {2181.5466308594,1676.5620117188,11.064884185791}, --6 {2448.1176757813,1273.7723388672,10.8203125}, --7 {2137.3835449219,1442.6499023438,10.8203125}, --8 {2575.3510742188,1824.5400390625,10.8203125}, --9 {2419.8813476563,1920.921875,6.015625}, --10 {2240.4582519531,2045.9215087891,11.0625}, --11 {2179.2749023438,1989.0098876953,10.8203125}, --12 {2127.1943359375,2358.7133789063,10.8203125}, --13 {1997.0966796875,2490.3330078125,10.830327987671}, --14 {1615.7999267578,2377.9553222656,10.8203125}, --15 {1490.2097167969,2188.0922851563,10.8203125}, --16 {1347.8723144531,2153.9106445313,11.015625}, --17 {957.20593261719,2036.7243652344,10.8203125}, --18 {960.08746337891,1730.7059326172,8.6484375}, --19 {271.10870361328,1412.4757080078,10.456546783447}, --20 {10.840476989746,1527.2421875,12.75}, --21 {-334.07357788086,1523.8828125,75.359375}, --22 {-299.88012695313,1025.5218505859,19.59375}, --23 {-702.23919677734,965.90991210938,12.38724899292}, --24 {364.03866577148,874.66436767578,20.40625}, --25 {1088.8571777344,1072.4573974609,10.8359375}, --26 {1489.9666748047,726.11511230469,10.8203125}, --27 {68.575103759766,-254.28695678711,1.578125}, --28 {-864.30541992188,1554.6318359375,23.846151351929}, --29 {-740.29302978516,2058.623046875,60.381847381592}, --30 {-1291.6973876953,2695.0310058594,50.0625}, --31 {-1406.4880371094,2642.3232421875,55.6875}, --32 {-2264.1694335938,2315.4348144531,4.8125}, --33 {-2466.390625,2232.5173339844,4.8093810081482}, --34 {-2614.7595214844,2258.6372070313,8.1994504928589}, --35 {-2681.3798828125,1815.4410400391,68.126068115234}, --36 {224.79331970215,-1832.55859375,3.7705931663513}, --37 {284.9049987793,-1176.2043457031,80.9140625}, --38 {755.96240234375,-1257.9576416016,13.564019203186}, --39 {773.50372314453,-1358.9060058594,13.535238265991},--40 {1128.8109130859,-1447.4973144531,15.796875}, --41 {1268.8708496094,-1251.5638427734,13.722779273987}, --42 {1588.3646240234,-1617.8371582031,13.3828125}, --43 {836.51336669922,-1999.4309082031,12.8671875}, --45 {977.61590576172,-2148.6538085938,13.09375}, --46 {1766.6722412109,-2543.4919433594,13.546875}, --47 {1786.4699707031,-1913.0993652344,13.39405632019}, --48 {1880.51953125,-1395.1171875,13.5703125}, --49 {2101.5480957031,-1572.7170410156,13.371836662292}, --50 {2316.2751464844,-1527.4803466797,25.34375}, --51 {2225.3930664063,-1343.8658447266,23.984144210815},--52 {2154.4069824219,-1168.8410644531,23.821853637695}, --53 {2217.7885742188,-1164.4217529297,25.7265625}, --54 {2028.7626953125,-1195.8115234375,21.663816452026}, --55 {1698.3475341797,-1053.8067626953,23.90625}, --56 {2488.0227050781,-1670.6463623047,13.335947036743}, --57 {2592.5354003906,-1560.2576904297,9.0321044921875}, --58 {2780.2709960938,-1855.2202148438,9.799732208252}, --59 {2874.2202148438,-1572.2838134766,11.100312232971}, --60 {2366.556640625,-111.22863769531,27.541097640991}, --61 {2140.7541503906,-70.945930480957,2.9356446266174}, --62 {-2531.8095703125,1229.8636474609,37.428329467773}, --63 {-2457.4055175781,730.96234130859,35.022338867188},--64 {-2511.1162109375,353.08959960938,35.1171875}, --65 {-2906.40625,472.73828125,4.9140625},--66 {-2327.1994628906,194.27606201172,35.3125},--67 {-2414.2265625,428.54388427734,34.9609375},--68 {-2087.9938964844,261.86730957031,35.669929504395},--69 {-1918.8548583984,264.65570068359,41.046875},--70 {-1968.3210449219,188.20690917969,27.15994644165},--71 {-2182.8562011719,-409.66201782227,35.3359375},--72 {-2406.6630859375,-597.85241699219,132.6484375},--73 {-2520.9538574219,-608.611328125,132.5625},--74 {-2140.0119628906,-860.41796875,32.0234375},--75 {-1515.9364013672,-401.26516723633,7.078125},--76 {-1328.1328125,-17.730365753174,14.1484375},--77 {-1653.7340087891,290.01672363281,7.1875},--78 {-1839.4580078125,144.68249511719,15.1171875},--79 {-1628.8912353516,664.92175292969,7.1875},--80 {-1504.8503417969,737.44427490234,7.1875},--81 {-1833.3952636719,-1574.7811279297,21.75},--82 {-2328.5769042969,-1628.1723632813,483.7038269043},--83 {-2209.6984863281,-2366.5932617188,30.892566680908},--84 {-2011.8569335938,-2430.955078125,30.618188858032},--85 {-1538.6431884766,-2756.8186035156,48.5390625},--86 {-1119.9534912109,-2857.6271972656,67.71875},--87 {-25.108991622925,-2509.640625,36.6484375},--88 } lootItems = { {"M4A1",70}, {"M4A3 CCO",70}, {"M16A2",70}, {"Steyr AUG",70}, {"AKS (gold)",70}, {"AKM",70}, {"AK-74",70}, {"AK-107",70}, {"G36C (camo)",70}, {"FN FAL",70}, {"LK-05 SD",70}, {"FN SCAR-L",70}, {"DMR",70}, {"M107",60}, {"M40A3",60}, {"AS50",60}, {"KSVK",60}, {"M249 SAW",40}, {"PKM",30}, {"MG36",30}, {"M240",30}, {"Mk 48 Mod 0",30}, {"Medic Kit",85}, {"Painkiller",50}, {"Morphine",50}, {"Bandage",50}, {"Toolbox",80}, {"Scrap Metal",34}, {"Steel Sheet",100}, {"Engine",43}, {"Tire",43}, {"Tank Parts",43}, {"MP5SD6",50}, {"Revolver",50}, {"Coyote Camo Backpack",60}, {"Drybag Backpack",80}, {"Alice Backpack",70}, {"Czech Backpack",60}, {"Motorbike Helmet 1",50}, {"Police Vest",50}, {"UK Vest Black",50}, {"Gas Mask 2",50}, } function math.percentChance(percent,repeatTime) local hits = 0 for i = 1,repeatTime do local number = math.random(1,1000)/10 if number <= percent then hits = hits+1 end end return hits end respawnAirdropTimer = false -- Função para adicionar de 1 a 4 itens da lista lootItems ao airdrop function addRandomItemsToAirdrop(avialColq) for i = 1, math.random(1, 4) do local item = lootItems[math.random(#lootItems)] local value = math.percentChance(item[2], 1) if value >= 1 then setElementData(avialColq, item[1], value) local ammoData, weapID = getWeaponAmmoType(item[1], true) if ammoData then local minBullets, maxBullets = math.floor(getAmmoPlus(ammoData) / 3), getAmmoPlus(ammoData) * 2 local ammoQuantity = math.random(minBullets, maxBullets) setElementData(avialColq, ammoData, ammoQuantity) end end end end function spawnAirdrop(player) -- Verifica se o jogador não é um administrador if isElement(player) and not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then return end -- Limpa objetos e timers antigos if isElement(productq) then destroyElement(productq) end if isElement(avialColq) then destroyElement(avialColq) end if isElement(blipq) then destroyElement(blipq) end if isElement(variavel) then destroyElement(variavel) end if isTimer(respawnAirdropTimer) then killTimer(respawnAirdropTimer) end -- Define um novo timer para respawn do airdrop respawnAirdropTimer = setTimer(spawnAirdrop, 120000, 1) -- Escolhe aleatoriamente uma localização para o airdrop local item_id = math.random(1, #spawnLocations) xq, yq, zq = spawnLocations[item_id][1], spawnLocations[item_id][2], spawnLocations[item_id][3] + 0.35 xpsq, ypsq, zpsq = xq, yq, zq + 7 xpvq, ypvq, zpvq = xq - 48, yq - 16, zq + 37 xsbq, ysbq, zsbq = xq - 48, yq - 16, zq + 41 xssq, yssq, zssq = xq - 528, yq + 2, zq + 141 xsdq, ysdq, zsdq = xq + 528, yq + 2, zq + 141 -- Cria um blip para o airdrop blipq = createBlip(xq, yq, zq, 5) -- Criação do avião e movimentação aviaNavaq = createObject(1683, xssq, yssq, zssq, 0, 0, 0) moveObject(aviaNavaq, 8000, xsbq, ysbq, zsbq) -- Criação do paraquedas setTimer(function() parasProdq = createObject(2903, xpvq, ypvq, zpvq, 0, 0, 0) moveObject(aviaNavaq, 8000, xsdq, ysdq, zsdq) moveObject(parasProdq, 15000, xpsq, ypsq, zpsq) triggerClientEvent("playAirdropSound", getRootElement()) outputChatBox("#ff0000[AIRDROP] #ffffffUM PACOTE COM LOOT MILITAR FOI LANÇADO AO CHÃO. SEU MAPA FOI MARCADO COM O LOCAL.", getRootElement(), 255, 255, 255, true) end, 8000, 1) -- Define um timer para destruir o avião setTimer(destroyElement, 16100, 1, aviaNavaq) -- Cria o conteúdo do airdrop setTimer(function() destroyElement(parasProdq) destroyElement(variavel) productq = createObject(2669, xq, yq, zq, 0, 0, 0) variavel = createObject(2060, xq, yq, zq + 1.3, 1, 0, 0) setElementFrozen(productq, true) avialColq = createColSphere(xq, yq, zq, 2) attachElements(avialColq, productq, 0, 0, 0) setElementData(avialColq, "parent", object) setElementData(avialColq, "hospitalbox", true) setElementData(avialColq, "MAX_Slots", 5000) -- Chama a função para adicionar itens aleatórios addRandomItemsToAirdrop(avialColq) end, 23100, 1) end spawnAirdrop() addCommandHandler("spawnairdrop",spawnAirdrop) addCommandHandler("removeairdrop",function(player) if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then return end if isElement(productq) then destroyElement(productq) end if isElement(avialColq) then destroyElement(avialColq) end if isElement(blipq) then destroyElement(blipq) end if isElement(variavel) then destroyElement(variavel) end if isTimer(respawnAirdropTimer)then killTimer(respawnAirdropTimer) end end)
-
33 minutes ago, gustavorn said:
Fala meu brother, como vai você? Que nostalgia me aventurar neste ambiente tão legal de comunicado aqui de novo, após tanto tempo. Vou tentar te ajudar, afinal faz tempo que não sei o que é Lua, viu? Kkkk!
Em resposta a sua dúvida, irei responder, levando em conta que você saiba algo sobre lógica de programação.
Existem vários objetos (itens) com chave e valor sendo armazenado dentro da nossa variável (lista) lootItems, desta forma, certifique-se de que está lista contenha todos os itens que precisam ser adicionados.
Agora, vamos para a função. Comentei em blocos para identar o código e melhorar o entendimento.
function spawnAirdrop(player) -- Verifica se o jogador não é um administrador if isElement(player) and not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then return end -- Limpa objetos e timers antigos if isElement(productq) then destroyElement(productq) end if isElement(avialColq) then destroyElement(avialColq) end if isElement(blipq) then destroyElement(blipq) end if isElement(variavel) then destroyElement(variavel) end if isTimer(respawnAirdropTimer) then killTimer(respawnAirdropTimer) end -- Define um novo timer para respawn do airdrop respawnAirdropTimer = setTimer(spawnAirdrop, 120000, 1) -- Escolhe aleatoriamente uma localização para o airdrop local item_id = math.random(1, #spawnLocations) xq, yq, zq = spawnLocations[item_id][1], spawnLocations[item_id][2], spawnLocations[item_id][3] + 0.35 xpsq, ypsq, zpsq = xq, yq, zq + 7 xpvq, ypvq, zpvq = xq - 48, yq - 16, zq + 37 xsbq, ysbq, zsbq = xq - 48, yq - 16, zq + 41 xssq, yssq, zssq = xq - 528, yq + 2, zq + 141 xsdq, ysdq, zsdq = xq + 528, yq + 2, zq + 141 -- Cria um blip para o airdrop blipq = createBlip(xq, yq, zq, 5) -- Criação do avião e movimentação aviaNavaq = createObject(1683, xssq, yssq, zssq, 0, 0, 0) moveObject(aviaNavaq, 8000, xsbq, ysbq, zsbq) -- Criação do paraquedas setTimer(function() parasProdq = createObject(2903, xpvq, ypvq, zpvq, 0, 0, 0) moveObject(aviaNavaq, 8000, xsdq, ysdq, zsdq) moveObject(parasProdq, 15000, xpsq, ypsq, zpsq) triggerClientEvent("playAirdropSound", getRootElement()) outputChatBox("#ff0000[AIRDROP] #ffffffUM PACOTE COM LOOT MILITAR FOI LANÇADO AO CHÃO. SEU MAPA FOI MARCADO COM O LOCAL.", getRootElement(), 255, 255, 255, true) end, 8000, 1) -- Define um timer para destruir o avião setTimer(destroyElement, 16100, 1, aviaNavaq) -- Cria o conteúdo do airdrop setTimer(function() destroyElement(parasProdq) destroyElement(variavel) productq = createObject(2669, xq, yq, zq, 0, 0, 0) variavel = createObject(2060, xq, yq, zq + 1.3, 1, 0, 0) setElementFrozen(productq, true) avialColq = createColSphere(xq, yq, zq, 2) attachElements(avialColq, productq, 0, 0, 0) setElementData(avialColq, "parent", object) setElementData(avialColq, "hospitalbox", true) setElementData(avialColq, "MAX_Slots", 5000) -- Adiciona de 1 a 4 itens da lista lootItems for i = 1, math.random(1, 4) do local item = lootItems[math.random(1, #lootItems)] local value = math.percentChance(item[2], 1) if value >= 1 then setElementData(avialColq, item[1], value) local ammoData, weapID = getWeaponAmmoType(item[1], true) if ammoData then local minBullets, maxBullets = math.floor(getAmmoPlus(ammoData) / 3), getAmmoPlus(ammoData) * 2 local ammoQuantity = math.random(minBullets, maxBullets) setElementData(avialColq, ammoData, ammoQuantity) end end end end, 23100, 1) end
A sua função spawnAirdrop original tinha o objetivo de criar um airdrop com um único item escolhido aleatoriamente da lista lootItems. Para modificar essa função e para que o airdrop contenha de 1 a 4 itens adicionei um loop
for i = 1, math.random(1, 4) do
Isso cria um loop que escolhe um número aleatório entre 1 e 4, representado por math.random(1, 4), que determinará quantos itens serão adicionados ao airdrop.
Espero que tenha funcionado para você e que tenha entendido, no mais, fique a vontade para voltar com qualquer dúvida. Abraços!
Oi amigo, primeiramente agradeço imensamente pela sua atenção e ajuda, sou muito grato! Segundo, continua dando apenas 1 item mas por outro lado resolveu outro problema que estava acontecendo, de vir sempre o mesmo item todas as vezes. Agora está vindo 100% aleatório de acordo com as porcentagens! Pra ficar perfeito so dando mais de 1 item simultâneo agora
PS.: Adorei seus comentários !! Eu já tive servidores de outros games mas Lua é totalmente novo pra mim
-
Ola boa noite, gostaria de uma ajuda quanto a função abaixo, sempre que spawna o "airdrop" (dayz) ele contém sempre apenas um dos itens abaixo... tem como fazer conter de 1 a 4 itens da lista?
lootItems = { {"M4A3 CCO",70}, {"M16A2",70}, {"Steyr AUG",70}, {"AKS (gold)",70}, {"AKM",70}, {"AK-74",70}, {"AK-107",70}, {"G36C (camo)",70}, {"FN FAL",70}, {"LK-05 SD",70}, {"FN SCAR-L",70}, {"DMR",70}, {"M107",60}, {"M40A3",60}, {"AS50",60}, {"KSVK",60}, {"M249 SAW",40}, {"PKM",30}, {"MG36",30}, {"M240",30}, {"Mk 48 Mod 0",30}, {"Medic Kit",85}, {"Painkiller",50}, {"Morphine",50}, {"Bandage",50}, {"Toolbox",80}, {"Scrap Metal",34}, {"Steel Sheet",100}, {"Engine",43}, {"Tire",43}, {"Tank Parts",43}, {"MP5SD6",50}, {"Revolver",50}, {"Coyote Camo Backpack",60}, {"Drybag Backpack",80}, {"Alice Backpack",70}, {"Czech Backpack",60}, {"Motorbike Helmet 1",50}, {"Police Vest",50}, {"UK Vest Black",50}, {"Gas Mask 2",50}, }
function spawnAirdrop(player) if isElement(player) and not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then return end if isElement(productq) then destroyElement(productq) end if isElement(avialColq) then destroyElement(avialColq) end if isElement(blipq) then destroyElement(blipq) end if isElement(variavel) then destroyElement(variavel) end if isTimer(respawnAirdropTimer)then killTimer(respawnAirdropTimer) end respawnAirdropTimer = setTimer(spawnAirdrop,120000,1) local item_id = math.random(1,#spawnLocations) xq,yq,zq = spawnLocations[item_id][1],spawnLocations[item_id][2],spawnLocations[item_id][3]+0.35 xpsq,ypsq,zpsq = xq,yq,zq+7,3 xpvq,ypvq,zpvq = xq-48,yq-16,zq+37 xsbq,ysbq,zsbq = xq-48,yq-16,zq+41 xssq,yssq,zssq = xq-528,yq+2,zq+141 xsdq,ysdq,zsdq = xq+528,yq+2,zq+141 blipq = createBlip(xq,yq,zq,5) aviaNavaq = createObject(1683,xssq,yssq,zssq,0,0,0) moveObject(aviaNavaq,8000,xsbq,ysbq,zsbq) setTimer(function() parasProdq = createObject(2903,xpvq,ypvq,zpvq,0,0,0) moveObject(aviaNavaq,8000,xsdq,ysdq,zsdq) moveObject(parasProdq,15000,xpsq,ypsq,zpsq) triggerClientEvent("playAirdropSound",getRootElement()) outputChatBox("#ff0000[AIRDROP] #ffffffUM PACOTE COM LOOT MILITAR FOI LANÇADO AO CHÃO. SEU MAPA FOI MARCADO COM O LOCAL.", getRootElement(), 255,255,255,true) end,8000,1) setTimer(destroyElement,16100,1,aviaNavaq) setTimer(function() destroyElement(parasProdq) destroyElement(variavel) productq = createObject(2669,xq,yq,zq,0,0,0) variavel = createObject(2060, xq, yq, zq +1.3, 1, 0, 0 ) setElementFrozen(productq,true) avialColq = createColSphere(xq,yq,zq,2) attachElements(avialColq,productq,0,0,0) setElementData(avialColq,"parent",object) setElementData(avialColq,"hospitalbox",true) setElementData(avialColq,"MAX_Slots",5000) for i,item in pairs(lootItems)do local value = math.percentChance(item[2],1) if value >= 1 then setElementData(avialColq,item[1],value) local ammoData,weapID = getWeaponAmmoType(item[1],true) if ammoData then local minBullets,maxBullets = math.floor(getAmmoPlus(ammoData)/3),getAmmoPlus(ammoData)*2 local ammoQuantity = math.random(minBullets,maxBullets) setElementData(avialColq,ammoData,ammoQuantity) end end end end,23100,1) end
-
É possível desativar jogador x jogador no servidor? Gostaria de montar um server PvE e pra isso quero evitar totalmente mortes entre jogadores de qualquer forma (inclusive atropelamentos)
Obrigado!!
-
Certinho, Muito obrigado!!
-
52 minutes ago, Lord Henry said:
Sobre sua primeira pergunta, coloque isso em qualquer script client.lua para fazer com que a mensagem fique oculta por padrão. No meu caso, coloquei num resource de radar modificado.
bindKey("F11", "down", "radar_help") -- Oculta a mensagem de Help ao abrir o mapa por padrão. Se quiser ver a mensagem, aperte num_1 com o mapa aberto.
Basicamente você binda o comando de mostrar/ocultar essa mensagem ao abrir o mapa. Então a mensagem por padrão vai sumir ao abrir o mapa e aparecer ao fechar o mapa. Você ainda pode trocar a ordem apertando a tecla num_1 para mostrar a mensagem novamente, pois este comando funciona em alternância.
Obs: Ao sair do servidor, a mensagem volta a ficar oculta por padrão.
Sobre sua segunda pergunta relacionada aos blips.
Qualquer shader simples que substitui texturas consegue fazer isso.
replace.fx
// Variable to fetch the texture from the script texture gTexture; // Very simple technique technique simple { pass P0 { // Set the texture Texture[0] = gTexture; } }
client.lua
local textures = { "radar_centre", "radar_north", "radar_light", "radar_runway", "radar_waypoint", } -- Nomes de alguns blips. addEventHandler ("onClientResourceStart", resourceRoot, function() for i, tex in ipairs(textures) do -- Para cada nome da lista de nomes de blips, faça: local shad = dxCreateShader ("replace.fx") -- Cria um shader a partir deste arquivo. local newTex = dxCreateTexture (tex.."0.png") -- As novas texturas possuem o mesmo nome da textura original seguido por 0. dxSetShaderValue (shad, "gTexture", newTex) -- Utiliza a nova textura no shader. engineApplyShaderToWorldTexture (shad, tex) -- Aplica o shader na textura original, substituindo pela nova. end end)
Sobre o shader, vou testar ainda mas do mapa ficou perfeito!! Muito obrigado!
Só mais uma coisa, é possível reduzir um pouco o tamanho do mapa com os blips acompanhando a escala?
-
I'm new to coding and I tried some ways with onPlayerQuit but no success.
This is the code that is probably wrong since it didnt work... Problem is this gui stays open when you disconnect and rejoin the server.
function quitPlayer () guiSetVisible ( GUIEditor.window[1] , false) showCursor ( false ) end addEventHandler ( "onPlayerQuit", root, quitPlayer )
This is the gui i want to close on quit
GUIEditor.window[1] = guiCreateWindow(98, 46, 654, 450, "Weapon shop", false)
-
17 minutes ago, Lord Henry said:
Conforme está escrito ali, ele está dizendo que apertar a tecla num_1 (1 do teclado numérico) vai ocultar essa mensagem. No entanto, ele só vai lembrar disso durante sua sessão atual de jogo, ou seja, se vc sair e entrar novamente no servidor, a mensagem estará visível novamente.
Se o que vc quer fazer é que essa mensagem já esteja oculta por padrão ao entrar no servidor, dai sim você tem que programar umas coisas.
Sim, com shaders. Um shader básico de substituição de textura faz isso.
Sim perdoe-me não fui claro. Gostaria de ocultar por padrão ou de preferência traduzir esta mensagem. Pois meu MTA está em português e a mensagem continua em inglês...
fetchRemote taking awhile to fetch
in Scripting
Posted · Edited by sirrjohn
oh that sounds like a good idea, a resource starter script!! Tyvm for the heads up i wasn't thinking about that.
I can find out how to do it myself, to not bother you guys much more! Was a nice tip. Ty!