-
Posts
94 -
Joined
-
Last visited
Posts posted by SinaAmp
-
-
hello guys
i want to use this library but when i use fore example this:
dbify.mysql.table.isValid(tableName, callback(result, arguments) print(tostring(result)) print(toJSON(arguments)) end, ...)
i got expected ) error
-
How i can get the player account name in custom event?
everything i try i got nil errors
-
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)
-
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)
-
im little bit confused
to be honest this is out of my lua abilitys
i need somone to complete this so i can learn the way
-
sorry i wasted your time @IIYAMAthank you for help
addEventHandler("onPlayerResourceStart", root, function(hungerandthirst) if loadedResource == resource then triggerClientEvent(source, "onGetData", resourceRoot,PHunger) end end)
@Burak5312 bro can you complete this part?
- 1
-
what i will do now to solve this problem?
-
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
-
i got this error repeatly
Database result uncollected after 5 minutes. [Query: SELECT Hunger,Thirst FROM stats WHERE Account IN ( NULL, )]
-
why i need to get hunger and thirst in 'checkhunger' function when i got them from 'afterlogin' function?
-
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:
Spoilerfunction 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:
Spoilercallserver ("checkHunger","PHunger")
-
thank you @IIYAMA
- 1
-
@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)
-
@IIYAMA sorry for late response
i think my way of creating hunger and thirst system with get/setelementdata is complatly wrong
and that cause of performance issues in future
may i use only triggerevents and a variable to process
- 1
-
here:
Spoilerfunction 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)
-
sorry *dynamic
-
Thank you @IIYAMA
I get element data from client side which is static for setting up timer
Isn't that cause of the problem?
-
i got my hunger and thirst number
-
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
Spoilerfunction 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
-
thank you guys problem solved
- 1
-
For this line:
if AccData and #AccData > 0 then return end
i got this error:
attempt to get length of local 'AccData' (a userdata value)
-
nothing changed still got that error
my issue is server freeze but i cant understand whats going on in dbpool
-
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:
Spoilerfunction 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)
- 1
-
oh i found whats wrong
i had too many update requests after onplayerquit in another resources
after i stoped another resources with db update in their code my problem was solved
but i need to use db update in my another resources
thank you bro
maybe @IIYAMA can help
[Help] problem to use a library
in Scripting
Posted
sorry guys problem solved