Jump to content

I need help


mint3d

Recommended Posts

Ok so I made this script but every time I restart it it doesn't load from the mysql I need help to make it load its all server sided

mysql = exports.mysql 
  
function powerChange ( thePlayer, command, power ) 
    if exports.global:isPlayerLeadAdmin(thePlayer) then 
         
    power = tonumber ( power ) 
    local veh = getPedOccupiedVehicle ( thePlayer ) 
     
    if power and veh then 
        local success = setVehicleHandling ( veh, "engineAcceleration", power ) 
        if success then 
            outputChatBox ( "Your vehicle's acceleration has been changed to: "..power.." ", thePlayer, 0, 255, 0 ) 
            local dbid = getElementData(veh, "dbid") 
            mysql:query_free("UPDATE vehicles SET power="..power.." WHERE id="..dbid) 
            exports.logs:dbLog(thePlayer, 40, veh, "SETPOWER: "..power.."") 
        else  
            outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
        end 
    elseif not veh then  
        outputChatBox ( "You're not in a vehicle.", thePlayer, 255, 0, 0 )  
    elseif not power then  
        outputChatBox ( "Syntax: /setpower [1 - 100000]", thePlayer, 255, 0, 0 )  
        end 
    end 
end 
addCommandHandler ( "setpower", powerChange ) 

Link to comment
mysql = exports.mysql 
  
function loadpower ( thePlayer, power ) 
    if exports.global:isPlayerLeadAdmin(thePlayer) then 
        
    power = tonumber ( power ) 
    local veh = getPedOccupiedVehicle ( thePlayer ) 
    
    if power and veh then 
        local success = setVehicleHandling ( veh, "engineAcceleration", power ) 
        if success then 
            local dbid = getElementData(veh, "dbid") 
            mysql:query_free("SELECT vehicles  power="..power.." WHERE id="..dbid) 
            exports.logs:dbLog(thePlayer, 40, veh, "SELECTPOWER: "..power.."") 
        else 
            outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
        end 
  
addEventHandler ( "onResourceStart", getRootElement(), loadpower ) 

Is this right?

Link to comment
  • Moderators
mysql = exports.mysql 
  
function loadpower ( thePlayer, power ) 
    if exports.global:isPlayerLeadAdmin(thePlayer) then 
        
    power = tonumber ( power ) 
    local veh = getPedOccupiedVehicle ( thePlayer ) 
    
    if power and veh then 
        local success = setVehicleHandling ( veh, "engineAcceleration", power ) 
        if success then 
            local dbid = getElementData(veh, "dbid") 
            mysql:query_free("SELECT vehicles  power="..power.." WHERE id="..dbid) 
            exports.logs:dbLog(thePlayer, 40, veh, "SELECTPOWER: "..power.."") 
        else 
            outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
        end 
  
addEventHandler ( "onResourceStart", getRootElement(), loadpower ) 

Is this right?

No. You have to get the data from the database (using the a query) and store the result in power (so remove it from your function arguments and the query should executed before the setVehicleHandling

You also have to add the argument veh to know which vehicle you want to load the power of.

local vehID = getElementID(veh) 
local power = mysql:query_free("SELECT power INTO vehicles WHERE id="..vehID) 

So you shall not call this function with the onResourceStart event but right after the vehicle has been created (in the function that loads all vehicles from the database).

Link to comment

Like this?

mysql = exports.mysql 
  
function loadpower ( thePlayer, power ) 
    if exports.global:isPlayerLeadAdmin(thePlayer) then 
local vehID = getElementID(veh) 
local power = mysql:query_free("SELECT power INTO vehicles WHERE id="..vehID)      
   
    power = tonumber ( power ) 
    local veh = getPedOccupiedVehicle ( thePlayer ) 
    
    if power and veh then 
        local success = setVehicleHandling ( veh, "engineAcceleration", power ) 
        if success then 
            exports.logs:dbLog(thePlayer, 40, veh, "SELECTPOWER: "..power.."") 
        else 
            outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
        end 
  
addEventHandler ( "onResourceStart", getRootElement(), loadpower ) 

Link to comment
mysql = exports.mysql 
  
function loadpower ( thePlayer ) 
    if exports.global:isPlayerLeadAdmin(thePlayer) then 
        local veh = getPedOccupiedVehicle ( thePlayer ) 
        local vehID = getElementData(veh, "dbid") 
        local power = mysql:query_free("SELECT `power` FROM vehicles WHERE id="..vehID)     
  
        power = tonumber ( power ) 
        
    
        if power and veh then 
            local success = setVehicleHandling ( veh, "engineAcceleration", power ) 
            if success then 
                 exports.logs:dbLog(thePlayer, 40, veh, "SELECTPOWER: "..power.."") 
            else 
                outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
            end 
        else 
             outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
        end 
    end 
end 
  
addCommandHandler( "test", loadpower ) -- If you use 'onResourceStart' then load and set the handlings for every vehicle with a loop 

Link to comment

I am bad at mysql but you would need to remove locals I think

mysql = exports.mysql 
  
function loadpower ( thePlayer ) 
    if exports.global:isPlayerLeadAdmin(thePlayer) then 
        veh = getPedOccupiedVehicle ( thePlayer ) 
        vehID = getElementData(veh, "dbid") 
        local power = mysql:query_free("SELECT `power` FROM vehicles WHERE id="..vehID)     
  
        power = tonumber ( power ) 
        
    
        if power and veh then 
            success = setVehicleHandling ( veh, "engineAcceleration", power ) 
            if success then 
                 exports.logs:dbLog(thePlayer, 40, veh, "SELECTPOWER: "..power.."") 
            else 
                outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
            end 
        else 
             outputChatBox ( "Setting power failed.", thePlayer, 255, 0, 0 ) 
        end 
    end 
end 
 addEventHandler ( "onResourceStart", getRootElement(), loadpower ) 
  

Link to comment
  • Moderators

I'm agree with pa3ck. the local keyword has nothing to do with mysql nor MTA. It's from the Lua language (Lua ~= MTA).

By the way, we need the code that loads the vehicles from database. This is where you have to get and set the power of the vehicle or call the loadPower(veh)

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...