Klesh Posted January 6, 2012 Share Posted January 6, 2012 I was do this code, and is a buy command, the thing is dont set the vehicle color, it saves too. function colorHandler ( thePlayer, commandName, col1, col2, col3 ) if (playerVehicle) then playerVehicle = getPedOccupiedVehicle(thePlayer) account = getPlayerAccount(thePlayer) setAccountData("color.data", account) exCol1, exCol2, exCol3 = getVehicleColor(thePlayer) if not col1 then col1 = exCol1 end if not col2 then col2 = exCol2 end if not col3 then col3 = exCol3 end setVehicleColor(playerVehicle , col1, col2, col3) else outputChatBox("[Error]: You use /bc [color1 color2 color3]", thePlayer, 255,0 ,0, true) outputChatBox("You can use 3 colors with /bc command", thePlayer, 255, 0, 0, true) outputChatBox("[Error]: This command only works when the player is in the vehicle.", thePlayer, 255, 0, 0, true) end if (isPedInVehicle(thePlayer)) then if (getPlayerMoney(thePlayer) ~= 10000) takePlayerMoney(thePlayer, 10000) playSoundFrontEnd(thePlayer, 46) outputChatBox("#2E9AFE[shop]: #FFFFFF" ..getPlayerName(thePlayer).. "#2E9AFE has bought vehicle colors. (/bc)", root, 255, 255, 255, true) else outputChatBox("[Error]: You don't have enought money to buy.", thePlayer, 255, 0, 0, true) end else outputChatBox("[Error]: This command only works when the player is in the vehicle", thePlayer, 255, 0, 0, true) end end ) addCommnandHandler("bc", colorHandler) Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 That's just a TOTAL MESS. function colorHandler ( thePlayer, commandName, r, g, b ) if (not isPedInVehicle(thePlayer)) then outputChatBox("[Error]: This command only works when you're in a vehicle", thePlayer, 255, 0, 0, true) return end if (tonumber(r) and tonumber(g) and tonumber(b)) then local playerVehicle = getPedOccupiedVehicle(thePlayer) local account = getPlayerAccount(thePlayer) if (getPlayerMoney(thePlayer) >= 10000) then takePlayerMoney(thePlayer, 10000) playSoundFrontEnd(thePlayer, 46) setVehicleColor(playerVehicle, tonumber(r), tonumber(g), tonumber(b)) setAccountData(account, "color.data", toJSON({r, g, b})) outputChatBox("#2E9AFE[shop]: #FFFFFF" ..getPlayerName(thePlayer).. "#2E9AFE has bought vehicle colors. (/bc)", root, 255, 255, 255, true) else outputChatBox("[Error]: You don't have enough money.", thePlayer, 255, 0, 0, true) end else outputChatBox("[Error]: Syntax: /bc [r g b]", thePlayer, 255,0 ,0, true) end end addCommandHandler("bc", colorHandler) See if it works (not tested). Link to comment
Klesh Posted January 6, 2012 Author Share Posted January 6, 2012 Being no working, dont take money and dont setcolor. Error "expecteted near takeplayermoney". Link to comment
Klesh Posted January 6, 2012 Author Share Posted January 6, 2012 Error "Bad "vehicle" pointer @ getVehicleColor1()" The command executes good but the color doesnt set, badArgument setVehicleColor. Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 Copy the script again, now it works. Link to comment
Klesh Posted January 6, 2012 Author Share Posted January 6, 2012 Alredy fixed, you missed something, you set setVehicleColor(thePlayer, true), i changed to setVehicleColor(playerVehicle) but thanks. Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 What are you talking about? My script is correct: setVehicleColor(playerVehicle, tonumber®, tonumber(g), tonumber(b)) Do you see a "thePlayer" or "true" there? I really don't. Link to comment
Klesh Posted January 6, 2012 Author Share Posted January 6, 2012 See old code, this one: local r, g, b = getVehicleColor(playerVehicle) and you put local r, g, b = getVehicleColor(thePlayer, true) Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 No, actually you put that and I forgot to remove it . Check your first script. Link to comment
Klesh Posted January 6, 2012 Author Share Posted January 6, 2012 Whell i see that little code and i fixed, but do you see it too, thanks. Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 Now im trying to save that data, making a server-side with this: function onPlayerLogin ( _, thePlayer, account ) local account = getPlayerAccount(thePlayer) local pColor = getAccountData(account, "color.data") if (pColor) then local color = getAccountData("color.data") local r, g, b = unpack(fromJSON(color)) triggerClientEvent(thePlayer,"colorv", thePlayer, "",r,g,b) end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) addEventHandler("onPlayerWasted", getRootElement(), onPlayerLogin) addEvent("colorv", true) added in the other script, is the same of up of the topic. The question, what event handler i can add to get the color when the map is changing? and when the vehicle take the pickup vehicle change. Thanks for any help. Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 The player element of the wasted player triggered by "onPlayerWasted" is 'source'. Use: "onPlayerPickUpRacePickup" -> Check if the pickup type is "vehiclechange". And "onVehicleEnter" for when the map starts. Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 (edited) I was try with that : function onPlayerLogin ( _, thePlayer, account, r, g, b ) local account = getPlayerAccount(thePlayer) local pColor = getAccountData(account, "color.data") if (pColor) then local color = getAccountData("color.data") local r, g, b = unpack(fromJSON(color)) triggerClientEvent(thePlayer,"colorv", thePlayer, "",r,g,b) if (color) then local playerVehicle = (getPedOccupiedVehicle(thePlayer) setVehicleColor(playerVehicle, tonumber(r), tonumber(g), tonumber(b), color) end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) addEventHandler("onPlayerWasted", thePlayer, onPlayerLogin) addEventHandler("onPlayerPickUpRacePickUp", getRootElement, onPlayerLogin) addEventHandler("onVehicleEnter", thePlayer, onPlayerLogin) When player pickups a vehiclechange, the color purchased on bc command is not saving, or when playerjoins, what code is wrong. Edited January 7, 2012 by Guest Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 Everything there is wrong -__-, you can't just expect that every event handler will fit your needs. Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 What will be correct there then? Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 Try this: function loadVehicleColor ( thePlayer ) local account = getPlayerAccount(thePlayer) local pColor = getAccountData(account, "color.data") if (pColor) then local r, g, b = unpack(fromJSON(pColor)) triggerClientEvent(thePlayer,"colorv", thePlayer, "",r,g,b) local playerVehicle = getPedOccupiedVehicle(thePlayer) if (playerVehicle) then setVehicleColor(playerVehicle, tonumber(r), tonumber(g), tonumber(b)) end end end addEventHandler("onPlayerLogin", getRootElement(), function () loadVehicleColor(source) end) addEventHandler("onPlayerWasted", getRootElement(), function () loadVehicleColor(source) end) addEventHandler("onPlayerPickUpRacePickUp", getRootElement(), function (pickupID, pickupType, vehicleModel) if (pickupType == "vehiclechange") then loadVehicleColor(source) end end) addEventHandler("onVehicleEnter", getRootElement(), function (thePlayer) loadVehicleColor(thePlayer) end) Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 (edited) Color saves only when starts another map, but not when player takes a pickup. Now i see only was fixed: local r, g, b = unpack(fromJSON(color)) to local r, g, b = unpack(fromJSON(pcolor)) and addEventHandler("onVehicleEnter", getRootElement(), function (thePlayer) loadVehicleColor(thePlayer) end) Edited January 7, 2012 by Guest Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 The script doesn't save the color, it'll load it. P.S: Is not the only thing I changed, are you blind? Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 Yes i know, i'm not blind what i mean is the color no load when the vehicle change, only that. PS: Thanks a lot for help me in this script. Im Just learning lua, you have wiki on your head. Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 No errors on debug? P.S: It loads the color when a map starts but not when you change the vehicle? Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 I was put the file to client, where is the bc command and the event, but in debugscript 3 shows bad argument, isPedInVehicle. Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 That script is SERVER SIDE, not client side. Link to comment
Klesh Posted January 7, 2012 Author Share Posted January 7, 2012 (edited) Ok, changed, then debug says colorv must be in client, then i put this on client. addEvent("colorv", true) addEventHandler("colorv", root, colorHandler) the same thing, ispedinvehicle bad argument. Edited January 7, 2012 by Guest Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 Post your complete script, client side and server side. 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