Jump to content

kieran

Members
  • Posts

    367
  • Joined

  • Last visited

Everything posted by kieran

  1. Thanks so much @IIYAMA, was driving me crazy, like how you even went to the efforts of checking number of accounts! The sole purpose of this part is if I ever upload it to the community, so servers using a GUI system can switch to this and players (hopefully) won't lose any data.
  2. I guess something like this would work.... function someFuntion() local theData = getElementData(source, "data_name") --First we get the data if theData ~= false then --If the data is not equal (~=) to false outputChatBox("data = "..theData, source) --We output a message to the source, adding the data value to the string else outputChatBox("Data was not found.", source) --Otherwise we tell the player data was not found. end end addEventHandler("onPlayerLogin", getRootElement(), someFunction) --When player logs in, function is triggered You get the data first, then you check it in the if, if it's there, output it to the chat, if not, say it's not there, keep in mind, you might need to use tostring when adding the data to chat message, so it might look like... outputChatBox("data = "..tostring(theData), source) where the data is in the brackets... Hope this helped you.
  3. I know that if you set handling on hydra it MUST be on the ground to have an effect, so I think what actually happens is it only sets handling if the vehicle has something to move on, so wheels must be on ground.... You could experiment with setGameSpeed, but I have no clue how you would set a helicopters speed.... Hope it helps.
  4. Right, first when you find something on the wiki, read the parameters!!! Parameters are very useful, in your case, with the onClientKey handler the parameters are (button) and (pressed) so it returns 3 things in total... "button" is the button pressed, "pressed" is true if the key is down, FALSE if the key is up So instead of doing this: function PressedKey(button, press) if (press) and button=="1" then Try this: function PressedKey(button, press) if (press == true) and button=="1" then Hope this helps.... In theory, if checks if a value is true, so if (press) should only happen when your key is pressed, if this doesn't work, look into using bindKey instead and bind each different key to set the weapon slot.
  5. When you return you basically end it, but you can use return to return values to a function, if it doesn't work... You just think of it like function nesting... setTimer = (function() Contents of function, end, time, times to repeat, other values) Or to set a timer for a function... setTimer = (function name, Contents of function, end, time, times to repeat, other values )
  6. As long as it works, sometimes things are overthought and that's how you end up on forums... Happens to me way too much, but I learned if I start as simple as possible, I can just add stuff later.
  7. Oh, then just set a global boolean (something that's true or false) before your functions and check it.... --add some variables/booleans, to check what door is open door1open = false door2open = false function moveDoor(hitElement, dimension) local vehicle = getPedOccupiedVehicle(hitElement) local money = getPlayerMoney(hitElement) if ( money >= 200 ) and getElementHealth(vehicle) < 1000 then if door1open == false then --if door 1 is not open we open it and set it to true moveObject(door1, moveTime, 2072.5, -1831.4200244141, 16.5, 0, -90, 0) door1open = true triggerClientEvent("doorSound", resourceRoot) else --Move the door back here end if door1open == true and door2open == false then --If door 1 is open and door 2 is not (player will need to enter marker again) --Code to open second door else --code to close it end end end addEventHandler("onMarkerHit", marker1, moveDoor) If you mean open door1 then open door2 after, why don't you just move them in the same if checking if they are closed (if doorsOpen == false) and set your timer on the second door to the "moveTime" ... This would open your door after the first door has opened...
  8. You're not being clear in the result you want, do you want the doors to open together? If so why don't you just move both doors in the same script with moveObject? Also line numbers and some debugscript 3 outputs would help, so I know what problems you're having if there is any... I'm a guy not a mind reader.
  9. https://wiki.multitheftauto.com/wiki/BindKey https://wiki.multitheftauto.com/wiki/GetPedWeaponSlot https://wiki.multitheftauto.com/wiki/SetPedWeaponSlot This will eliminate the need for the client side file altogether, use bindKey instead and bind each key to set the players weapon slot, getPedWeaponSlot is just there too because it might be useful, depends what errors happen, I never used keys for weapons before.... You can also use all 3 of those client side, eliminating the need for server file and freeing up space on your server/host, but I do not know if that changes only for local player or for all players.
  10. This topic should be on Resources forum, not here, as it is not lua related! But look it up on YouTube, look up keywords on forum, there's tutorials... You can use any 3D modelling software, the paid ones usually have more, and better stuff, more choices and control... But they are paid, my best answer (as I don't do 3d modelling but plan to try soon) is sketchup or 3ds max, it's not the program.... It's a question of whether or not the guy using it has researched it, look it up on YouTube, you need creativity to be a 3d modeller/coder, without that, you basically hit a dead end before you've started....
  11. Check through it dude, the problem was obvious just use /debugscript 3, look at the line number, script, and go to that line.... I forgot I changed vehicle to player on your vehicle exit command, the source of the function (the player) now is "player" and not "vehicle" since we are checking and destroying the vehicle.... So we want to replace line 25 with the following. vehicle = getElementData(player,"housing") Notice how I changed the first argument in getElementData from vehicle (which wouldn't work as that doesn't exist) to player (the player we are retrieving the data from) Hopefully it's sorted now, it's just a case of reading the errors it says, then thinking of all the possible things that are wrong where it says they are
  12. It is hard to put it in words when you have learned from just trying stuff, but I'll try explain why words are in ( ) in your function... See the "Parameters" on the wiki? These are the values that your event handlers return, so if it returns 2 parameters, then your first 2 words in the brackets will be the parameters (the stuff that the function is returning, such as the player, and the dimension) it's not the easiest to understand, but once you understand it you'll get it, I recommend you look up passing parameters and also using subroutines in lua, a subroutine/subprogram is basically a function that has 2 values, you can then call another function if you added a custom event with addEvent and addEventHandler, to pass these parameters to a custom event you use for example... function login() triggerClientEvent("myEvent", source, 20, 30, "hello") end addEventHandler("onPlayerLogin", getRootElement(), login) So the above is The event (attached to the function you want to pass stuff to) and the source, so if it was onPlayerLogin, you'd pass the player as the source element, anything after that is stuff to be passed to your function. So for client side code you can do something like the following using the server side code above. function passedOnLogin(num1,num2,text) outputChatBox(""..text,tonumber(num1), 0, tonumber(num2)) end addEvent("myEvent", true) addEventHandler("myEvent", root, passedOnLogin) triggerClientEvent("myEvent", source, 20, 30, "hello") This would output the message "hello" when the player logs in by passing it to the client, it would also change color of the text to 20, 0, 30 (rgb) Hope this helps
  13. allowedTeams = { ["Staff"] = true,} function spawner ( sourceplayer, commandname ) if allowedTeams[getTeamName(getPlayerTeam( sourceplayer))]then local x, y, z = getElementPosition ( sourceplayer ) local location = getZoneName ( x, y, z ) local car = createVehicle ( 445, x, y, z) setElementData( source, "housing", car ) --We set the players element data and pass the spawned car as a value, saving that car to the player until there data is set to false or they reconnect... warpPedIntoVehicle ( sourceplayer, car ) setVehiclePlateText( car, 'housing' ) setVehicleHandling(car , "maxVelocity", 40) setVehicleLocked ( car, true ) setVehicleDamageProof(car, true) local vehicleName = getVehicleName (car) outputDebugString ( "Housing Admin: [" ..getPlayerName(sourceplayer).."] Has Spawned "..vehicleName.." At {" ..location.."}.") --[[setTimer ( function() destroyElement (car) end, 25000, 1 )]] --Just commented it out as it's spawning here, NOT destroying else outputDebugString ( "Housing Admin: [" ..getPlayerName(sourceplayer).."] Has Tried the Housing command.") end end addCommandHandler ( "spawn", spawner ) function out ( player ) --He was returning the PLAYER... ALWAYS check the source element on the wiki. if player then vehicle = getElementData(vehicle,"housing") --This returns the vehicle if the player has the data. if isElement(vehicle) then --Next you should double check to make sure the element is there. destroyElement(vehicle) --If so you destroy it local setElementData( player, "housing", false ) --We also want to reset their data (set it false) if it's destroyed so they can spawn another one. else outputDebugString ( "Housing Admin: [" ..getPlayerName(player).."] Has left their vehicle and it was NOT destroyed.") --send a message end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), out ) My bad, copy and pasted getElementData as it was easy to keep the "housing" part, I am lazy haha.... Should work now. Basically I set setElementData as a variable, you shouldn't do that, you should only do it with getElementData
  14. Ah, I see, well none the less, the way you used vehicle is wrong, check it again and remember that the wiki is there for a reason it's very useful.
  15. Honestly, you're trying to complicate it, start small, work your way up.... Make the marker first, then pass the parameters that onMarkerHit returns in the brackets of function, the way you have done this is not right... But I don't know if you missed it or just didn't understand the returns on the wiki, so I will explain. Always read this stuff, don't just muck with code and hope it works, I learned this the hard way.... Parameters element hitElement, bool matchingDimension hitElement: The element that hit the marker matchingDimension: True if the element is in the same dimension as the marker he hit Source The source of this event is the marker that got hit by the element. So the parameters for example would be "function(hitElement, matchingDimension)" these return what the wiki say, but they are not a "special phrase", "special word" or "magic word", meaning you can call these 2 almost anything you want, a "magic word" would be source, this will return the source element, so "theMarker = source" in your first function would be the marker, as that is the source element, the dimension is true if the marker and element you are checking is in the same dimension, otherwise they are false, not there.... You'll want to check the element, in case it's a spawned ped... So I'm just going to re-type your code at a level I think you should start at, then I want you to go to wiki, and read a little about it so you know what's happening. isMoving = false --You need to put these out of your functions if you want to use them across multiple functions, later in lua scripting once you are at a more advanced level you can learn how to pass them back and forth and use subroutines moveTime = 5*1000 --Set the number to the time you want it to move, we MUST use miliseconds, so 5*1000 = 5 seconds --Add a marker with createMarker function moveDoor(hitElement, dimension) --We DON'T put the dimension as vehicle here as you are setting vehicle to the players vehicle below local vehicle = getPedOccupiedVehicle(hitElement) --We use hitElement as it is passed from event handler local money = getPlayerMoney(hitElement) if ( money >= 200 ) and getElementHealth(vehicle) < 1000 then if isMoving == true then return end if source == marker1 then moveObject(door1, moveTime, 2071.5, -1831.4000244141, 14.60000038147, 0, 90, 0) triggerClientEvent("doorSound", resourceRoot) --I'm assuming this works, I would not start sounds if you are just starting isMoving = true --We don't check move, moveObject doesn't wait, so best bet is to just set it true, set a timer to set it false --setTimer(moveDoor, moveTime, 1, true) --DO NOT DO THIS, YOU WILL LOOP INFINITELY AS YOU CALL THE FUNCTION INSIDE ITSELF. setTimer(door2, moveTime, 1, true)--This will trigger door2 after moveTime is over end end end addEventHandler("onMarkerHit", marker1, moveDoor) function door2(player, vehicle) --You can try figure out what's going wrong here yourself, look at the above and see what's been changed setTimer(function() if moveDoor = true then moveObject(door1, moveTime, 2072.5, -1831.4200244141, 16.5, 0, -90, 0) isMoving = false triggerClientEvent("doorSound", resourceRoot) end end, 6000, 1) end addEventHandler("onMarkerHit", marker1, door2) Use /debugscript 3 when testing scripts, carefully read the wiki, look at the examples, look at the parameters, look at what the full page says and not just a little of the page... I could do it all for you, but then you'd maybe learn nothing, so just try your hardest with what I've gave you and if you really are stuck, I'll try explain and help until you understand it.
  16. Hello, first time I have ever tried replacing textures and editing txd files, so I will sound like a complete noob... I wan to edit the elecfence_BAR.txd texture and remove the little yellow sign, so I simply opened the texture, deleted the yellow sign, and then I called the txd as a file in meta as you would if you were loading an image into a script... But it's still there. Can someone give me a quick run through of how you'd remove an image and load the txd in? By the way, here's my code. --electric fence addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource() ), function () txd = engineLoadTXD ( "elecfence_bar.txd" ) engineImportTXD ( txd, 987 ) end ) Is it because file name is the same as default? Thanks for any input or advice
  17. Personally I would use onClientPlayerVehicleExit and not onPlayerVehicleExit as you are using client side code, this would probably make it easier and more readable.... URBAN is along the right lines, but he was on phone, so it's expected he had some problems.... I will try restructure his code in a way the server can read it, and fix any problems I come across... Server side allowedTeams = { ["Staff"] = true,} function spawner ( sourceplayer, commandname ) if allowedTeams[getTeamName(getPlayerTeam( sourceplayer))]then local x, y, z = getElementPosition ( sourceplayer ) local location = getZoneName ( x, y, z ) local car = createVehicle ( 445, x, y, z) local theVeh = setElementData( sourceplayer, "housing", car ) --We set the players element data and pass the spawned car as a value, saving that car to the player until there data is set to false or they reconnect... warpPedIntoVehicle ( sourceplayer, car ) setVehiclePlateText( car, 'housing' ) setVehicleHandling(car , "maxVelocity", 40) setVehicleLocked ( car, true ) setVehicleDamageProof(car, true) local vehicleName = getVehicleName (car) outputDebugString ( "Housing Admin: [" ..getPlayerName(sourceplayer).."] Has Spawned "..vehicleName.." At {" ..location.."}.") --[[setTimer ( function() destroyElement (car) end, 25000, 1 )]] --Just commented it out as it's spawning here, NOT destroying else outputDebugString ( "Housing Admin: [" ..getPlayerName(sourceplayer).."] Has Tried the Housing command.") end end addCommandHandler ( "spawn", spawner ) function out ( player ) --He was returning the PLAYER... ALWAYS check the source element on the wiki. if player then vehicle = getElementData(vehicle,"housing") --This returns the vehicle if the player has the data. if isElement(vehicle) then --Next you should double check to make sure the element is there. destroyElement(vehicle) --If so you destroy it local setElementData( player, "housing", false ) --We also want to reset their data (set it false) if it's destroyed so they can spawn another one. else outputDebugString ( "Housing Admin: [" ..getPlayerName(player).."] Has left their vehicle and it was NOT destroyed.") --send a message end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), out ) Client side function colloff () local theVeh = getElementData( localPlayer, "housing" ) for index,vehicle in ipairs(getElementsByType("vehicle")) do --LOOP through all Vehicles, if you want it to be players change it to player setElementCollidableWith(vehicle, theVeh, false) -- Set the Collison off with the Other vehicles, (the vehicles, your vehicle, state) end end addEvent( "HousingCollisionless", true ) --renamed in case there was any conflicts, remember, handler are triggered across all scripts if they are true, not just the one they are in. addEventHandler( "HousingCollisionless", root, colloff ) If it doesn't work this time I'm just going to test and debug myself... But hopefully it will be a little better.
  18. Believe it or not I sorted this problem last night, but.... I still have big problems with table.insert Here is my updated code, I can hopefully figure it all out if you or someone else helps me understand where I am going wrong with inserting into the table... local accountSafe = {} local serial = getPlayerSerial( source ) local oldAccounts = getAccountsBySerial( serial ) --So this returns a table, so in my mind, this will then BECOME a table... if not oldAccounts == false then --If they have old accounts (I will add checks for current account later) outputChatBox("You have an account and your data will now be transferred to the new one.", source, 50, 255, 200) --Tell them dataSafe = {} --Here is my "dataSafe" where I will use table.insert to add each index of, the account name, the data, the value local name --To store name for i=1,#oldAccounts do --For each account accounts = oldAccounts[i] --This is how I get the data from table name = getAccountName ( accounts ) --I get the name with "accounts" and it's the players name local data = getAllAccountData( accounts ) --I then get all the players data if ( data ) then --If they have data for k,v in pairs ( data ) do --Data returns tuple (Name, Value) table.insert(dataSafe, tostring(name)..","..tostring(k)..","..tostring(v)) --Here is the issue, it adds "nil" end end end for i=1,#dataSafe do --Outside my for to cycle through accounts is where I will merge data, for now it prints the table name, k, v = dataSafe[i][1],dataSafe[i][2],dataSafe[i][3] --So it does index them, BUT, it indexes as nil... outputChatBox(tostring(name)..""..tostring(k)..""..tostring(v), source) --As you can see when it prints end end All you'd have to do to test this and see what I mean is add an onPlayerJoin handler... I have tried adding indexes multiple ways, separated by commas. inserted with the index as a second argument as you'll see here, and even tried adding them together the same way you would if you were to output to chat, nothing but "nilnilnil" Just so you know, the result I am trying to get is: dataSafe = { {Account1,Name1,Value1}, {Account1,Name2,Value2}, {Account2,Name1,Value1}, --Each account gets the account name, then the account data name and then data value. {Account2,Name2,Value2}, {Account3,Name1,Value1}, {Account3,Name2,Value2} --Just keeps adding lines like above, obviously table is hidden, but this is to show what I want to happen in the background... } Here is a quick link to lua manual where table.insert is on page, I just don't understand the lua manual that clearly no matter how many times I read it http://www.lua.org/manual/5.2/manual.html#6.5 I have no idea how to use it really and I am just blindly trying different things until it works... On the bright side, I'm slowly getting there, it's just I could really do with an in depth view to table.insert....
  19. Love it, 5/5 man, I learned a lot from this!
  20. Well, first of all you have localPlayer where root should be, read addEventHandler on the wiki You are trying to pass "sourceplayer" when it's not included in your function, to sort this, since this script is client side, use localPlayer. Also you are just going to set the vehicle so it can't collide with one player (I think) I have not used setElementCollidableWith yet as I have had no use for it.... But I will try fix your code a little function colloff () local theVeh = getElementData( localPlayer, "freecar" ) --local v = getPedOccupiedVehicle(localPlayer) --If you still have no luck try this for index,vehicle in ipairs(getElementsByType("vehicle")) do --LOOP through all Vehicles, if you want it to be players change it to player setElementCollidableWith(vehicle, theVeh, false) -- Set the Collison off with the Other vehicles, (the vehicles, your vehicle, state) end end addEvent( "test", true ) addEventHandler( "test", root, colloff ) Could work, could not work, if you really want I can test it and get back to you
  21. Forgot to mention, you can use the element data you set when a vehicle spawns for the player client and server side, they share it, so a little element data is good, LOTS of element data being passed is very bad, as it's CPU intensive... Just be wary of using it since you are a fairly new scripter, also you should check out IIYAMA's tutorial on debugging, it isn't just /debugscript 3, he walks you through manual debugging Manual debugging is super useful, the way the debugscript works is it just runs through some simple checks, checking if you have certain information at certain points, this is making it limited, so it sometimes will show nothing, so just keep in mind that manual debugging is there
  22. See where you have time.month Add this bit of code where you want to add +1 time.month = (tonumber(time.month)) + 1 --This should do time.month = the month converted to a number plus one
  23. With the help of the forums I know enough about lua to help out on forums every now and then, my only advice is to start off small and slowly challenge yourself with more complicated scripts. /debugscript 3 this EXTREMELY useful command tells you what went wrong and where it went wrong, you just got to figure out how to fix it. Always check top right on forums this is the best tip I can give any new person that is scripting, if it says "Shared function" you can use this function both on the client side, and server side, if it says "Useful function" this often means you need to include the "code" section in your own code, along with the example code.... "Server-only" and "Client-only" <<<IMPORTANT this tells you if you can only use a function on the server side or the client side! Hope this helps you! Just remember, check where you can use it, and always use /debugscript 3.... It will make life so much easier, OH! And my final piece of advice to you would be to very carefully read the page where the function is, it can tell you restrictions, uses, and even give you links to functions you can use with it! Good luck!
  24. First off, don't do setElementCollisionsEnabled on vehicles, not a happy ending..... The good news is, there is a client side function that is setElementCollidableWith Please carefully read the wiki, it clearly says if you use setElementCollisionsEnabled on a vehicle it will cause bugs..... I know the temptation to grab code, but it is all useful information. I have a small script I made ages ago (with help on forums as I was a noob) that limits players to having one vehicle, all you'll need to do is change the part that checks if they have a vehicle and make it destroy there vehicle when they exit! function Elegy (hitElement) --Get source and pass it as hitElement local theVeh = getElementData( hitElement, "freecar" ) --Get the players data as it is set to there vehicle if ( theVeh ~= false ) then --If the player has the element data they have spawned a car destroyElement(theVeh) --So we destroy the car here setElementData(hitElement, "freecar", false) --Now we want to set the data to false, this is important!!! end local x, y, z = getElementPosition (hitElement) --Get the players position local rotX, rotY, rotZ = getElementRotation (hitElement) --Get their rotation veh = createVehicle (562, x, y+5, z, rotX, rotY, 270) --Create a vehicle warpPedIntoVehicle (hitElement, veh) --Warp player into vehicle setElementData(hitElement, "freecar", veh) --Set the players data to the vehicle you just created, we can use the data to destroy the vehicle end addCommandHandler("spawnElegy", Elegy) Hope this helps, use "/debugscript 3" when you have issues on your script, it help A LOT.
×
×
  • Create New...