lolek123 Posted August 22, 2012 Share Posted August 22, 2012 How can I make server check my objects and make marker on object model ID 2916, any help? Please. Link to comment
AMARANT Posted August 22, 2012 Share Posted August 22, 2012 What do you mean? Checking an object that hits marker or what? Link to comment
lolek123 Posted August 22, 2012 Author Share Posted August 22, 2012 No. I want my server to do an auto check after the server starts.. And whenever it finds an object with Model ID 2916 it will create a marker on it. Link to comment
AMARANT Posted August 22, 2012 Share Posted August 22, 2012 This will work after your resource starts. Server-side: function CheckMyObject(res) if res==getThisResource() then for _,object in ipairs(getElementsByType("object")) do if getElementModel(object)==2916 then local x,y,z=getElementPosition(object) local int=getElementInterior(object) local dim=getElementDimension(object) myMarker=createMarker(x,y,z,"cylinder",2.0,255,0,0,125) setElementInterior(myMarker,int) setElementDimension(myMarker,dim) end end end end addEventHandler("onResourceStart",getRootElement(),CheckMyObject) Link to comment
Perfect Posted August 22, 2012 Share Posted August 22, 2012 This will work after your resource starts.Server-side: function CheckMyObject(res) if res==getThisResource() then for _,object in ipairs(getElementsByType("object")) do if getElementModel(object)==2916 then local x,y,z=getElementPosition(object) local int=getElementInterior(object) local dim=getElementDimension(object) myMarker=createMarker(x,y,z,"cylinder",2.0,255,0,0,125) setElementInterior(myMarker,int) setElementDimension(myMarker,dim) end end end end addEventHandler("onResourceStart",getRootElement(),CheckMyObject) Hi, how you know how many "end" will add ? Link to comment
AMARANT Posted August 22, 2012 Share Posted August 22, 2012 Because every "if", loop or function must be closed with "end" operator. Install Notepad++ it can help you to figure this out. Link to comment
Perfect Posted August 22, 2012 Share Posted August 22, 2012 Because every "if", loop or function must be closed with "end" operator. Install Notepad++ it can help you to figure this out. Yeah, i have notepad. what is loop ? and there is 1 function, 2 if's and 4 end's ??? Link to comment
AMARANT Posted August 22, 2012 Share Posted August 22, 2012 The 4th "end" is loop actually. Link to comment
Perfect Posted August 22, 2012 Share Posted August 22, 2012 The 4th "end" is loop actually. but what is loop ? can you pls give me 2 or 3 examples if that is not single function ? Link to comment
lolek123 Posted August 22, 2012 Author Share Posted August 22, 2012 "for _,object in ipairs(getElementsByType("object")) do" could you kinda explain and simplify this part for me? I dont really understand the in ipairs. Link to comment
Perfect Posted August 22, 2012 Share Posted August 22, 2012 "for _,object in ipairs(getElementsByType("object")) do"could you kinda explain and simplify this part for me? I dont really understand the in ipairs. me too!!! can we put anything instead _ and object ? everything everyword clrealy Link to comment
AMARANT Posted August 22, 2012 Share Posted August 22, 2012 I'm not good at explaining the lua basics. For that you can find more with google or tutorials on MTA wiki. And I made an example above for lolek123. But here is one more: function outputForPerfect(player) for i,player in ipairs(getElementsByType("player") do -- Here's looping through all player elements in order to find what we want. Loops are usually used to check tables or to shorten a code so you can write several lines of your script instead of writing hundred. if getPlayerName(player)=="Perfect" then -- We wanted to find a player with nickname "Perfect". Here we are outputChatBox("Bla-bla-bla...",player,0,255,0) -- And finally we output a message to him. end end end addCommandHandler ( "loop", outputForPerfect ) 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