Jump to content

ViRuZGamiing

Members
  • Posts

    1,050
  • Joined

  • Last visited

Everything posted by ViRuZGamiing

  1. I am a Pro at 3 Programming Languages , So LUA Would not be So Unrecognized to me. I would not think that You Said that because my last Code make's a problem right ? Okay nevermind then, it just looked like you really were starting from scratch. Just out of interest, which languages?
  2. Hello community, I'll be explaining the basics of LUA as I understand it. CONTENT Foreword My background Part 1 - Let's get started! Part 2 - Variables (Extra: concat) Foreword First of all I wanna make some things clear, I'm not the best scripter in the world let be in LUA. Second, I can write stuff here that some programmers will disagree that's why I am saying 'as I understand it'. I'm going to try and make this understandable for the beginner starting from scratch. My Background My name is Billy, I'm from Belgium and I've been interested in LUA since I started MTA in 2011, I've tried many times to understand LUA and thanks to IIYAMA I've continued trying and never gave up, he taught me a lot but I never saw the entire picture, Why? Because I was to focussed on trying to make something I want instead of learning the language first. I've seen C# in 1 school year and it learned me to understand and learn programming languages on my own. Part 1 - Let's get started! The first things we need to understand are datatypes in my opinion. In LUA there isn't that much to explain about datatypes since we don't need to declare them with our variable. BUT we need to make sure that variable data is of the same datatype. So we can't combine numbers and text we'd need to convert these numbers to plain text to fit in. (More about this later). Part 2 - Variables There are 2 types of variables, local and global. Example: local localVariable -- Here is 'localVariable' the name globalVariable -- Here is 'globalVariable' the name, ALSO we don't write global Now, what's the difference? globalVariable = "Hello" function funcName () local localVariable = "World" -- the name 'localVariable can only be used inside this function end outputChatBox(globalVariable) outputChatBox(localVariable) -- Result only globalVariable will be outputted, if we put the output inside the function local would work as well This would work, globalVariable = "Hello" function funcName () local localVariable = "World" -- the name 'localVariable can only be used inside this function outputChatBox(localVariable) end outputChatBox(globalVariable) Try avoiding the use of global variables as much as possible! Part 2 Extra - Concat We can use both variables as plain text but to merge them we have to 'concat' them. What is concat? Text example: LUA Example: local localVariable = "Hello" outputChatBox(localVariable.." World!") .. is concat you can see it as a + (Do not see it as a + for calculations but for adding text to eachother) ________________________________________________________________________________ If this is the end of the tutorial? That's what you guys decide, it took me some time for this and I am definitely not the best teacher but if you guys think I should continue I definitely will. I have a lot more to feature to finish the entire basics I hope this will be accepted as a good attempt to teaching. Kind regards Billy
  3. I suggest start learning LUA from the start and not from a view of something you want to make. Learn LUA stepwise, Datatypes, If, Else, For, Array's after studying this LUA becomes a whole easier.
  4. You removed this; local vehicle = getPedOccupiedVehicle (getLocalPlayer())
  5. I was actually thinking the same but thought that the weapon property would be easier.
  6. What you could do is check if the amount going off of the armor (ex. 20) is greater then the remaining armor (ex. 10). Then do; (if 20 > 10 then), In that case you could do (20 - 10) and then 10 is your difference. Set armor to 0 and take the remaining 10 off of the health. Example in LUA (might not be the best solution) function damageFunc (attacker, attackerweapon, bodypart, loss) cancelEvent() -- Not sure but I think if not cancelling it the damage is doubled local armor = getPedArmor(source) -- example. no armor, armor is 0 if (loss > armor) then loss = loss - armor -- Loss example 20, loss = 20 - 0 = 20 setPedArmor(source, 0) setElementHealth(source, (getElementHealth(source) - loss) -- health - 20 else setPedArmor(source, (armor - loss)) end end addEventHandler("onPlayerDamage", getRootElement(), damageFunc)
  7. Depends on your look on a wanted system but pretty much would be done over elementData, accountData or SQL queries if you're not using the casual wanteds.
  8. function onPlaySound() local sound = playSound("file/sound.wav") setSoundVolume(sound, 0.5) setTimer ( function() stopSound(sound) end, 2000, 1) end EDIT. This is to stop after 2000 ms, example above will start after 2000 ms
  9. Hazard lights are simply recreated with vehicle lights why use custom lights? Hazard lights:
  10. Is this server sided because you can use the 'visibleTo' for createBlipAttachedTo instead of setElementVisibleTo
  11. yes there is; setVehicleLightState @knightscript, it's when you're parking your car somewhere temporarily.
  12. The best to do is just create your own group system of course if you do like the one you're using you could adapt your code to fit in with the group panel.
  13. Add this, addEventHandler("onPlayerQuit", getRootElement(), function() destroyElement(getElementData(source, "spawnedCar")) end) EDIT nvm you found it.
  14. createBlipAttachedTo If you set the visibleDistance high enough, you see the blip from every position on your 'gps', it's always visible on Radar (F11) tho.
  15. you could use a boolean and onClientColShapeHit true, onClientColShapeLeave false.
  16. Maybe too advanced but can't you get a vehicle in your line of sight instead of the ped thing? Also not sure if it's secure.
  17. Maybe this works? setControlState(source, "handbrake", true) Regards Billy
  18. It's a bit of an weird way to do it, but I guess you could get the position and set it everytime it changes but it'll be too server or client intensive I guess.
  19. Maybe you can use this; https://wiki.multitheftauto.com/wiki/IsGuestAccount
  20. Maybe explain what you expect to be scripted.
  21. triggerServerEvent("CJAPS", CJ, 24, 999) -- 24 is Max Health, 999 the value function CJAPSs(stat, value) setPedStat(source, stat, value) end addEvent("CJAPS",true) addEventHandler("CJAPS", getRootElement(), CJAPSs)
  22. Nope, it's been implemented way back but it didn't work out.
  23. addCommandHandler(k, playMusic) and get rid of the triggers
  24. Not that your code is bad but wouldn't be /play pokerface be more obvious? /play namesong
  25. I'm not able to understand your text can you write in steps (1, 2, 3, ...) what you needs to happen.
×
×
  • Create New...