Bilal135 Posted December 6, 2018 Share Posted December 6, 2018 (edited) I made three tables, local insults = {":O you", ":O off", "cry", "suck my :O", "pussy", ":O", "idiot", "whore", "dickhead", "mother:Oer", "your mom sucks", "bitch", ":Oer", "virgin", "peace of :~", "piece of :~", ":~ of peace", ":~ of piece", "retard", "gay :O", ":O", "gay :O", "gay", "dicksucker", "coward", "angry german kid", "kid", "agk", "asshole"} local answers = {"oki", "stfu", "kid", "tenks", "lol", "kiddy", "wow", "pff", "lmao", "noob", "omg"} local random = {"if i die tell my mom i love she", "omg my heart", "i miss you"} and stored some string values (insults) in it. Then, looped through them to find if a player said one of those in chat. It is supposed to work like this, if he said one of those in chat, then it would trigger functionA, but if he did not, that would trigger functionB. addEventHandler("onPlayerChat", root, function(message, messageType) if not messageType == 0 then return end if not isElementWithinColShape(source, colArea) then return end if not getElementData(tarek, "alive") == true then return end if getElementData(tarek, "rage") == true then return end for _, sMessage in pairs(insults) do if message == sMessage then functionA() else functionB() return end end end) But in this case, it triggered both functionA and function B. What each of these functions do, functionA: Checks if the player insulted the ped a certain number of times, and outputs ped's reaction according to that. (tarek = ped) If the player has not yet insulted a set number of times (end_time_value) then, it outputs something else. functionB: If the player did not say any value from the 'insults' table, then a random value from 'random' table will be outputed. function functionA() setTimer(function() local end_limit_value = 5 if getElementData(tarek, "limit_value") == tonumber(end_limit_value) then setElementData(tarek, "rage", true) setPedAnimation(tarek, "graveyard", "mrnf_loop") outputChatBox("#FFBC74Tarek: #FFFFFFgtfo kiddy", source, 255, 255, 255, true) playAgkRageSound() setTimer(function() outputChatBox("#FFBC74Tarek: #FFFFFFgod get a pussy you virgin :~ of peace", source, 255, 255, 255, true) end, 3000, 1) setTimer(function() outputChatBox("#FFBC74Tarek: #FFFFFFmother:Oer you mom dont want you", source, 255, 255, 255, true) setTimer(function() local x, y, z = getElementPosition(tarek) createExplosion(x, y, z, 6) createExplosion(x, y, z, 6) createExplosion(x, y, z, 6) killPed(tarek) setElementData(tarek, "alive", false) outputChatBox("Angry German Kid has exploded and killed you!", source, 255, 100, 100) setTimer(function() destroyElement(tarek) reviveTarek() setElementData(tarek, "rage", false) end, 20000, 1) end, 6000, 1) end, 2000, 1) return end outputChatBox("#FFBC74Tarek: #FFFFFF"..table.random(answers).."", source, 255, 255, 255, true) index = index + (index_value and 1 or -1) setElementData(tarek, "limit_value", tonumber(index)) end, 3000, 1) end function functionB() outputChatBox("#FFBC74Tarek: #FFFFFF"..table.random(random).."", source, 255, 255, 255, true) end Complete code; https://pastebin.com/hHQs3qZR The problem is with the loop, it does not output what is required, but outputs both of the functions at the same time. (Btw, this script is an *attempt* to create a clone of my friend. Pretty lame, but that's what it is) Any help regarding this would be really appreciated. Edited December 6, 2018 by Bilal135 Link to comment
Moderators IIYAMA Posted December 6, 2018 Moderators Share Posted December 6, 2018 (edited) local didInsult = false -- State insult or not. for _, sMessage in pairs(insults) do if message == sMessage then didInsult = true -- ":O yea" Set insult state to true! break -- stop looping! end end (didInsult and functionA or functionB)() -- execute A or B -- How does this work? -- ??? Which function to use: didInsult and functionA or functionB -- didInsult == true = functionA -- didInsult == false = functionB -- (...)() < execute it! @Bilal135 Edited December 6, 2018 by IIYAMA 1 Link to comment
Bilal135 Posted December 6, 2018 Author Share Posted December 6, 2018 Thank you once again @IIYAMA. Was really easy to understand this time. Solved. 1 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