Jump to content

ShayF2

Members
  • Posts

    230
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ShayF2

  1. You can make it do what you want.
  2. local vehicle = getPedOccuipiedVehicle(localPlayer) for i,v in pairs(getElementsByType('vehicle')) do setElementCollidableWith(vehicle,v,false) end This code is an example on client side, it will disable collision between vehicles, this works as like a ghostmode type script.
  3. Disabling collision to a vehicle will prevent anything colliding with it, even the world. What you'd want to do is set what it can collide with, other vehicles, players, obects etc.. Using setElementCollidableWith()
  4. ShayF2

    question

    Using API's with fetchRemote is the best way to use website services like youtube or gmail. However these API's need keys, you get keys from registering yourself up to use the api and it will give you a key. It's not that difficult to use an api with fetchRemote either, you can send the api information and the fetch remote will grab any info that the api sends back. However with fetchRemote things are not instant, they are fast but not instant. So you don't want to grab things from fetch remote until you know for sure it's finished uploading and downloading that data. I hope that I have helped you. Good luck.
  5. Recreate the entire script either with gui or dx. The main script is way too complicated to edit. best of luck mate.
  6. GTA SA map limit is not set by the game but it is set by MTA. MTA's map limit is 6000x6000
  7. Poorly designed code, not clear issue, code expanded and hard to read. Error code outputs that whatever variable you are using at the line it tells you, it is not of the vehicle type. Good luck.
  8. ShayF2

    Round Robin

    I think I figured out the issue. Say I have 3 items in the gridlist and the maxItems is calculated to be 5. The start position would change to -2 when it's range is only 1 to 3. This is because it does the math self.startPos = #self.items-self.maxItems. I'm not totally sure that fixing this will fix the problem, I will test it when I have the time. Today I don't really have the time.
  9. ShayF2

    Round Robin

    Hello. I'm a scripter for MTA:SA, many of you have seen me on the forums, posting helpful things on your threads. Today I need some help. This code below is code to create dx gridlists. I use arrow keys to control what I select. However when the gridlist can show 5 items at a time and I only put 3 in, it seems to overlap, thinking that there is an extra index. So long as the gridlist has at least 5 items it'll work perfectly fine. Could someone please help me fix this round robin effect? function dxCreateGridlist(x,y,w,h) local self = dx('gridlist','default',x,y,w,h) if self then self.itemHeight = 25 self.maxItems = math.floor(self.h/self.itemHeight) self.bgColor = tocolor(0,0,0,180) self.selectedColor = tocolor(80,80,80,180) self.textColor = tocolor(255,255,255,200) self.startPos = 1 self.endPos = 20 self.currentItem = 1 self.itemSpacing = 2 self.selected = 1 self.items = {} self.draw = function() self.endPos = self.startPos+self.maxItems local yOff = 0 for i=self.startPos,self.endPos do if self.items[i] then if i == self.selected then dxRect(self.x,self.y+yOff,self.w,self.itemHeight-self.itemSpacing,self.selectedColor) dxText(self.items[i].text,self.x,self.y+yOff,self.w,self.itemHeight-self.itemSpacing,self.textColor) else dxRect(self.x,self.y+yOff,self.w,self.itemHeight-self.itemSpacing,self.bgColor) dxText(self.items[i].text,self.x,self.y+yOff,self.w,self.itemHeight-self.itemSpacing,self.textColor) end yOff = yOff+((self.itemHeight))+self.itemSpacing end end end self.addItem = function(text) local item = {} item.text = text table.insert(self.items,item) end self.itemsClear = function() for k=1,#self.items do table.remove(self.items,k) end end self.onKey = function(key,state) if state then if key == 'num_8' then if self.selected < self.startPos then if self.selected <= 1 then self.startPos = #self.items-self.maxItems self.selected = #self.items else self.startPos = self.startPos-1 end else self.selected = self.selected-1 end elseif key == 'num_2' then if self.selected > self.endPos then if self.selected >= #self.items then self.selected = 1 self.startPos = 1 else self.startPos = self.startPos+1 end else self.selected = self.selected+1 end elseif key == 'num_enter' then outputChatBox(self.items[self.selected].text) end end end table.insert(draw,self) return self end end
  10. addEventHandler('onMarkerHit',root,function(player) -- replace root with marker or if you use multiple markers please use the code below local name = getTeamName(getPlayerTeam(player)) or 'None' outputChatBox('You are in team: '..name,player,0,255,255) end) local markers = {} addEventHandler('onMarkerHit',root,function(player) for i=1,#markers do if source == markers[i] then local name = getTeamName(getPlayerTeam(player)) or 'None' outputChatBox('You are in team: '..name,player,0,255,255) end end end)
  11. triggerServerEvent('eventName',root,localPlayer) Do not use other functions to get root or get local player, just use this, and then on the event handler you'll have something like addEventHandler('eventName',root,function(player) end) -- where player would be your local player.
  12. This is due to improper math calculations.
  13. Thank you, I'm on a phone and a bit busy, hard to type or even thing of reasonable math. So thank you for fixing my code.
  14. local reductionPercent = '50' addEventHandler('onClientPlayerDamage',root,function(attacker,weapon,bodypart,loss) if loss then local health = getElementHealth(localplayer) setElementHealth(localplayer,health+(loss/reductionPercent)) end end) Something like this. No offense, I was using a phone to type this, so code might look wonky..
  15. Using checks usually helps, like shown in the code says if isElement() then That's a check, which prevents errors in your code. Using this you know that if the script does nothing in a result, that either the sound does not exist, is not an element, or is not visible to the other function. I hope that this helps, have a nice day.
  16. local markers = {} function addMarker(x,y,z,type,size,r,g,b,a,visible) local self = {} self.x = x or 0 self.y = y or 0 self.z = z or 0 self.type = type or 'checkpoint' self.size = size or 1 self.r = r or 0 self.g = g or 0 self.b = b or 0 self.a = a or 255 self.visible = visible or root table.insert(markers,self) return self end function startMarkers() for i=1,#markers do local m = markers[i] if m.marker then if isElement(m.marker) then destroyElement(m.marker) end end m.marker = createMarker(m.x,m.y,m.z,m.type,m.size,m.r,m.g,m.b,m.a,m.visible) end end local marker1 = addMarker(0,0,0,'cylinder',1,0,255,255,root) startMarkers() Maybe this script isn't what you wanted, however it allows you to store markers in a table without triggering them. It allows you to trigger them whenever you want. That way you could do what you want with the table, you know adding positions, but this way you're adding the entire marker. And then creating it whenever you want. I hope you find this helpful, have a nice day. Here is what you were looking for, I hope you have a nice day. local positions = { {x=0,y=0,z=0}, {x=1,y=1,z=1},-- use whatever positions u want {x=2,y=2,z=2} } function marker(type,size,r,g,b,a,visible) local type = type or 'cylinder' local size = size or 1 local r,g,b,a = r,g,b,a or 255,255,255,255 local visible = visible or root local pos = positions[math.random(1,#positions)] return createMarker(pos.x,pos.y,pos.z,type,size,r,g,b,a,visible) end local mark = marker()-- this allows u to not put values in if u dont want to. Also this may help you for future scripts. function getRandomFromTable(tab) if tab and tab[2] then local rand = math.random(1,#tab) return tab[rand] end end local pos = getRandomFromTable(positions)
  17. Hi, I saw this and I figured I'd say something. I've been scripting for about 5 years as of now and debugging code has always been testing what parts of the code work and what parts don't. Usually debug scripts come with panels showing what went wrong. Sometimes it didn't show anything and I had to use hard debugging messages where I would output certain values in chat, or print. Debugging checks for faults in your code before final initialization. Or at least that's what it's mostly used for. I suppose you could output data for admins to read, like he/she did this/that etc.
  18. This is in the original dayz script for mta, which spawns randomly, unless there's not a spawn location there, I'd suggest you look at the files within the script if they are not compiled to see what you can do to get it to spawn.
  19. Try something like this. -- NOTE This code is not tested and may need to be edited to work properly. local symbol = '/' local commands = { 'help', 'commands' } addEventHandler('onPlayerChat',root,function(message) local textTable = split(message,' ') for k=1,#textTable do for l=1,#commands do if textTable[1] == symbol..commands[l] then table.remove(textTable,1) triggerEvent(commands[l],root,source,textTable) end end end end) for i=1,#commands do addEvent(commands[i]) end addEventHandler('help',root,function(source,payload) outputChatBox('Use /commands for a list of commands.',source) end) addEventHandler('commands',root,function(source,payload) outputChatBox('Commands: '..table.concat(commands,', '),source) end)
  20. Try using something like this -- NOTE This code is not tested and may need to be edited to work properly. -- Client Side local teams = {} function addTeam(name,color,type,spawnx,spawny,spawnz,camerax,cameray,cameraz,skins) if name and color and type and spawnx and spawny and spawnz and camerax and cameray and cameraz and skins then local self = {} self.name = name self.color = color self.type = type self.skins = skins self.spawnPos = Vector3(spawnx,spawny,spawnz) self.cameraPos = Vector3(camerax,cameray,cameraz) table.insert(teams,self) return self end end function createTeams() for i=1,#teams do createTeam(teams[i].name,teams[i].color) end end local selection = 1 function startSelection() for i=1,#teams do if i == selection then setCameraMatrix(teams[i].cameraPos,teams[i].spawnPos) end end bindKey('arrow_l','down',function() if selection-1 < 1 then selection = #teams else selection = selection-1 end end) bindKey('arrow_r','down',function() if selection+1 > #teams then selection = 1 else selection = selection+1 end end) bindKey('enter','down',selectTeam) end function selectTeam() for i=1,#teams do if i == selection then triggerServerEvent('spawnPlayer',root,localPlayer,teams[i]) end end end -- Server Side addEvent('spawnPlayer',true) addEventHandler('spawnPlayer',root,function(player,teamData) local skinID = math.random(1,#teamData.skins) spawnPlayer(player,teamData.spawnPos,0,teamData.skins[skinID]) setCameraTarget(player,player) end) I hope this has helped you, have a nice day. This is an example of how to use the code above. addEventHandler('onClientResourceStart',resourceRoot,function() addTeam('Freeroam',{0,255,255},'player',0,0,0,20,20,5) startSelection() end)
  21. local t1,t2 = string.split(string,',') Or local t1,t2 = split(string,',') One of those to split the string Then string.gsub(t1,'INTERIOR: ','') and string.gsub(t2,'OWNER = ','')
  22. local vehicles = getElementsByType('vehicle') for i=1,#vehicles do local name = getVehicleNameFromModel(getElementModel(vehicles[i])) if name == 'sultan' then local driver = getVehicleOccupant(vehicles[i]) if driver then return driver end end return false end
  23. ShayF2

    help

    -- This code is NOT tested and may need adjustments in order to work properly. -- Client Side local money function moneyChange(oldMoney,newMoney) local inc local change if newMoney > oldMoney then inc = 'raised' change = newMoney-oldMoney elseif newMoney < oldMoney then inc = 'lowered' change = oldMoney-newMoney end outputChatBox('Your money has '..inc..' by '..change..' Balance: '..newMoney,0,255,255) end addEventHandler('onClientRender',root,function() local newCash = getPlayerMoney(localPlayer) if not money then money = newCash else if newCash > money or newCash < money then moneyChange(money,newCash) money = newCash end end end) -- Serverside local money = {} function moneyChange(player,oldMoney,newMoney) local inc local change if newMoney > oldMoney then inc = 'raised' change = newMoney-oldMoney elseif newMoney < oldMoney then inc = 'lowered' change = oldMoney-newMoney end outputChatBox('Your money has '..inc..' by '..change..' Balance: '..newMoney,player,0,255,255) end setTimer(function() for i,plr in pairs(getElementsByType('player')) do local newCash = getPlayerMoney(plr) if not money[plr] then money[plr] = newCash else if newCash > money[plr] or newCash < money[plr] then moneyChange(plr,money[plr],newCash) money[plr] = newCash end end end end,1000,0) I hope that this has helped you, have a nice day.
  24. There's quite a few methods of saving data in MTA Lua. Local Saving 1. Lua Table (Temporary data, works similar to ram, where all data is destroyed when script stops) 2. SQLite (Saving to internal server database) External 3. TXT (Saving strings to a txt file and then loading them again with loadstring()(), not very organized and needing to save functions) 4. JSON (Converting lua tables to JSON with toJSON() function, then saving the result of the toJSON() function into a JSON file and loading it again by reading the file and using fromJSON() function on the buffered content) 5. XML (Saving nodes into xml and then loading them again with MTA's premade xml functions) 6. MySQL (Best method for saving data, goes into an external database, load/read time is fast, downside being that it relies on a MySQL Server) 4. LUA (Similar to txt, converting a chunk of a script into a string and then exporting it to a file to be loaded later on with fileRead and loadstring()(), used when transporting scripts) I hoped that this has helped you, lots of choices to choose from, good luck and have a nice day.
  25. This code may help, you will have to modify it to fit your script, however this is a basic layout of how you want it. local x,y,z = getElementPosition(marker) local sx,sy = getScreenFromWorldPosition(x-2,y,z+1) local sw,sh = getScreenFromWorldPosition(x+2,3,z+1)-- 3 will be your text height. addEventHandler('onClientRender',root,function() dxDrawText('Marker Text',sx,sy,sw,sh) end) Hopefully this has helped you, have a nice day.
×
×
  • Create New...