ShayF2 Posted February 26, 2017 Share Posted February 26, 2017 I'm trying to make a phone script, where I can make a base script and then just keep releasing phones and updates for those phones. A script where people can download like, addons, and just plug them in and run them. I cannot get the phone to draw on the screen, I need help with this script. Note this is advanced MTA Lua code, professionals needed. Please help me with this. Code will be posted below with file names and resource names inside of spoilers. meta.xml (Phone) Spoiler <meta> <info name="Phone Base System" author="Shaio Fencski" version="0.0.1" type="script"/> <script src="server.lua" type="server"/> <script src="client.lua" type="client"/> <include resource="voice"/> <include resource="bone_attach"/> <settings> <setting name="Default Phone" value="Moto G3 (White)"/> <setting name="Default Theme" value="SimpleDark"/> <setting name="Default Carrier" value="US Cellular"/> <setting name="Max Messages" value="10"/> </settings> </meta> server.lua (Phone) Spoiler Towers = {} Phones = {} Themes = {} Apps = {} playerData = {} addEvent('addTower',true) addEventHandler('addTower',root,function(company,x,y,z,radius,code) if not Towers[company] then Towers[company] = {} end table.insert(Towers[company],{x = x,y = y,z = z,radius = radius,code = code}) end) addEvent('addPhone',true) addEventHandler('addPhone',root,function(phone,size,buffer,txd,dff,id) if not Phones[phone] then Phones[phone] = {} end table.insert(Phones[phone],{size = size,picture = buffer}) end) addEvent('addTheme',true) addEventHandler('addTheme',root,function(theme,...) if not Themes[theme] then Themes[theme] = {} end local values = table.concat({...},',') table.insert(Themes[theme],values) end) addEvent('addApp',true) addEventHandler('addApp',root,function(app,...) if not Apps[app] then Apps[app] = {} end local values = table.concat({...},',') table.insert(Apps[app],values) end) addEventHandler('onPlayerLogin',root,function(_,c) bindKey(source,'o','down',openPhone) if not playerData[getAccountName(c)] then playerData[getAccountName(c)] = {} playerData[getAccountName(c)]['carrier'] = get('Default Carrier') playerData[getAccountName(c)]['phone'] = get('Default Phone') playerData[getAccountName(c)]['theme'] = get('Default Theme') playerData[getAccountName(c)]['apps'] = {} else pCarrier = playerData[getAccountName(c)]['carrier'] pPhone = playerData[getAccountName(c)]['phone'] pTheme = playerData[getAccountName(c)]['theme'] pApps = playerData[getAccountName(c)]['apps'] end end) function openPhone(player,key,state) if key == 'o' then if state == 'down' then local acc = getPlayerAccount(player) if not isGuestAccount(acc) then for i,phone in pairs(Phones) do if playerData[getAccountName(acc)]['phone'] == Phones[phone] then for k,d in pairs(Phones[phone]) do local size = d.size local picture = d.picture end triggerClientEvent(player,'openPhone',player,d.size,d.picture) if getElementData(player,'phone') == false then setElementData(player,'phone',true) else setElementData(player,'phone',false) end end end end end end end client.lua (Phone) Spoiler layout = {} addEvent('openPhone',true) addEventHandler('openPhone',root,function(size,picture) local phoneLayout = layout['default'] local phoneImage = dxCreateTexture(picture) addEventHandler('onClientRender',root,function() local toggle = getElementData(localPlayer,'phone') if toggle == true then local sx,sy = guiGetScreenSize() dxDrawImage(sx*0.8097,sy*0.3750,sx*0.1794,sy*0.5755,phoneImage,0,0,0,tocolor(255,255,255,255),false) end end) end) meta.xml (MotoG3B) Spoiler <meta> <info name="Motorola G3 Phone (Black)" author="Shaio Fencski" version="0.0.1" type="script"/> <script src="server.lua" type="server"/> <script src="client.lua" type="client"/> <file src="/model/motog3.txd"/> <file src="/model/motog3.dff"/> <include resource="Phone"/> </meta> server.lua (MotoG3B) Spoiler addEventHandler('onResourceStart',resourceRoot,function() if fileExists('/pic/motog3b.png') then local buffer = fileRead(fileOpen('/pic/motog3b.png'),fileGetSize(fileOpen('/pic/motog3b.png'))) triggerEvent('addPhone',root,'Moto G3 (Black)',5,buffer,'/model/motog3.txd','/model/motog3.dff',1575) end end) Link to comment
Administrators Lpsd Posted February 26, 2017 Administrators Share Posted February 26, 2017 Any errors when using `debugscript 3`? Link to comment
Captain Cody Posted February 26, 2017 Share Posted February 26, 2017 Try debugscript, and adding debug messages throughout the code. Link to comment
ShayF2 Posted February 26, 2017 Author Share Posted February 26, 2017 I'm currently working on an advanced house system, I will debug the script tomorrow, manually, since it doesn't produce any debug errors. Link to comment
ShayF2 Posted February 27, 2017 Author Share Posted February 27, 2017 (edited) I have debugged the script, I will re-type the script below including the debug messages and above I will paste what the output was. The meta's did not change so I will not repaste them. here are the debug messages in order. Spoiler onResourceStart event triggered found phone picture picture data converted addPhone event triggered phone not in table yet txd loaded dff loaded playerdata set to default key pressed key down not guest server.lua (phone) Spoiler Towers = {} Phones = {} Themes = {} Apps = {} playerData = {} addEvent('addTower',true) addEventHandler('addTower',root,function(company,x,y,z,radius,code) outputChatBox('addTower event triggered') if not Towers[company] then Towers[company] = {} outputChatBox('company not in table yet') end table.insert(Towers[company],{x = x,y = y,z = z,radius = radius,code = code}) end) addEvent('addPhone',true) addEventHandler('addPhone',root,function(phone,size,buffer,txd,dff,id) outputChatBox('addPhone event triggered') if not Phones[phone] then Phones[phone] = {} outputChatBox('phone not in table yet') end table.insert(Phones[phone],{size = size,picture = buffer}) end) addEventHandler('onPlayerLogin',root,function(_,c) bindKey(source,'o','down',openPhone) if not playerData[getAccountName(c)] then playerData[getAccountName(c)] = {} playerData[getAccountName(c)]['carrier'] = get('Default Carrier') playerData[getAccountName(c)]['phone'] = get('Default Phone') playerData[getAccountName(c)]['theme'] = get('Default Theme') playerData[getAccountName(c)]['apps'] = {} outputChatBox('playerdata set to default') else pCarrier = playerData[getAccountName(c)]['carrier'] pPhone = playerData[getAccountName(c)]['phone'] pTheme = playerData[getAccountName(c)]['theme'] pApps = playerData[getAccountName(c)]['apps'] outputChatBox('loaded saved player data') end end) function openPhone(player,key,state) if key == 'o' then outputChatBox('key pressed') if state == 'down' then outputChatBox('key down') local acc = getPlayerAccount(player) if not isGuestAccount(acc) then outputChatBox('not guest') for i,phone in pairs(Phones) do if playerData[getAccountName(acc)]['phone'] == Phones[phone] then outputChatBox('found matching phone for player') for k,d in pairs(Phones[phone]) do outputChatBox('found phone table data') local size = d.size local picture = d.picture end triggerClientEvent(player,'openPhone',player,d.size,d.picture) if getElementData(player,'phone') == false then setElementData(player,'phone',true) outputChatBox('set player phone open true') else setElementData(player,'phone',false) outputChatBox('set player phone open false') end end end end end end end client.lua (phone) Spoiler layout = {} addEvent('openPhone',true) addEventHandler('openPhone',root,function(size,picture) outputChatBox('openPhone event triggered') local phoneLayout = layout['default'] local phoneImage = dxCreateTexture(picture) addEventHandler('onClientRender',root,function() outputChatBox('added rendering event') local toggle = getElementData(localPlayer,'phone') if toggle == true then outputChatBox('checking player open phone data') local sx,sy = guiGetScreenSize() local image = dxDrawImage(sx*0.8097,sy*0.3750,sx*0.1794,sy*0.5755,phoneImage,0,0,0,tocolor(255,255,255,255),false) if image then outputChatBox('image is drawn') end end end) end) server.lua (motog3b) Spoiler addEventHandler('onResourceStart',resourceRoot,function() outputChatBox('onResourceStart event triggered') if fileExists('pic/motog3b.png') then outputChatBox('found phone picture') local buffer = fileRead(fileOpen('pic/motog3b.png'),fileGetSize(fileOpen('pic/motog3b.png'))) if buffer then outputChatBox('picture data converted') triggerEvent('addPhone',root,'Moto G3 (Black)',5,buffer,'model/motog3.txd','model/motog3.dff',1575) end end end) client.lua (motog3b) Spoiler modTXD = engineLoadTXD('/model/motog3.txd') engineImportTXD(modTXD,tonumber(1575)) modDFF = engineLoadDFF('/model/motog3.dff') engineReplaceModel(modDFF,tonumber(1575)) if modTXD then outputChatBox('txd loaded') end if modDFF then outputChatBox('dff loaded') end I also found that instead of the default phone being Moto G3 (Black) that it was Moto G3 (White), which was fixed, and still did not solve this. Edited February 27, 2017 by shay103 Link to comment
ShayF2 Posted February 28, 2017 Author Share Posted February 28, 2017 Please send some help my way ! Link to comment
Captain Cody Posted February 28, 2017 Share Posted February 28, 2017 client.lua(phone) isn't getting triggered. Link to comment
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