Jump to content

I need help please


mint3d

Recommended Posts

Ok so I made this script but every time the script restarts the power resets can anyone help me please?

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

Whenever you are using elementData, you must know that elementData is lost whenever the vehicle is destroyed (I mean, destroyElement, not blowVehicle). So that makes dbid get lost. So whenever you do a query, you'll have the wrong dbid.

What you should do then is to find the way to make some sort of vehicles system where the IDs are stored even after the server is shut down. That will probably do.

Link to comment
Whenever you are using elementData, you must know that elementData is lost whenever the vehicle is destroyed (I mean, destroyElement, not blowVehicle).

destroyElement, onVehicleExplode ( blowVehicle also triggers the function ) and restarting the source which spawned the vehicle destroys the vehicle. So it does also destroy the elementData.

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