Guest Posted September 7, 2018 Share Posted September 7, 2018 بدي عدد اللاعبين على قيد حياة يكتب رقمهم addEvent ("AlivePlayersTrigger",true) addEventHandler ("AlivePlayersTrigger",root, function () local alivePlayers = getAlivePlayers () end ) triggerServerEvent ( "AlivePlayersTrigger", localPlayer) dxDrawText("#ffffffAlive players:"..alivePlayers.." ", (483/1024)*sWidth, (15/768)*sHeight, (289/1024)*sWidth, (250/768)*sHeight, tocolor (0, 0, 0, 255), (1/1366)*sWidth,(1/768)*sHeight,"default-bold","left","top",false,false,false,true) Link to comment
KillerX Posted September 7, 2018 Share Posted September 7, 2018 (edited) Client : addEventHandler('onClientRender',root, function() dxDrawText('Players Count :'..tonumber(getElementData(resourceRoot,'Players')) or 0, 63, 231, 466, 305, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end ) Server : function Count() setElementData(resourceRoot,'Players',#getAlivePlayers()) end setTimer(Count,50,0) OR Server : setTimer(function() triggerClientEvent('GetNumber',root,#getAlivePlayers()) end,50,0) Client : addEvent('GetNumber',true) addEventHandler('GetNumber',root, function(Number2) Number = Number2 end ) addEventHandler('onClientRender',root, function() dxDrawText('Players Count :'..Number or 0, 63, 231, 466, 305, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end ) Edited September 7, 2018 by KillerX 1 1 Link to comment
iMr.WiFi..! Posted September 7, 2018 Share Posted September 7, 2018 (edited) 4 hours ago, KillerX said: Client : addEventHandler('onClientRender',root, function() dxDrawText('Players Count :'..tonumber(getElementData(resourceRoot,'Players')) or 0, 63, 231, 466, 305, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end ) Server : function Count() setElementData(resourceRoot,'Players',#getAlivePlayers()) end setTimer(Count,50,0) OR Server : setTimer(function() triggerClientEvent('GetNumber',root,#getAlivePlayers()) end,50,0) Client : addEvent('GetNumber',true) addEventHandler('GetNumber',root, function(Number2) Number = Number2 end ) addEventHandler('onClientRender',root, function() dxDrawText('Players Count :'..Number or 0, 63, 231, 466, 305, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end ) طرقك تجيب اللاق استعمل هذي الطريقة افضل : - table.filter = function(t, filterIter) local out = {} for k, v in pairs(t) do if filterIter(v, k, t) then out[k] = v end end return out end addEventHandler('onClientRender',root, function() local filter = table.filter(getElementsByType('player'), function ( player, k, v ) return not isPedDead( player ) end ) dxDrawText('Players Count :'.. #filter or 0, 63, 231, 466, 305, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end ) غير مجرب : ) Edited September 7, 2018 by iMr.WiFi..! توضيح للكود اكثر Link to comment
SycroX Posted September 7, 2018 Share Posted September 7, 2018 25 minutes ago, iMr.WiFi..! said: طرقك تجيب اللاق استعمل هذي الطريقة افضل : - table.filter = function(t, filterIter) local out = {} for k, v in pairs(t) do if filterIter(v, k, t) then out[k] = v end end return out end addEventHandler('onClientRender',root, function() local filter = table.filter(getElementsByType('player'), function ( player, k, v ) return not isPedDead( player ) end ) dxDrawText('Players Count :'.. #filter or 0, 63, 231, 466, 305, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false) end ) غير مجرب : ) بس مو طريقتك لوب لكل اللاعبين داخل رندر ؟ ما تجيب لاق ذي كمان ؟ Link to comment
iMr.WiFi..! Posted September 7, 2018 Share Posted September 7, 2018 2 minutes ago, #َxLysandeR said: بس مو طريقتك لوب لكل اللاعبين داخل رندر ؟ ما تجيب لاق ذي كمان ؟ كل واحد وطريقته انا اشوف ان لو حصر اللاق من جهة واحده افضل من جهتين - اقصد بهم الكلاينت والسيرفر - Link to comment
KillerX Posted September 7, 2018 Share Posted September 7, 2018 34 minutes ago, iMr.WiFi..! said: طرقك تجيب اللاق استعمل هذي الطريقة افضل يمكن الطريقة الاولي تجيب لاق عشان تعدد الداتا بس الثانية ما اعتقد Link to comment
SycroX Posted September 7, 2018 Share Posted September 7, 2018 12 minutes ago, iMr.WiFi..! said: كل واحد وطريقته انا اشوف ان لو حصر اللاق من جهة واحده افضل من جهتين - اقصد بهم الكلاينت والسيرفر - + 1 او ممكن يسوي طريقه اخره جت علي بالي local AlivePlayers, Events = 0, {"Wasted", "Spawn", "Quit", "Join"} function updateAlivePlayers() AlivePlayers = 0 for i,v in ipairs(getElementsByType("player")) do if not isPedDead(v) then AlivePlayers = AlivePlayers + 1 end end end for _,event in ipairs(Events) do addEventHandler("onClientPlayer"..event, root, updateAlivePlayers) end بحيث نتجنب اللوب في الريندر 2 Link to comment
coNolel Posted September 7, 2018 Share Posted September 7, 2018 7 hours ago, #َxLysandeR said: + 1 او ممكن يسوي طريقه اخره جت علي بالي local AlivePlayers, Events = 0, {"Wasted", "Spawn", "Quit", "Join"} function updateAlivePlayers() AlivePlayers = 0 for i,v in ipairs(getElementsByType("player")) do if not isPedDead(v) then AlivePlayers = AlivePlayers + 1 end end end for _,event in ipairs(Events) do addEventHandler("onClientPlayer"..event, root, updateAlivePlayers) end بحيث نتجنب اللوب في الريندر آسف على الفضول شكلي محشش ولا ممكن تقولي وش الإيفنت الجديد ذا addEventHandler("onClientPlayer"..event, root, updateAlivePlayers) Link to comment
Rockyz Posted September 7, 2018 Share Posted September 7, 2018 2 minutes ago, coNolel said: آسف على الفضول شكلي محشش ولا ممكن تقولي وش الإيفنت الجديد ذا addEventHandler("onClientPlayer"..event, root, updateAlivePlayers) لو تلاحظ اللوب و ..event 1 Link to comment
coNolel Posted September 7, 2018 Share Posted September 7, 2018 1 minute ago, #,xiRocKyz said: لو تلاحظ اللوب و ..event لا ، صدقي onClientPlayer Link to comment
KillerX Posted September 7, 2018 Share Posted September 7, 2018 4 minutes ago, coNolel said: آسف على الفضول شكلي محشش ولا ممكن تقولي وش الإيفنت الجديد ذا addEventHandler("onClientPlayer"..event, root, updateAlivePlayers) يسوي لوب علي الجدول اللي في Wasted , Spawn عشان تصير بالشكل دا يعني onClientPlayer..event = onClientPlayerWasted و باقي الجدول 2 Link to comment
SycroX Posted September 7, 2018 Share Posted September 7, 2018 21 minutes ago, coNolel said: لا ، صدقي onClientPlayer لاحظ الجدول .. لما اللوب يتنفذ هيكونو هيك onClientPlayerJoin/onClientPlayerQuit/onClientPlayerWasted/onClientPlayerSpawn 1 Link to comment
Guest Posted September 7, 2018 Share Posted September 7, 2018 أي من الأكواد ذي أفضل و ما فيه لاق؟ Link to comment
KillerX Posted September 7, 2018 Share Posted September 7, 2018 11 hours ago, #َxLysandeR said: local AlivePlayers, Events = 0, {"Wasted", "Spawn", "Quit", "Join"} function updateAlivePlayers() AlivePlayers = 0 for i,v in ipairs(getElementsByType("player")) do if not isPedDead(v) then AlivePlayers = AlivePlayers + 1 end end end for _,event in ipairs(Events) do addEventHandler("onClientPlayer"..event, root, updateAlivePlayers) end في نظري دا افضل كود Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now