Tony Brand Posted October 14, 2018 Share Posted October 14, 2018 Hi everyone,i am new to lua and i don't know exactly where i must put ends in code! i think i must put end under of every if & for when commands happens! so i made a code like this: function eventDeath(killer) local killed = getPlayerName (source) if ( killer ) then local killerPerson = getPlayerName (killer) if ( getElementData(killer,"Prison") == true ) or ( getElementData(source,"Prison") == true ) then for index,player in ipairs (getElementsByType("player")) do if ( getElementData(player,"Police") == true ) or ( getElementData(player,"AdminRank") >= 5 ) then outputChatBox(""..killerPerson.." Killed "..killed.." while he/she was in jail! ",player,255,255,255,true) end end end end addEventHandler ( "onPlayerWasted", getRootElement(), eventDeath ) can you help me to fix it and also tell me where i should exactly put end in my code? Link to comment
Moderators IIYAMA Posted October 14, 2018 Moderators Share Posted October 14, 2018 (edited) ------------------ ------ function function functionName () end -- < end ------------------ ------ if statement if true then end -- < end ------------------ ------ if statement with elseif and else if true then elseif true then else end -- < end ------------------ ------ do-end block do end -- < end ------------------ ------ loops for i=1, 10 do end -- < end -- for i, v in ipairs({1, 2, 3}) do end -- < end -- while true do end -- < end ------ Cheat sheet. More info: Starting here: https://www.lua.org/pil/4.3.html https://www.lua.org/pil/4.3.2.html https://www.lua.org/pil/4.3.1.html https://www.lua.org/pil/4.3.4.html https://www.lua.org/pil/4.3.5.html https://www.lua.org/pil/5.html Edited October 14, 2018 by IIYAMA 1 Link to comment
savour Posted October 20, 2018 Share Posted October 20, 2018 it seems like you've missed one "end" every if, for, while and there sub-statements must be closed with end, just like IIYAMA said, Here is the code with the missing end, you just compare it and you will know which one you've missed. function eventDeath(killer) local killed = getPlayerName (source) if ( killer ) then local killerPerson = getPlayerName (killer) if ( getElementData(killer,"Prison") == true ) or ( getElementData(source,"Prison") == true ) then for index,player in ipairs (getElementsByType("player")) do if ( getElementData(player,"Police") == true ) or ( getElementData(player,"AdminRank") >= 5 ) then outputChatBox(""..killerPerson.." Killed "..killed.." while he/she was in jail! ",player,255,255,255,true) end end end end end addEventHandler ( "onPlayerWasted", getRootElement(), eventDeath ) 1 Link to comment
Tony Brand Posted October 21, 2018 Author Share Posted October 21, 2018 thank you guys, now i learned where to use end in script 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