Jump to content

ShayF2

Members
  • Posts

    230
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ShayF2

  1. json is not that hard to use, its compact and really simplified. You make a lua table, then make a json file, convert the lua table to json with toJSON and then write it to the json file, and when you want to load it you just use fromJSON to convert it back to a lua table. That's why I prefer JSON over everything. local data = { {'blah','blah','blah'}, {'blah','blah','blah'} } function save() local file = fileOpen('save.json') or fileCreate('save.json') fileWrite(toJSON(data),file) fileClose(file) end function load() if fileExists('save.json') then local file = fileOpen('save.json') local size = fileGetSize(file) local buffer = fileRead(file,size) data = fromJSON(buffer) fileClose(file) end end If you were to use different saving methods than xml you would see why I treat it with disrespect. I personally prefer json and mysql.
  2. I see that you're attaching elements after setting their position, their position wont matter after you attach them, you need to use setElementAttachedOffsets, this uses the position from the vehicle, so in setElementAttachedOffsets the vehicles position will be 0,0,0. If the object does not appear on your vehicle then it most likely doesn't exist, if you have administrator privileges on the server you are testing with use /debugscript 3 and the print() function do debug variables and elements. print(isElement(Asiento2T))
  3. You there, why are you teaching him to use xml? xml sucks, it uses up 75-90% of the file just to create nodes WITHOUT the values themselves, and it's got complicated af functions. The best way to go for storage is the following: Internal - internal database with sqlite element data account data lua tables External - JSON MYSQL or MariaDB Okay and you here, this actually very simple, I'll give you some premium code a little tip before hand however ['a'] is the same as .a, I suggest you start using that. You only want to use [''] method when you have spaces in your string. I'll also show you how to combine commands into a single function and work a table properly. local items = {} function commands(player,cmd,name,value) if cmd == 'add' then if name and value and tonumber(value) then if not items[name] then items[name] = tonumber(value) end end elseif cmd == 'remove' then if name and items[name] then for i=1,#items do if items[i] == items[name] then table.remove(items,i) end end end elseif cmd == 'test' then iprint(items)-- only works on MTA 1.5.5+ servers end end local cmds = {'add','remove','test'} for i=1,#cmd do addCommandHandler(cmds[i],commands) end I hoped this has helped you, if not send me a private message. Example Command: /add six 6 Example Command: /remove six And to the rest of you out there, for the love of god please don't use xml, and just because you set a nil value to an item in a table doesn't mean that the item is gone, it's still there it just doesn't have a value..
  4. Asiento = {} for i=1,21 do Asiento[i] = 0 end function SubenPasajeros(client) if CantidadDeAsientos >= 0 then if Asiento[1] == 0 then Asiento[1] = 1 local vehicle = getPedOccupiedVehicle(client) local x1,y1,z1 = getElementPosition(client) local Asiento1T = createObject(2035,1423.2880859375,2602.650390625,10.8203125) setElementPosition(Asiento1T,x1,y1,z1) attachElements(Asiento1T,vehicle,0.95,0.6,0,0,0,0) outputChatBox('Asiento1') else if Asiento[2] == 0 then Asiento[2] = 1 outputChatBox('Asiento2') local vehicle = getPedOccupiedVehicle(client) local x1,y1,z1 = getElementPosition(client) local Asiento2T = createObject(2035,1421.958984375,2624.4677734375,11.392612457275) setElementPosition(Asiento2T,x1,y1,z1) attachElements(Asiento2T,vehicle,0.5,-0.2,0,0,0,0) end end end function greetingCommand(client) setTimer(SubenPasajeros,500,1,client) triggerClientEvent('onGreetingb',root,PasajSuben) end Try this.
  5. You're setting Asiento1 and Asiento2 as integers and then setting them as elements, which won't allow the check to run again. Change the variable names for your objects and try it again.
  6. ShayF2

    Camber

    I'm wondering what math I need to do camber effect to wheels, I need to set y rotation based off of x rotation, I'm just not sure how to do it. Can someone help me ? Debugscript Legend: INFO: rotation X : rotation Y : amount of camber
  7. I didn't want to put this into resources because it's not a resource, its more of a useful function. I made this today and I thought that it would help a lot of scripters. This is a onVehicleSpawn event that I made, it is server side only. Here is how you use it. addEvent('onVehicleSpawn') local last = 0 setTimer(function() local vehs = getElementsByType('vehicle') if #vehs > last then last = #vehs triggerEvent('onVehicleSpawn',root,vehs[#vehs]) end end,50,0) -- then use it like so addEventHandler('onVehicleSpawn',root,function(vehicle) setElementPosition(vehicle,0,0,0) -- or whatever u want here.. end)
  8. Are you wanting to learn lua but no scripter will teach you? We all know its hard to find decent tutorials and understand that it would be better to know the material rather than ask for help with it all the time. That's why I designed Vinewood Development Extras. VDE teaches people how to script in MTA. Lessons are FREE. Lessons are uploaded daily and there are channels to ask for help from teachers or certified professionals. This includes a free test server to test scripts, just talk to ShayF to set up an ftp account. I hope that you enjoy the community, happy scripting my friends! Vinewood Development Extras Discord
  9. ShayF2

    Parked Cars

    local parked = {} function parkedCar(player,seat,owner) if source and player and seat and owner then if seat == 0 then if not player == owner then cancelEvent() outputChatBox('You cannot enter this vehicle, it is parked by '..getPlayerName(owner),player,255,0,0) outputChatBox(getPlayerName(player)..' has tried to get access to your parked vehicle.',owner,255,0,0) end end end end setTimer(function() for i=1,#parked do if parked[i].park then parked[i].event = addEventHandler('onVehicleStartEnter',parked[i].vehicle,parkedCar,parked[i].vehicle,parked[i].owner) setElementFrozen(parked[i].vehicle,true) else parked[i].event = removeEventHandler('onVehicleStartEnter',parked[i].vehicle,parkedCar) setElementFrozen(parked[i].vehicle,false) end end end,1000,0) addCommandHandler('parkcar',function(player,cmd) local vehicle = getPedOccupiedVehicle(player) if vehicle then local driver = getVehicleOccupant(vehicle) if driver == player then local self = {} self.owner = player self.vehicle = vehicle self.park = true table.insert(parked,self) end end end) addCommandHandler('unparkcar',function(player,cmd) local vehicle = getPedOccupiedVehicle(player) if vehicle then local driver = getVehicleOccupant(vehicle) if driver == player then for i=1,#parked do if parked[i].vehicle == vehicle then parked[i].park = false end end end end end) Something like that idk. This is untested code and may need modifications, good luck.
  10. None of us help with ripped scripts. If you steal someone else's work then you do it on your own. If someone helps you then they are stupid. You're real lucky if nexus doesn't have a copyright protection claim on that script. Otherwise you'd be breaking the law.
  11. Use fetchRemote with a youtube to mp3 converter api. If you don't know how to do this, learn. It's actually quite simple.
  12. It may be part of the freeroam script, or possibly another script in the server. Usually its freeroam though. So look into its code and see if you can find a respawn on death function or whatever. And for the love of god please use a codebox next time.
  13. Compiled scripts cannot be uncompiled unless you have a profession in that field of decrypting encrypted stuff. If the script is having errors while its compiled, I just assume getting rid of it. Scripts are compiled when the author of the script doesn't want people stealing his/her work.
  14. Best way is to run a timer on server side checking the data in the sql, since the sql connection stays constant.
  15. local camera = createCamera(0,0,0) setElementPosition(camera,1,1,1) Tadaa
  16. Yes, you set the progress bar progress to the players health, like I showed.. of course it doesn't have borders around it, but you can add borders in the self.draw function.
  17. show me example that is tested to work.
  18. dont worry about the debug errers i took care of dem, i just cant get the dam thing centered under the hud with custom width calculated by text length.
  19. Uh I wouldn't because a lot of id's are used, uh you would have to grab 2 id's and swap them, or use 5 digits. But uh, good bro.
  20. I want to center the dx elements in a certain space via math with text length and max text length. Here is my code as well as a picture to show its status. local messagesList = { '----------- Coming Soon!', 'Visit the site! http://---------/', 'Let your voice be heard! http://---------/forum/', 'READ F9!' } local sx,sy = guiGetScreenSize() local sw,sh = 1360,768 local currentMessage = 1 function dxRect(...) arg[1],arg[2],arg[3],arg[4] = arg[1]/sw*sx,arg[2]/sh*sy,arg[3]/sw*sx,arg[4]/sh*sy return dxDrawRectangle(unpack(arg)) end function dxText(...) arg[2],arg[3],arg[4],arg[5],arg[7] = arg[2]/sw*sx,arg[3]/sh*sy,(arg[4]+arg[2])/sw*sx,(arg[5]+arg[3])/sh*sy,(arg[7] or 1)/sw*sx return dxDrawText(unpack(arg)) end addEventHandler('onClientPreRender',root,function() local width = dxGetTextWidth(messagesList[currentMessage]) dxRect(1068-8,107,width+16,21,tocolor(0,0,0,192),false) dxText(messagesList[currentMessage],1068,107,width,21,tocolor(0,255,255,255),1,'default-bold','center','center',false,false,false) end) setTimer(function() if currentMessage ~= #messagesList then currentMessage = currentMessage+1 else currentMessage = 1 end end,5000,0)
  21. My code for his other thread that I posted above has everything you'll ever need. If he wants to draw lines around it then he can. My code is Auto relative, he puts in his resolution then positions it and sizes it, it will resize and reposition for other resolutions. He can also change the colors of it. Mainly the progress of the progress bar, which is controlled when player loses health. styles = {} styles['progressBar'] = { ['default'] = { bgColor = tocolor(0,0,0,180), barColor = tocolor(255,255,255,200), textColor = tocolor(255,0,0,255) } } local sx,sy = guiGetScreenSize() local sw,sh = 1360,768-- Change this to your resolution and use absolute values when creating elements. local draw = {} local validTypes = {'progressBar'} function dxRect(...) arg[1],arg[2],arg[3],arg[4] = arg[1]/sw*sx,arg[2]/sh*sy,arg[3]/sw*sx,arg[4]/sh*sy return dxDrawRectangle(unpack(arg)) end function dxText(...) arg[2],arg[3],arg[4],arg[5],arg[7] = arg[2]/sw*sx,arg[3]/sh*sy,(arg[4]+arg[2])/sw*sx,(arg[5]+arg[3])/sh*sy,(arg[7] or 1)/sw*sx return dxDrawText(unpack(arg)) end function dx(type,theme,x,y,w,h,visible) for i=1,#validTypes do if type == validTypes[i] then local self = {} self.type = type self.x = x or 0 self.y = y or 0 self.w = w or 0 self.h = h or 0 self.style = styles[self.type][theme] or styles[self.type]['default'] self.visible = visible or true self.destroy = function() for i=1,#draw do if draw[i] == self then table.remove(draw,i) end end end return self end end return false end function dxCreateProgressBar(text,x,y,w,h) local self = dx('progressBar','default',x,y,w,h,true) if self then self.progress = 0 local pbText = text self.draw = function() dxRect(self.x,self.y,self.w,self.h,self.style.bgColor) if string.find(pbText,'%progress%',1,true) then pbText = string.gsub(pbText,'%progress%',tostring(math.floor(self.progress))..'%') end dxText(pbText,self.x,self.y,self.w,self.h,self.style.textColor) dxRect(self.x,self.y,(self.w/100)*self.progress,self.h,self.style.barColor) end table.insert(draw,self) return self end end addEventHandler('onClientRender',root,function() for i=1,#draw do if draw[i].visible then draw[i].draw() end end end) local progressBar = dxCreateProgressBar('Health %progress%',500,500,600,200)-- create a progress bar like this setTimer(function() local health = getPlayerHealth(localPlayer)-- if its 100 then use it, if its 200 then divide it by 2 if getPlayerMaxHealth(localPlayer) > 100 then health = health/2 end progressBar.progress = health -- then set the progress end,50,0) -- you can also set colors like this progressBar.style.barColor = tocolor(255,0,0,200) progressBar.style.bgColor = tocolor(255,255,255,160)
  22. I posted code that may help here, please do not make multiple threads here.
  23. styles = {} styles['progressBar'] = { ['default'] = { bgColor = tocolor(0,0,0,180), barColor = tocolor(255,255,255,200), textColor = tocolor(255,0,0,255) } } local sx,sy = guiGetScreenSize() local sw,sh = 1360,768-- Change this to your resolution and use absolute values when creating elements. local draw = {} local validTypes = {'progressBar'} function dxRect(...) arg[1],arg[2],arg[3],arg[4] = arg[1]/sw*sx,arg[2]/sh*sy,arg[3]/sw*sx,arg[4]/sh*sy return dxDrawRectangle(unpack(arg)) end function dxText(...) arg[2],arg[3],arg[4],arg[5],arg[7] = arg[2]/sw*sx,arg[3]/sh*sy,(arg[4]+arg[2])/sw*sx,(arg[5]+arg[3])/sh*sy,(arg[7] or 1)/sw*sx return dxDrawText(unpack(arg)) end function dx(type,theme,x,y,w,h,visible) for i=1,#validTypes do if type == validTypes[i] then local self = {} self.type = type self.x = x or 0 self.y = y or 0 self.w = w or 0 self.h = h or 0 self.style = styles[self.type][theme] or styles[self.type]['default'] self.visible = visible or true self.destroy = function() for i=1,#draw do if draw[i] == self then table.remove(draw,i) end end end return self end end return false end function dxCreateProgressBar(text,x,y,w,h) local self = dx('progressBar','default',x,y,w,h,true) if self then self.progress = 0 local pbText = text self.draw = function() dxRect(self.x,self.y,self.w,self.h,self.style.bgColor) if string.find(pbText,'%progress%',1,true) then pbText = string.gsub(pbText,'%progress%',tostring(math.floor(self.progress))..'%') end dxText(pbText,self.x,self.y,self.w,self.h,self.style.textColor) dxRect(self.x,self.y,(self.w/100)*self.progress,self.h,self.style.barColor) end table.insert(draw,self) return self end end addEventHandler('onClientRender',root,function() for i=1,#draw do if draw[i].visible then draw[i].draw() end end end) local progressBar = dxCreateProgressBar('Health %progress%',500,500,600,200)-- create a progress bar like this setTimer(function() local health = getPlayerHealth(localPlayer)-- if its 100 then use it, if its 200 then divide it by 2 if health > 100 then health = health/2 end progressBar.progress = health -- then set the progress end,50,0) -- you can also set colors like this progressBar.style.barColor = tocolor(255,0,0,200) progressBar.style.bgColor = tocolor(255,255,255,160) This is a bit of code from my dx library, maybe it'll help ya.
  24. setTimer is not a good way to do it, it's different if you are using the default hud or your own. Best way to do it is using increments (maybe decimals) in the onClientRender event that changes the health to what it's suppose to be but using a slow motion, animation like movement.
×
×
  • Create New...