Jump to content

SinaAmp

Members
  • Posts

    94
  • Joined

  • Last visited

Posts posted by SinaAmp

  1. Test this:

    commands "jumpc" and "cancelj"

    function jumpKey()
    	if not isPedInVehicle(localPlayer) then return end
    	local vehicle = getPedOccupiedVehicle(localPlayer)
    	if vehicle and getVehicleController(vehicle) == localPlayer then
    		local vehType = getVehicleType(vehicle)
    		if vehType == "Plane" or vehType == "Helicopter" then return end
    		local sx, sy, sz = getElementVelocity(vehicle)
            setElementVelocity(vehicle, sx, sy, sz + 2)
    	end
    end
    addCommandHandler("jumpc",jumpKey)
    
    function cjumpKey()
    	if not isPedInVehicle(localPlayer) then return end
        local vehicle = getPedOccupiedVehicle(localPlayer)
    	if vehicle and getVehicleController(vehicle) == localPlayer then
    		local vehType = getVehicleType(vehicle)
    		if vehType == "Plane" or vehType == "Helicopter" then return end
    		local sx, sy, sz = getElementVelocity(vehicle)
            local px, py, pz = getElementPosition(vehicle)
            setElementPosition(vehicle,px,py,35.33)
        end
    end
    
    
    addCommandHandler("cancelj",cjumpKey)

     

  2. try this:

    function jumpKey()
    	if not isPedInVehicle(localPlayer) then return end
    
    	local vehicle = getPedOccupiedVehicle(localPlayer)
    	if vehicle and getVehicleController(vehicle) == localPlayer then
    		local vehType = getVehicleType(vehicle)
    		if vehType == "Plane" or vehType == "Helicopter" then return end
    		local sx, sy, sz = getElementVelocity(vehicle)
    		setElementVelocity(vehicle, sx, sy, sz + 0.33)
    	end
    end
    addCommandHandler("jumpc",jumpKey)

     

  3. edited server side:

    Spoiler
    -- calc hunger and thirst
    
    function checkHunger(playersource,PHunger)
    	local players = getElementsByType("player")
    	local queryString = dbPrepareString( db, "SELECT Hunger,Thirst FROM stats WHERE Account IN ( ")
    	queryString = queryString .. dbPrepareString( db, "?, ",  AccName)
    	queryString = queryString .. " )"
    	local handle = dbQuery( db, queryString )
    	setTimer(function()
    	if Hunger and Hunger >= 0 then
    		local row = handle[1]
            Hunger = row["Hunger"]
    		PHunger = Hunger - 1
    		outputDebugString(PHunger)
    	end
    	if PHunger <= 20 then
    		outputChatBox("You need to feed as fast as possible.", 255, 0, 0)
    	end
    	if PHunger == 0 then	
    		if not isPedDead(Player) then
    			local hp = getElementHealth(Player)
    			setElementHealth(Player, hp - 30)
    		end
    	end
    end,30000,0)
    end
    triggerClientEvent("onGetData", root,PHunger)

     

    but i got this error:

    server triggered client side event but event is not added

  4. sorry @IIYAMA i can't understand why should i use triggerClientEvent in server side when i use your library and calc hunger and thirst in server side

    i dont know how to get my processed hunger and thirst from server side

    please look at this:

    server:

    Spoiler
    function AccDatacallback(AccData, player, account, AccName)
    	local result = dbPoll( AccData, 0 )
    	if(result) then
          if(#result > 0) then
             for _,row in ipairs(result) do
                Hunger = row["Hunger"]
                Thirst = row["Thirst"]
                break
             end
          end
       end
    end
    function afterlogin (_,Acc)
        local AccName = getAccountName(Acc)
        dbQuery(AccDatacallback,{source, account, AccName},db,"SELECT Hunger,Thirst FROM stats WHERE Account=?", AccName)
    end
    addEventHandler ("onPlayerLogin",root, afterlogin)
    
    -- calc hunger and thirst
    
    function checkHunger(player, PHunger)
    	if Hunger and Hunger >= 0 then
    		PHunger = Hunger - 1
    	end
    	if PHunger <= 20 then
    		outputChatBox("You need to feed as fast as possible.", 255, 0, 0)
    	end
    	if PHunger == 0 then	
    		if not isPedDead(Player) then
    			local hp = getElementHealth(Player)
    			setElementHealth(Player, hp - 30)
    		end
    	end
    end
    setTimer(checkHunger, 30000, 0)
    
    
    
    function checkThirst(player, PThirst)
    	if Thirst and Thirst >= 0 then
    		PThirst = Thirst - 1
    	end
    	if PThirst <= 20 then
    		outputChatBox("You need to drink something as fast as possible.", 255, 0, 0)
    		playSoundFrontEnd(40)
    	end
    	if PThirst == 0 then	
    		if not isPedDead(Player) then
    			local hp = getElementHealth(Player)
    			setElementHealth(Player, hp - 30)
    		end
    	end
    end
    setTimer(checkThirst, 30000, 0)
    
    
    
    -- Data saving function
       function saveAccountData (player)
          local playerAccount = getPlayerAccount(player) 
          if(playerAccount) then
             if(isGuestAccount(playerAccount)) then return end
          end
          local AccName = getAccountName(playerAccount)
          local Hungers = PHunger
          local Thirsts = PThirst
          dbExec(db,"UPDATE stats SET Hunger=?, Thirst=? WHERE Account=?",Hungers, Thirsts, AccName)
       end
       
       addEventHandler ( 'onPlayerQuit', root, function ( )
           saveAccountData(source)
       end )

     

    client:

    Spoiler
    callserver ("checkHunger","PHunger")

     

     

  5. @IIYAMA i tryed  to do this method can you please review my code

    i commented near the lines i had problem [ -- this ]

    server:

    function AccDatacallback(AccData, player, account, AccName)
    	local result = dbPoll( AccData, 0 )
    	if(result) then
          if(#result > 0) then
             for _,row in ipairs(result) do
                local Hunger = row["Hunger"]
                local Thirst = row["Thirst"]
                break
             end
          end
       end
    end
    function afterlogin (_,Acc)
        local AccName = getAccountName(Acc)
        dbQuery(AccDatacallback,{source, account, AccName},db,"SELECT Hunger,Thirst FROM stats WHERE Account=?", AccName)
    end
    addEventHandler ("onPlayerLogin",root, afterlogin)
    
    -- function to send hunger and thirst to client for process 
    
    function sendhsdata (_, Acc, Hunger ,Thirst) -- ***this***
       local AccName = getAccountName(Acc)
       local hsdata = dbPoll(dbQuery(db,"SELECT Hunger,Thirst FROM stats WHERE Account=?", AccName), -1)
       local Hunger = hsdata["Hunger"] -- ***this***
       local Thirst = hsdata["Thirst"] -- ***this***
    end
    addEvent( "onSendData", true ) -- ***this***
    addEventHandler( "onSendData", root, sendhsdata) -- ***this***
    
    
    
    -- Data saving function
    function saveAccountData (player)
       local playerAccount = getPlayerAccount(player) 
       if(playerAccount) then
          if(isGuestAccount(playerAccount)) then return end
       end
       local AccName = getAccountName(playerAccount)
       local Hungers = triggerClientEvent(player, "onSendPData", playersource, PHunger) -- ***this***
       local Thirsts = triggerClientEvent(player, "onSendPData", playersource, PThirst) -- ***this***
       dbExec(db,"UPDATE stats SET Hunger=?, Thirst=? WHERE Account=?",Hungers, Thirsts, AccName)
    end
    
    addEventHandler ( 'onPlayerQuit', root, function ( )
        saveAccountData(source)
    end )

    client:

    function checkHunger(PHunger)
    	local Hunger = triggerServerEvent("onSendData", resourceRoot, Hunger) -- ***this***
    	if Hunger and Hunger >= 0 then
    		PHunger = Hunger - 1 -- ***this***
    	end
    	if Hunger <= 20 then
    		outputChatBox("You need to feed as fast as possible.", 255, 0, 0)
    		playSoundFrontEnd(40)
    	end
    	if Hunger == 0 then	
    		if not isPedDead(localPlayer) then
    			local hp = getElementHealth(localPlayer)
    			setElementHealth(localPlayer, hp - 30)
    		end
    	end
    end
    setTimer(checkHunger, 60000, 0)
    addEvent( "onSendPHData", true ) -- ***this***
    addEventHandler( "onSendPHData", localPlayer, checkHunger ) -- ***this***
    
    
    
    function onClientPlayerSpawn()
    	setElementData(source, "Hunger", 100)
    end
    addEventHandler("onClientPlayerSpawn", root, onClientPlayerSpawn)
    
    
    
    
    function checkThirst(PThirst) -- ***this***
    	local Thirst = triggerServerEvent("onSendData", resourceRoot, Thirst) -- ***this***
    	if Thirst and Thirst >= 0 then
    		PThirst = Thirst - 1 -- ***this***
    	end
    	if Thirst <= 20 then
    		outputChatBox("You need to drink something as fast as possible.", 255, 0, 0)
    		playSoundFrontEnd(40)
    	end
    	if Thirst == 0 then	
    		if not isPedDead(localPlayer) then
    			local hp = getElementHealth(localPlayer)
    			setElementHealth(localPlayer, hp - 30)
    		end
    	end
    end
    setTimer(checkThirst, 60000, 0)
    addEvent( "onSendPTData", true ) -- ***this***
    addEventHandler( "onSendPTData", localPlayer, checkThirst ) -- ***this***
    
    
    
    function onClientPlayerSpawn()
    	setElementData(source, "Thirst", 100)
    end
    addEventHandler("onClientPlayerSpawn", root, onClientPlayerSpawn)

     

  6. here:

    Spoiler
    function checkHunger()
    	local Hunger = tonumber(getElementData(localPlayer, "Hunger"))
    	if Hunger and Hunger >= 0 then
    		setElementData(localPlayer, "Hunger", Hunger - 1)
    	end
    	if Hunger <= 20 then
    		outputChatBox("You need to feed as fast as possible.", 255, 0, 0)
    		playSoundFrontEnd(40)
    	end
    	if Hunger == 0 then	
    		if not isPedDead(localPlayer) then
    			local hp = getElementHealth(localPlayer)
    			setElementHealth(localPlayer, hp - 30)
    		end
    	end
    end
    setTimer(checkHunger, 60000, 0)
    
    function onClientPlayerSpawn()
    	setElementData(source, "Hunger", 100)
    end
    addEventHandler("onClientPlayerSpawn", root, onClientPlayerSpawn)
    
    function checkThirst()
    	local Thirst = tonumber(getElementData(localPlayer, "Thirst"))
    	if Thirst and Thirst >= 0 then
    		setElementData(localPlayer, "Thirst", Thirst - 1)
    	end
    	if Thirst <= 20 then
    		outputChatBox("You need to drink something as fast as possible.", 255, 0, 0)
    		playSoundFrontEnd(40)
    	end
    	if Thirst == 0 then	
    		if not isPedDead(localPlayer) then
    			local hp = getElementHealth(localPlayer)
    			setElementHealth(localPlayer, hp - 30)
    		end
    	end
    end
    setTimer(checkThirst, 60000, 0)
    
    function onClientPlayerSpawn()
    	setElementData(source, "Thirst", 100)
    end
    addEventHandler("onClientPlayerSpawn", root, onClientPlayerSpawn)

     

     

  7. sorry @IIYAMA but i still got dbExec failed; (1205) Lock wait timeout exceeded; try restarting transaction

    i had 15 dbexec in my resources.  3 of them must work after player logout

    when i decrease them (dbexec's) by stop one of the resources. after that i hadn't this issue but when 3 of them work's together i got that error

    aslo i added the callback for all of my dbquerys

    maybe that's for timing issue in my hunger and thirst system

    Spoiler
    function saveAccountData (player)
          local playerAccount = getPlayerAccount(player) 
          if(playerAccount) then
             if(isGuestAccount(playerAccount)) then return end
          end
          local AccName = getAccountName(playerAccount)
      
          local Hungers = getElementData (player,"Hunger")
          local Thirsts = getElementData (player,"Thirst")
          dbExec(db,"UPDATE stats SET Hunger=?, Thirst=? WHERE Account=?",Hungers, Thirsts, AccName)
          end
          
          addEventHandler ( 'onPlayerQuit', root, function ( )
              saveAccountData(source)
          end )

     

    i think in this code dbexec doesn't get data from Hungers and thirsts variables

  8. i solved the problem with using callback for must of them but some of them when i use callback get attempt to call global ' ' nil value

    like this code:

    Spoiler
    function getpaccount (_,account)
    	local AccName = getAccountName(account)
    	local Setpname = setPlayerName(source,tostring(AccName))
    	local AccData = dbQuery(AccDatacallback(), db,"SELECT * FROM stats WHERE Account=? LIMIT 1", AccName)
    	function AccDatacallback(AccData)
    		local result = dbPoll( AccData, 0 )
    	end
    	if(AccData) then 
           if(#AccData > 0) then return end
    	end
    	local ID = getFreeID()
    	local SetData = dbExec(db,"INSERT INTO stats (ID,Account) VALUES (?, ?)",ID, AccName)
    end
    addEventHandler("onPlayerLogin",root, getpaccount)

     

     

    • Like 1
×
×
  • Create New...