Jump to content

[HELP] DERBY STATS


Recommended Posts

Hi guys, im making a derby server, I need help with storing info to the user's account, some of the information i need to store is, the player's rank from all the players in the server based on points(which also needs to be stored) and the players chosen skin, and car colour/headlight color. Help Please and thank you

Link to comment
  
playerAccount = getPlayerAccount ( source ) 
playerVehicle = getPlayerOccupiedVehicle ( playerSource ) 
function saveColours () 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
            local color1, color2, color3, color4 = getVehicleColor ( playerVehicle ) 
            local r, g, b = getVehicleHeadLightColor ( playerVehicle ) 
            setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
            setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
            setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
            setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
            setAccountData ( playerAccount, "idd.cchcr", r) 
            setAccountData ( playerAccount, "idd.cchcg", g) 
            setAccountData ( playerAccount, "idd.cchcb", b) 
    end 
end 
addCommandHandler("saveColours", getRootElement(), setColours) 
  
function setCarColours() 
    local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
    local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
    local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
    local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
    local r = getAccountData ( playerAccount, "idd.cchcr" ) 
    local g = getAccountData ( playerAccount, "idd.cchcg" ) 
    local b = getAccountData ( playerAccount, "idd.cchcb" ) 
    setVehicleColor ( playerVehicle, color1, color2, color3, color4 ) 
    getVehicleHeadLightColor ( playerVehicle, r,g,b) 
end 
addEventHandler("",getRootElement(),setCarColours) 
  

This should work right? but what handler do i use for the colours, when a car is spawned, i am using the resource race.

Link to comment
function saveColours ( playerSource ) 
    local playerAccount = getPlayerAccount ( playerSource ) 
    local playerVehicle = getPlayerOccupiedVehicle ( playerSource ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local color1, color2, color3, color4 = getVehicleColor ( playerVehicle ) 
        local r, g, b = getVehicleHeadLightColor ( playerVehicle ) 
        setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
        setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
        setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
        setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
        setAccountData ( playerAccount, "idd.cchcr", r) 
        setAccountData ( playerAccount, "idd.cchcg", g) 
        setAccountData ( playerAccount, "idd.cchcb", b) 
    end 
end 
addCommandHandler("saveColours", saveColours) 
  
function setCarColours(_, playerAccount) 
    local playerVehicle = getPlayerOccupiedVehicle ( source ) 
    local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
    local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
    local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
    local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
    local r = getAccountData ( playerAccount, "idd.cchcr" ) 
    local g = getAccountData ( playerAccount, "idd.cchcg" ) 
    local b = getAccountData ( playerAccount, "idd.cchcb" ) 
    setVehicleColor ( playerVehicle, color1, color2, color3, color4 ) 
    getVehicleHeadLightColor ( playerVehicle, r,g,b) 
end 
addEventHandler("onPlayerLogin",getRootElement(),setCarColours) 

Link to comment
Yeah, that's correct. If you want your addon to start with race then you have to change race meta.xml. In the settings section you will find addons that start with race.

If i understand you correctly, this is what i am suppoesed to do right? but i get this message in the console:

"WARNING: [gamemodes]\[race]\[addons]\gr_stats\server.lua:32: Bad arguement @ 'addEventHandler' [Expected at argument 2, got function]"

Here is my meta...

<meta> 
<info name="IDD Stats" addon="race" /> 
<script src="server.lua" type="server" /> 
</meta> 

Here is my code...

addEvent ( "onMapStarting" ) 
function saveColours ( playerSource ) 
    local playerAccount = getPlayerAccount ( playerSource ) 
    local playerVehicle = getPlayerOccupiedVehicle ( playerSource ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local color1, color2, color3, color4 = getVehicleColor ( playerVehicle ) 
        local r, g, b = getVehicleHeadLightColor ( playerVehicle ) 
        setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
        setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
        setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
        setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
        setAccountData ( playerAccount, "idd.cchcr", r) 
        setAccountData ( playerAccount, "idd.cchcg", g) 
        setAccountData ( playerAccount, "idd.cchcb", b) 
        outputChatBox ( "Your Chosen Colours have Been Saved!", source) 
    end 
end 
addCommandHandler("saveColours", saveColours) 
  
function setCarColours(_, playerAccount) 
    local playerVehicle = getPlayerOccupiedVehicle ( source ) 
    local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
    local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
    local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
    local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
    local r = getAccountData ( playerAccount, "idd.cchcr" ) 
    local g = getAccountData ( playerAccount, "idd.cchcg" ) 
    local b = getAccountData ( playerAccount, "idd.cchcb" ) 
    setVehicleColor ( playerVehicle, color1, color2, color3, color4 ) 
    getVehicleHeadLightColor ( playerVehicle, r,g,b) 
end 
addEventHandler ( "onMapStarting" ,setCarColours ) 

Link to comment
addEvent ( "onMapStarting" ) 
function saveColours ( playerSource ) 
    local playerAccount = getPlayerAccount ( playerSource ) 
    local playerVehicle = getPlayerOccupiedVehicle ( playerSource ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local color1, color2, color3, color4 = getVehicleColor ( playerVehicle ) 
        local r, g, b = getVehicleHeadLightColor ( playerVehicle ) 
        setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
        setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
        setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
        setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
        setAccountData ( playerAccount, "idd.cchcr", r) 
        setAccountData ( playerAccount, "idd.cchcg", g) 
        setAccountData ( playerAccount, "idd.cchcb", b) 
        outputChatBox ( "Your Chosen Colours have Been Saved!", source) 
    end 
end 
addCommandHandler("saveColours", saveColours) 
  
function setCarColours(_, playerAccount) 
    local playerVehicle = getPlayerOccupiedVehicle ( source ) 
    local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
    local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
    local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
    local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
    local r = getAccountData ( playerAccount, "idd.cchcr" ) 
    local g = getAccountData ( playerAccount, "idd.cchcg" ) 
    local b = getAccountData ( playerAccount, "idd.cchcb" ) 
    setVehicleColor ( playerVehicle, color1, color2, color3, color4 ) 
    getVehicleHeadLightColor ( playerVehicle, r,g,b) 
end 
addEventHandler ( "onMapStarting", getRootElement(),setCarColours ) -- For EVERY Event in server you need to have root here. 

Link to comment
addEvent ( "onMapStarting" ) 
function saveColours ( playerSource ) 
    local playerAccount = getPlayerAccount ( playerSource ) 
    local playerVehicle = getPlayerOccupiedVehicle ( playerSource ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local color1, color2, color3, color4 = getVehicleColor ( playerVehicle ) 
        local r, g, b = getVehicleHeadLightColor ( playerVehicle ) 
        setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
        setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
        setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
        setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
        setAccountData ( playerAccount, "idd.cchcr", r) 
        setAccountData ( playerAccount, "idd.cchcg", g) 
        setAccountData ( playerAccount, "idd.cchcb", b) 
        outputChatBox ( "Your Chosen Colours have Been Saved!", source) 
    end 
end 
addCommandHandler("saveColours", saveColours) 
  
function setCarColours(_, playerAccount) 
    local playerVehicle = getPlayerOccupiedVehicle ( source ) 
    local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
    local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
    local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
    local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
    local r = getAccountData ( playerAccount, "idd.cchcr" ) 
    local g = getAccountData ( playerAccount, "idd.cchcg" ) 
    local b = getAccountData ( playerAccount, "idd.cchcb" ) 
    setVehicleColor ( playerVehicle, color1, color2, color3, color4 ) 
    getVehicleHeadLightColor ( playerVehicle, r,g,b) 
end 
addEventHandler ( "onMapStarting", getRootElement(),setCarColours ) -- For EVERY Event in server you need to have root here. 

Thank you blazy, that worked, but i need this last bit of info, i get a warning saying that getPedOccupidVehicle on line 2 is not a valid arg, why??

here is the code\

  
addEvent ( "onMapStarting" )     
theVehicle = getPedOccupiedVehicle ( source ) 
function setLightColours ( source, commandName, r, g, b ) 
    local playerAccount = getPlayerAccount ( source ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        setAccountData ( playerAccount, "idd.cchcr", r) 
        setAccountData ( playerAccount, "idd.cchcg", g) 
        setAccountData ( playerAccount, "idd.cchcb", b) 
        setVehicleHeadLightColor ( theVehicle, r,g,b) 
        setVehicleOverrideLights ( theVehicle, 2 ) 
        outputChatBox ( "Your Chosen Light Colours have Been Saved!", source) 
    end 
end 
addCommandHandler("setLightColours", setLightColours) 
  
function setCarColours () 
    local playerAccount = getPlayerAccount ( source ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local color1, color2, color3, color4 = getVehicleColor ( theVehicle ) 
        setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
        setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
        setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
        setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
        local crdone = outputChatBox ( "Your Current Car Colours have Been Saved!", source) 
    end 
end 
addCommandHandler("setCarColours", setCarColours) 
  
function setAllColours(_, playerAccount) 
    outputChatBox ("Broken!",source) 
    local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
    local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
    local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
    local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
    local r = getAccountData ( playerAccount, "idd.cchcr" ) 
    local g = getAccountData ( playerAccount, "idd.cchcg" ) 
    local b = getAccountData ( playerAccount, "idd.cchcb" ) 
    local cr = tonumber ( r ) 
    local cg = tonumber ( g ) 
    local cb = tonumber ( b ) 
    setVehicleColor ( theVehicle, color1, color2, color3, color4 ) 
    setVehicleHeadLightColor ( theVehicle, cr,cg,cb) 
end 
addCommandHandler ( "restoreColours", setAllColours) 
addEventHandler ( "onMapStarting", getRootElement(),setAllColours ) 
  

Link to comment
addEvent ( "onMapStarting" ) 
function setLightColours ( source, commandName, r, g, b ) 
theVehicle = getPedOccupiedVehicle ( source ) 
if theVehicle then 
local playerAccount = getPlayerAccount ( source ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        setAccountData ( playerAccount, "idd.cchcr", r) 
        setAccountData ( playerAccount, "idd.cchcg", g) 
        setAccountData ( playerAccount, "idd.cchcb", b) 
        setVehicleHeadLightColor ( theVehicle, r,g,b) 
        setVehicleOverrideLights ( theVehicle, 2 ) 
        outputChatBox ( "Your Chosen Light Colours have Been Saved!", source) 
    else 
        outputChatBox ( "You are not logged in!", source) 
    end 
else 
      outputChatBox ( "You do not have a Vehicle!", source) 
end 
end 
addCommandHandler("setLightColours", setLightColours) 
  
function setCarColours () 
theVehicle = getPedOccupiedVehicle ( source ) 
if theVehicle then 
local playerAccount = getPlayerAccount ( source ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local color1, color2, color3, color4 = getVehicleColor ( theVehicle ) 
        setAccountData ( playerAccount, "idd.ccolor1", colour1 ) 
        setAccountData ( playerAccount, "idd.ccolor2", colour2 ) 
        setAccountData ( playerAccount, "idd.ccolor3", colour3 ) 
        setAccountData ( playerAccount, "idd.ccolor4", colour4 ) 
        local crdone = outputChatBox ( "Your Current Car Colours have Been Saved!", source) 
    else 
        outputChatBox ( "You are not logged in!", source) 
    end 
else 
      outputChatBox ( "You do not have a Vehicle!", source) 
end 
end 
addCommandHandler("setCarColours", setCarColours) 
  
function setAllColours(_, playerAccount) 
theVehicle = getPedOccupiedVehicle ( source ) 
    if theVehicle then 
    local playerAccount = getPlayerAccount ( source ) 
        if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        outputChatBox ("Broken!",source) 
        local color1 = getAccountData ( playerAccount, "idd.ccolor1") 
        local color2 = getAccountData ( playerAccount, "idd.ccolor2") 
        local color3 = getAccountData ( playerAccount, "idd.ccolor3") 
        local color4 = getAccountData ( playerAccount, "idd.ccolor4") 
        local r = getAccountData ( playerAccount, "idd.cchcr" ) 
        local g = getAccountData ( playerAccount, "idd.cchcg" ) 
        local b = getAccountData ( playerAccount, "idd.cchcb" ) 
        local cr = tonumber ( r ) 
        local cg = tonumber ( g ) 
        local cb = tonumber ( b ) 
        setVehicleColor ( theVehicle, color1, color2, color3, color4 ) 
        setVehicleHeadLightColor ( theVehicle, cr,cg,cb) 
        else 
        outputChatBox ( "You are not logged in!", source) 
        end 
    else 
        outputChatBox ( "You do not have a Vehicle!", source) 
    end 
end 
addCommandHandler ( "restoreColours", setAllColours) 
addEventHandler ( "onMapStarting", getRootElement(),setAllColours ) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...