Jump to content

Problem with where to put end in code


Tony Brand

Recommended Posts

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
------------------
------ 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 by IIYAMA
  • Thanks 1
Link to comment

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 )	

 

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...