WallMart Posted October 16, 2013 Posted October 16, 2013 Hi guys. Back after a long time of in-activity on MTA, i decided i wanted to learn to script in Lua. However the tutorials i found are a bit outdated, since the scripts ( i literally copied them, just to try it out ) don't work anymore. If anyone could link me to any tutorial on lua that works with the current MTA, that would be nice. Greets, WallMart EDIT: i figured i should post the code too, maybe i did something horribly wrong. local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 10 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("Welcome to My Server", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler)
slotman Posted October 16, 2013 Posted October 16, 2013 function spawn(player) if getElementType(player)=="player" then local desiredSkin = getElementData(player, "skinID") if desiredSkin then skinID=desiredSkin else skinID= math.random(9,288) end spawnX = math.random(-691, -671) spawnY = math.random(962, 971) spawnZ = 20 repeat until spawnPlayer ( player, spawnX, spawnY, spawnZ, 180, skinID ) fadeCamera(player, true) setCameraTarget(player, player) end end addEventHandler("onPlayerJoin", root, function() setTimer(function(src) spawn(src) end, 5000, 1, source) end ) addEventHandler("onPlayerWasted", root, function() if getElementType(source)=="player" then local tmpID = getPedSkin(source) --outputChatBox(tmpID.."f") setElementData(source,"skinID",tmpID) setTimer(spawn, 5000, 1, source) end end )
pa3ck Posted October 16, 2013 Posted October 16, 2013 This is a server side code, do you have that in meta.xml? Like : <meta> <script src="s_name.lua" type="server"/> </meta>
WallMart Posted October 16, 2013 Author Posted October 16, 2013 This is a server side code, do you have that in meta.xml? Like : <meta> <script src="s_name.lua" type="server"/> </meta> it still says that it contains illegal characters. but as i said, i took this literally from an official tutorial of the mta wiki and it stated that it should work with those lines of code. so if you an updated tutorial i would be grateful
BieHDC Posted October 16, 2013 Posted October 16, 2013 what use has the line 12 and 13? ^^ spawnZ = 20 repeat --this until --n dat spawnPlayer ( player, spawnX, spawnY, spawnZ, 180, skinID ) ^^
WallMart Posted October 16, 2013 Author Posted October 16, 2013 okay guys, it works now as it should! but still i'd like to see some tutorials. so if anyone knows about them, send em over!
Spajk Posted October 16, 2013 Posted October 16, 2013 function spawn(player) if getElementType(player)=="player" then local desiredSkin = getElementData(player, "skinID") if desiredSkin then skinID=desiredSkin else skinID= math.random(9,288) end spawnX = math.random(-691, -671) spawnY = math.random(962, 971) spawnZ = 20 repeat until spawnPlayer ( player, spawnX, spawnY, spawnZ, 180, skinID ) fadeCamera(player, true) setCameraTarget(player, player) end end addEventHandler("onPlayerJoin", root, function() setTimer(function(src) spawn(src) end, 5000, 1, source) end ) addEventHandler("onPlayerWasted", root, function() if getElementType(source)=="player" then local tmpID = getPedSkin(source) --outputChatBox(tmpID.."f") setElementData(source,"skinID",tmpID) setTimer(spawn, 5000, 1, source) end end ) Use of element data here is quite bad, passing the skin id as function argument thru timer would be much better.
WallMart Posted October 17, 2013 Author Posted October 17, 2013 also, while i'm at it anyway. how do i call current vehicle? would that be currentVehicle or playerVehicle or something? sorry for the noobish questions but just started out
WallMart Posted October 17, 2013 Author Posted October 17, 2013 okay, can someone help me with this script? it's the first one i have written myself, obviously it doesnt work i wanted to make a script, that when players press the R key their car will be completely repaired. function playerPressedKey (r, press) local theVehicle = getPedOccupiedVehicle ( thePlayer ) if (press) then setElementHealth (theVehicle, getElementHealth(theVehicle) + 100) end end addEventHandler ("setElementHealth", root, getPedOccupiedVehicle) it's nice if anyone could fix the code, it would be even better with explanation ( and tell me if i really fucked up, i just want to learn )
csiguusz Posted October 17, 2013 Posted October 17, 2013 Your code doesn't make much sense . Try this, on client side. And if you need further explaination then ask just ask for it! function repairCar () local vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then -- check if the local player is in a vehicle fixVehicle ( vehicle ) -- fix it end end bindKey ( "r", "down", repairCar ) -- bind a key to a function
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