Gabriel1375 Posted November 21, 2017 Share Posted November 21, 2017 Hello guys, what's up ? I've made myself an blip event script, that attach a blip on the admin on the map, and the user who kills it get a random item. The most complicated part of the script is working fine, but i have a problem... The problem is: When the admin kills himself, the event doesn't end, if i die 10x, i'll have the function still running, so everytime i die it gives the message and the item... The script: (i've already commented all the lines to get easier to understand...) --function blip has paremeter: theplayer function blip (thePlayer) --variable accountname receive the value of the getaccountname of the player, to see the player login accountname = getAccountName(getPlayerAccount(thePlayer)) --if the player who triggered the blip function is a supermoderator or an admin then if isObjectInACLGroup("user." .. accountname, aclGetGroup("SuperModerator")) or isObjectInACLGroup("user." .. accountname, aclGetGroup("Admin")) then --output the message "special event - kill the adm identified as a $ on the map, the winner will get random items" outputChatBox ('#00BFFF==============================================================',getRootElement(),255,255,255,true) outputChatBox ('#00BFFF【 EVENTO ESPECIAL! 】#FFFFFF Mate o ADM identificado com o #098700cifrão ($) verde no mapa',getRootElement(),255,255,255,true) outputChatBox ('#FFFFFFO vencedor ganhará itens aleátorios!',getRootElement(),255,255,255,true) outputChatBox ('#00BFFF==============================================================',getRootElement(),255,255,255,true) --attach a "$" blip to the admin or supermod who started the event blip = createBlipAttachedTo (thePlayer,52,10) --set the admin data blood to 100 setElementData(thePlayer, "blood",100) --set the admin data blip event to true setElementData(thePlayer, "eventoblip",true) --set the max slots of the admin backpack to 350 setElementData(thePlayer, "MAX_Slots",350) end end --add the command /eventoblip that triggers the function blip addCommandHandler("eventoblip", blip) --table that determine what items the player will be given local itens = { {"Banana"}, {"Kiwi"}, {"Pizza"} } --function that calculates the size of the table itens above function tamanho( tabela ) local count = 0 for a in pairs( tabela ) do count = count + 1 end return count end -- function endevent has parameters: ammo, attacker, weapon, bodypart function fimdoevento(ammo, attacker, weapon, bodypart) -- if there is a attacker, and the element that killed him was a player, and the killed player has the data blip event then if attacker and getElementType ( attacker ) == "player" and getElementData(source,"eventoblip") == true then --declaring a local variable item that uses the tablecount system to pickup a random item of the table items local item = itens[math.random(tamanho(itens))][1] --declaring a local variable quantity, that's equal to 1x local quantidade = 1 --destroy the blip on the map after event is over destroyElement(blip) --remove the data blip event from staff setElementData(source, "eventoblip",false) --give to the attacker and the admin(test purposes) the random item, and quantity setElementData(attacker, item , quantidade) setElementData(source, item, quantidade) --output message "congratulations attackername killed the staff and wins X quantity of the X item" outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) outputChatBox ("#00a5ff Parabéns [#FF0000" ..getPlayerName(attacker).."#00a5ff] matou o Staff e ganhou [#ff0000 "..quantidade.."x "..item.."#00a5ff]!",getRootElement(),255,255,255,true) outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) -- else if there is a attacker, and the attacker killed with a vehicle, and the killed player has the data blip event then elseif attacker and getElementType ( attacker ) == "vehicle" and getElementData(source,"eventoblip") == true then --destroy the blip on the map after event is over destroyElement(blip) --remove the data blip event from staff setElementData(source, "eventoblip",false) --give to the attacker and the admin(test purposes) the random item, and quantity setElementData(attacker, item , quantidade) setElementData(source, item, quantidade) --output message "congratulations attackername killed the staff and wins X quantity of the X item" outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) outputChatBox ("#00a5ff Parabéns [#FF0000" ..getPlayerName(attacker).."#00a5ff] atropelou o Staff e ganhou [#ff0000 "..quantidade.."x "..item.."#00a5ff]!",getRootElement(),255,255,255,true) outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) -- if none of this conditions is true then the admin accidentally killed himself from falling or other causes else --output message "the staff adminname killed himself, the event is still running" outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) outputChatBox ('#00a5ffO Staff ' .. getPlayerName(source) .. ' se matou, o evento continua.' ,getRootElement(),255,255,255,true) outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) end end --add an event handler of type onplayerwasted, that triggers the fimdoevento (translating: endevent) function addEventHandler("onPlayerWasted", getRootElement(), fimdoevento) Thank you guys, and please if anyone is thinking to use the script, please have my credits in: Gabriel Bigardi Link to comment
msyyn Posted November 21, 2017 Share Posted November 21, 2017 (edited) if attacker ~= source then ... You could try this to prevent it ending when you kill yourself. Also, why are you counting length of table like this? You can do simply this: local item = itens[math.random(#itens)][1] The code has few other issues as well, check your scopes Edited November 21, 2017 by msyyn Link to comment
Gabriel1375 Posted November 22, 2017 Author Share Posted November 22, 2017 Hello, thanks for helping... I ve done it but now i cant even get the suicide message Idk what more can i do Link to comment
msyyn Posted November 22, 2017 Share Posted November 22, 2017 /debugscript 3 ingame. What does it say? Link to comment
Gabriel1375 Posted November 25, 2017 Author Share Posted November 25, 2017 Hello, Sorry for the late answers, i've been a little busy... So, i've modified my script and now it works fine to identify when i killed myself or when anyone killed me, but... It doesn't identify the "attacker" value... It doesn't give the message that the event is over because someone killed the staff, and doesn't give items to the attacker... Here is the new script: --function blip has paremeter: theplayer function blip (thePlayer) --variable accountname receive the value of the getaccountname of the player, to see the player login accountname = getAccountName(getPlayerAccount(thePlayer)) --if the player who triggered the blip function is a supermoderator or an admin then if isObjectInACLGroup("user." .. accountname, aclGetGroup("SuperModerator")) or isObjectInACLGroup("user." .. accountname, aclGetGroup("Admin")) then --output the message "special event - kill the adm identified as a $ on the map, the winner will get random items" outputChatBox ('#00BFFF==============================================================',getRootElement(),255,255,255,true) outputChatBox ('#00BFFF【 EVENTO ESPECIAL! 】#FFFFFF Mate o ADM identificado com o #098700cifrão ($) verde no mapa',getRootElement(),255,255,255,true) outputChatBox ('#FFFFFFO vencedor ganhará itens aleátorios!',getRootElement(),255,255,255,true) outputChatBox ('#00BFFF==============================================================',getRootElement(),255,255,255,true) --attach a "$" blip to the admin or supermod who started the event blip = createBlipAttachedTo (thePlayer,52,10) --set the admin data blood to 100 setElementData(thePlayer, "blood",100) --set the admin data blip event to true setElementData(thePlayer, "eventoblip",true) --set the max slots of the admin backpack to 350 setElementData(thePlayer, "MAX_Slots",350) end end --add the command /eventoblip that triggers the function blip addCommandHandler("eventoblip", blip) --table that determine what items the player will be given local itens = { {"Banana"}, {"Kiwi"}, {"Pizza"} } --function that calculates the size of the table itens above function tamanho( tabela ) local count = 0 for a in pairs( tabela ) do count = count + 1 end return count end -- function endevent has parameters: ammo, attacker, weapon, bodypart function fimdoevento(ammo, attacker, weapon, bodypart) --varaible to stop the event data of the player who started the event local getData = getElementData ( source, "eventoblip" ) --when i die, if i'm the one who started the event, and the event is still running... if getData then -- there is a attacker if attacker then --variable item local item = itens[math.random(tamanho(itens))][1] --variable quantity local quantidade = 1 --destroy the blip attached destroyElement(blip) --remove the event data from staff setElementData(source, "eventoblip",false) --give the attacker items setElementData(attacker, item , quantidade) --give the source items (this one is working in else) setElementData(source, item, quantidade) --win message outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) outputChatBox ('#00a5ff ANYONE WINS THE EVENT MESSAGE',getRootElement(),255,255,255,true) outputChatBox ("#00a5ff Parabéns [#FF0000" .. getPlayerName(attacker) .. "#00a5ff] matou o Staff e ganhou [#ff0000 "..quantidade.."x "..item.."#00a5ff]!",getRootElement(),255,255,255,true) outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) --else if there is not a attacker so i killed myself else --destroy blip attached destroyElement(blip) --remove event data from staff setElementData(source, "eventoblip",false) --the staff killed himself, the event is over outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) outputChatBox ('#00a5ff O Staff #FF0000' .. getPlayerName(source) .. ' #00a5ff se matou, o evento irá reiniciar',getRootElement(),255,255,255,true) outputChatBox ('#00a5ff==============================================================',getRootElement(),255,255,255,true) end end end --add an event handler of type onplayerwasted, that triggers the fimdoevento (translating: endevent) function addEventHandler("onPlayerWasted", getRootElement(), fimdoevento) --function to force the end of event if i give the command /finalizareventoblip (working perfectly) function finalizarevento(thePlayer) --local variable data local pegaData = getElementData ( thePlayer, "eventoblip" ) --identify account name accountname = getAccountName(getPlayerAccount(thePlayer)) -- if is a admin or supermod then if isObjectInACLGroup("user." .. accountname, aclGetGroup("SuperModerator")) or isObjectInACLGroup("user." .. accountname, aclGetGroup("Admin")) then --if the event is running then if pegaData then --destroy blip destroyElement(blip) --remove data setElementData(thePlayer, "eventoblip",false) removeElementData(thePlayer,"eventoblip") --message admin ended the event outputChatBox ('#00BFFF==============================================================',getRootElement(),255,255,255,true) outputChatBox ('#FF0000【 ATENÇÃO! 】#FFFFFF O Staff finalizou o evento.',getRootElement(),255,255,255,true) outputChatBox ('#FFFFFFO ele explicará o motivo em breve!',getRootElement(),255,255,255,true) outputChatBox ('#00BFFF==============================================================',getRootElement(),255,255,255,true) --blood back to normal setElementData(thePlayer, "blood",12000) --slots back to normal setElementData(thePlayer, "MAX_Slots",350) else --else if the event is not running give message event is not running outputChatBox ('#FFFFFFO Evento não está acontecendo !!!',thePlayer,255,255,255,true) end end end addCommandHandler("finalizareventoblip", finalizarevento) Also, ty again !! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now