Klesh Posted January 5, 2012 Posted January 5, 2012 Hi i try to add some code line to the script shader_nitro to save it when player quit and back nitro when player joins, so this is the whole code: root = getRootElement() addEventHandler("onClientResourceStart",resourceRoot, function() nitroShader = dxCreateShader("nitro.fx") end) -- This function will set the new color of the nitro function updateNitroColor(r,g,b) if nitroShader then if r and g and b then engineApplyShaderToWorldTexture (nitroShader,"smoke") dxSetShaderValue (nitroShader, "gNitroColor", r/255, g/255, b/255 ) end end end -- This function will reset the nitro back to the original function resetNitroColor() if nitroShader then engineRemoveShaderFromWorldTexture(nitroShader,"smoke") end end -- Example command use addCommandHandler("nitro", function nitroPursache(command,r,g,b) if r and g and b then local r,g,b = tonumber(r),tonumber(g),tonumber(b) if r <= 255 and g <= 255 and b <= 255 then updateNitroColor(r,g,b) outputChatBox("Nitro color updated!",255,255,255,true) else outputChatBox("Colors must be between 0 and 255",255,255,255,true) end else resetNitroColor() outputChatBox("Nitro color reset to original!",255,255,255,true) end end) function onPlayerQuit (playerSource) local acc = getPlayerAccount(source) local playerVehicle = getOccupiedVehicle(playerSource) if acc then getPlayerAccount(nitroPursache) setAccountData(acc, "nitro.data", gNitroColor(playerVehicle)) end end addEventHandler("onPlayerQuit", root, onPlayerQuit) function onPlayerLogin () if acc then pNitro = getAccountData(acc, "nitro.data") if pNitro then setgNitroColor( source, gNitroColor ( pNitro ) ) end end end addEventHandler("onPlayerLogin", root, onPlayerJoin) Doesn't save, i dont know how to call nitrocolor function.
Castillo Posted January 5, 2012 Posted January 5, 2012 You're messing client side with server side. I would use client side XML to save the color, but well, if you want it account data based, here it is: -- client side: addEventHandler("onClientResourceStart",resourceRoot, function() nitroShader = dxCreateShader("nitro.fx") end) -- This function will set the new color of the nitro function updateNitroColor(r,g,b) if nitroShader then if r and g and b then engineApplyShaderToWorldTexture (nitroShader,"smoke") dxSetShaderValue (nitroShader, "gNitroColor", r/255, g/255, b/255 ) end end end -- This function will reset the nitro back to the original function resetNitroColor() if nitroShader then engineRemoveShaderFromWorldTexture(nitroShader,"smoke") end end function setNitroColor(command,r,g,b) if (r and g and b) then local r,g,b = tonumber(r),tonumber(g),tonumber(b) if (r <= 255 and g <= 255 and b <= 255) then updateNitroColor(r,g,b) setElementData(localPlayer,"nitroColor",{r, g, b}) outputChatBox("Nitro color updated!",255,255,255,true) else outputChatBox("Colors must be between 0 and 255",255,255,255,true) end else resetNitroColor() outputChatBox("Nitro color reset to original!",255,255,255,true) end end addCommandHandler("nitro",setNitroColor) addEvent("setNitroColor",true) addEventHandler("setNitroColor",root,setNitroColor) -- server side: function onPlayerQuit (playerSource) local acc = getPlayerAccount(playerSource) local playerVehicle = getOccupiedVehicle(playerSource) if (not isGuestAccount(acc) and playerVehicle) then local nitroColor = getElementData(playerSource, "nitroColor") if (nitroColor) then setAccountData(acc, "nitro.data", toJSON({unpack(nitroColor)})) end end end addEventHandler("onPlayerQuit", root, onPlayerQuit) function onPlayerLogin (_,acc) local pNitro = getAccountData(acc, "nitro.data") if (pNitro) then local color = getAccountData(acc,"nitro.data") local r, g, b = unpack(fromJSON(color)) triggerClientEvent(source,"setNitroColor",source,"",r,g,b) end end addEventHandler("onPlayerLogin", root, onPlayerLogin)
Klesh Posted January 5, 2012 Author Posted January 5, 2012 I didn't understand the toJSON event, how to use and when, can explain because wiki say's something about cats Thanks, i forgot that's a server-side, and setcolorNitro, thanks for that.
Castillo Posted January 5, 2012 Posted January 5, 2012 The wiki explains all what you need to know about it. P.S: The script should work without any change.
Klesh Posted January 5, 2012 Author Posted January 5, 2012 Ok, i see on wiki and i read more, i understand that stores data between scripts, you use unpack to extract them on server side, thanks.
Castillo Posted January 5, 2012 Posted January 5, 2012 You can't store a Lua-table into account data or (My)SQL, but you can store a JSON string which works pretty much like a table.
Klesh Posted January 5, 2012 Author Posted January 5, 2012 That's mean you can store data as db or SQLite, with JSON, that good to know, never seen before.(Tables) Edit: The script doesn't save the nitro.
Castillo Posted January 5, 2012 Posted January 5, 2012 Any errors on debug script? also, are you driving a vehicle?
Castillo Posted January 5, 2012 Posted January 5, 2012 Ok, I fixed the first error, but the second doesn't match the line in the script I gave you. P.S: Copy the server-side script again.
Klesh Posted January 5, 2012 Author Posted January 5, 2012 Same error on commandHandler, i was copy again.
Kenix Posted January 5, 2012 Posted January 5, 2012 Try: Server: function onPlayerQuit ( ) local acc = getPlayerAccount(soruce) local playerVehicle = getPedOccupiedVehicle(soruce) if (not isGuestAccount(acc) and playerVehicle) then local nitroColor = getElementData(soruce, "nitroColor") if (nitroColor) then setAccountData(acc, "nitro.data", toJSON( { unpack( nitroColor ) } ) ) end end end addEventHandler( "onPlayerQuit", root, onPlayerQuit ) function onPlayerLogin (_,acc) local pNitro = getAccountData(acc, "nitro.data") if pNitro then local r, g, b = unpack( fromJSON( pNitro ) ) triggerClientEvent( source,"setNitroColor",source,"",r,g,b ) end end addEventHandler( "onPlayerLogin", root, onPlayerLogin )
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