VenomOG Posted August 8, 2018 Share Posted August 8, 2018 addEvent("revieve",true) addEventHandler("revieve",root, function () local data = getElementData (source,"selected") if (data == true ) then ---------------and getElementData(source,"KArr") x,y,z = getElementPosition(source) Team = getPlayerTeam ( source ) spawnPlayer (source, x, y, z) spawnPlayer (source, x, y,z, 0,0, 0, 0,Team) setElementHealth (source, 100) setPedAnimation(source,false) setElementData (source,"rev",false) end end ) Okey so server side finished i want in client if player is doing sleeping animation and click it starts progress bar when finish cancel animation and set player health 100 Link to comment
Addlibs Posted August 8, 2018 Share Posted August 8, 2018 How about you attempt it on your own and come back if you encounter any problems? We're not here to script for you. Link to comment
knightscript Posted August 10, 2018 Share Posted August 10, 2018 I mean, there was no need to humilliate him, you could of told him more or less what functions to use, here, tested it, CLIENT: function math.round(number) local _, decimals = math.modf(number) if decimals < 0.5 then return math.floor(number) end return math.ceil(number) end local revive_percentage = 0 local timer = 0 function add_percentage_per_second() if (revive_percentage < 100) then revive_percentage = revive_percentage + 1.25 if (revive_percentage >= 100) then setPedAnimation(getLocalPlayer()) removeEventHandler("onClientRender", getRootElement(), start_revive_process) revive_percentage = 0 end end end local screenW, screenH = guiGetScreenSize() function start_revive_process() if (revive_percentage == 0) then setTimer(add_percentage_per_second,62.5,80) --ads a timer that executes once every second for 5 seconds, adding 20% each time. setPedAnimation(getLocalPlayer( ),"ped","FLOOR_hit_f",-1,false) --start anim revive_percentage = revive_percentage+1 end dxDrawText(math.round(revive_percentage).."%", screenW * 0.4802, screenH * 0.9500, screenW * 0.5198, screenH * 0.9694, tocolor(0, 0, 0, 255), 1.00, "default", "center", "center", false, false, true, false, false) dxDrawRectangle(screenW * 0.4219, screenH * 0.9491, screenW * 0.1568, screenH * 0.0204, tocolor(255, 255, 255, 255), false) dxDrawRectangle(screenW * 0.4219, screenH * 0.9491, screenW * revive_percentage/638, screenH * 0.0204, tocolor(255, 0, 0, 255), false) end function StartReviveClient() addEventHandler( "onClientRender", getRootElement(), start_revive_process ) end addEvent( "startrevive", true ) addEventHandler( "startrevive", getRootElement( ), StartReviveClient ) and add this on your server side, I imagine you know how to adapt it: function startRevive(playerSource, commandName) triggerClientEvent( getRootElement( ), "startrevive", playerSource) --this calls the client event end addCommandHandler( "revive", startRevive) how does it work: 1.) it creates a timer that executes once every 62.5 milliseconds 80 times, which is 5 seconds (62.5 x 80 = 5000) to function "add_percentage_per_second (ignore function name, wanted to do it a little more fast-paced, 1.25 percent 80 times equals 100% if you want to change the total time of revive, you now know the math needed WARNING: THIS IS NOT THE MOST OPTIMIZED WAY TO DO IT I did this in 10 minutes, hopefully it helps Link to comment
VenomOG Posted August 12, 2018 Author Share Posted August 12, 2018 On 8/10/2018 at 00:15, knightscript said: I mean, there was no need to humilliate him, you could of told him more or less what functions to use, here, tested it, CLIENT: function math.round(number) local _, decimals = math.modf(number) if decimals < 0.5 then return math.floor(number) end return math.ceil(number) end local revive_percentage = 0 local timer = 0 function add_percentage_per_second() if (revive_percentage < 100) then revive_percentage = revive_percentage + 1.25 if (revive_percentage >= 100) then setPedAnimation(getLocalPlayer()) removeEventHandler("onClientRender", getRootElement(), start_revive_process) revive_percentage = 0 end end end local screenW, screenH = guiGetScreenSize() function start_revive_process() if (revive_percentage == 0) then setTimer(add_percentage_per_second,62.5,80) --ads a timer that executes once every second for 5 seconds, adding 20% each time. setPedAnimation(getLocalPlayer( ),"ped","FLOOR_hit_f",-1,false) --start anim revive_percentage = revive_percentage+1 end dxDrawText(math.round(revive_percentage).."%", screenW * 0.4802, screenH * 0.9500, screenW * 0.5198, screenH * 0.9694, tocolor(0, 0, 0, 255), 1.00, "default", "center", "center", false, false, true, false, false) dxDrawRectangle(screenW * 0.4219, screenH * 0.9491, screenW * 0.1568, screenH * 0.0204, tocolor(255, 255, 255, 255), false) dxDrawRectangle(screenW * 0.4219, screenH * 0.9491, screenW * revive_percentage/638, screenH * 0.0204, tocolor(255, 0, 0, 255), false) end function StartReviveClient() addEventHandler( "onClientRender", getRootElement(), start_revive_process ) end addEvent( "startrevive", true ) addEventHandler( "startrevive", getRootElement( ), StartReviveClient ) and add this on your server side, I imagine you know how to adapt it: function startRevive(playerSource, commandName) triggerClientEvent( getRootElement( ), "startrevive", playerSource) --this calls the client eventendaddCommandHandler( "revive", startRevive) how does it work: 1.) it creates a timer that executes once every 62.5 milliseconds 80 times, which is 5 seconds (62.5 x 80 = 5000) to function "add_percentage_per_second (ignore function name, wanted to do it a little more fast-paced, 1.25 percent 80 times equals 100% if you want to change the total time of revive, you now know the math needed WARNING: THIS IS NOT THE MOST OPTIMIZED WAY TO DO IT I did this in 10 minutes, hopefully it helps its cool but do you know what revive system im talking? let me explain 1. Cop killed criminal, criminal is sleeping 2.If a criminal or someone else clicked criminal while hes still sleeping timer starts 3. timer ends and criminal is alive again Link to comment
knightscript Posted August 12, 2018 Share Posted August 12, 2018 (edited) 4 hours ago, KnucklesSAEG said: its cool but do you know what revive system im talking? let me explain 1. Cop killed criminal, criminal is sleeping 2.If a criminal or someone else clicked criminal while hes still sleeping timer starts 3. timer ends and criminal is alive again well you just have to adapt the code I gave you just use getDistanceBetweenPoints3D and i dont know what you use to know if its a criminal that is trying to revive Edited August 12, 2018 by knightscript added more info Link to comment
VenomOG Posted August 12, 2018 Author Share Posted August 12, 2018 Here s my go GUIEditor = { button = {}, window = {}, progressbar = {}, label = {} } addEvent("ReviveProgress", true) addEventHandler("ReviveProgress", root, function(player) local screenW, screenH = guiGetScreenSize() if isElement(GUIEditor.window[1]) then return end GUIEditor.window[1] = guiCreateWindow(321, 277, 408, 178, "Revive", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(252, 148, 15, 15, "", false, GUIEditor.window[1]) GUIEditor.label[2] = guiCreateLabel(6, 24, 392, 66, "PLAYER IS TRYING TO REVIVE YOU CLICK ACCEPT TO ACCEPT AND BE ALIVE\nOR CLICK DENY TO DIE AND SUFFER", false, GUIEditor.window[1]) guiLabelSetHorizontalAlign(GUIEditor.label[2], "left", true) GUIEditor.button[1] = guiCreateButton(9, 128, 153, 35, "Accept", false, GUIEditor.window[1]) GUIEditor.button[2] = guiCreateButton(235, 128, 153, 35, "Deny", false, GUIEditor.window[1]) GUIEditor.progressbar = guiCreateProgressBar(284, 481, 479, 52, false) guiSetVisible(GUIEditor.progressbar, false) end ) addEventHandler("onClientGUIClick", GUIEditor.button[1], function () progress = guiProgressBarGetProgress() guiSetVisible(GUIEditor.window[1], false) guiSetVisible(GUIEditor.progressbar, true) local lol = guiProgressBarGetProgress(GUIEditor.progressbar) setTimer( guiProgressBarSetProgress, 5000, 1,GUIEditor.progressbar,lol+10 ) setTimer( guiProgressBarSetProgress, 10000, 1,GUIEditor.progressbar,lol+20 ) setTimer( guiProgressBarSetProgress, 15000, 1,GUIEditor.progressbar,lol+30 ) setTimer( guiProgressBarSetProgress, 20000, 1,GUIEditor.progressbar,lol+40 ) setTimer( guiProgressBarSetProgress, 25000, 1,GUIEditor.progressbar,lol+50 ) setTimer( guiProgressBarSetProgress, 30000, 1,GUIEditor.progressbar,lol+60 ) setTimer( guiProgressBarSetProgress, 35000, 1,GUIEditor.progressbar,lol+70 ) setTimer( guiProgressBarSetProgress, 40000, 1,GUIEditor.progressbar,lol+80 ) setTimer( guiProgressBarSetProgress, 45000, 1,GUIEditor.progressbar,lol+90 ) setTimer( guiProgressBarSetProgress, 50000, 1,GUIEditor.progressbar,lol+100 ) timer = setTimer( function () triggerServerEvent("revieve", localPlayer) guiSetVisible(GUIEditor.progressbar, false) showCursor(false) guiProgressBarSetProgress(GUIEditor.progressbar, 0) end, 50000,1) end) addEventHandler("onClientGUIClick", GUIEditor.button[2], hideGui) function hideGui() destroyElement(GUIEditor.window[1]) showCursor(false) end SERVER function click(btn, state, plr) if btn ~= "left" and state ~= "down" then return end if getElementType(source) ~= "player" then return end if source ~= plr then return end triggerClientEvent("ReviveProgress", plr) end addEventHandler("onElementClicked", root, click) addEvent("revieve" ,true) addEventHandler("revieve", root, function () local data = getElementData(source, "selected") if (data == true) then local x, y, z = getElementPosition(source) local Team = getPlayerTeam(source) if (getTeamName(Team) ~= "Police") then spawnPlayer(source, x, y, z) spawnPlayer(source, x, y, z, 0, 0, 0, 0, Team) setElementHealth(source, 100) setPedAnimation(source, false) setElementData(source, "rev", false) end end end) @knightscript @knightscript 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