Deep thinker Posted December 16, 2016 Share Posted December 16, 2016 Topic #1 i have a script for the police but there is a bug when they player is jailed it get it's crimes and he get jailed for ex : 3.5 second and the 0.5 doesn't count down and the player get stuck in jail ,this one make the player stuck for 3.5 3.75 and the 0.75 or the 0.5 don't count down, local seconds_left = 0 local sWidth, sHeight = guiGetScreenSize() local controls = {"fire","enter_exit","action","crouch","next_weapon","previous_weapon"} local pos = {} local client = getLocalPlayer() local cop local lawTeams = {["Police"]=true, ["SWAT"]=true, ["Military"] = true} chargesWindow = guiCreateWindow((sWidth/2)-365,(sHeight/2)-158,730,316,"T-RPG Police Database: The charges against you",false) guiSetAlpha(chargesWindow,0.95) guiSetVisible(chargesWindow, false) guiWindowSetSizable(chargesWindow,false) chargesGrid = guiCreateGridList(14,31,700,235,false,chargesWindow) guiGridListSetSelectionMode(chargesGrid,0) chargeColumn = guiGridListAddColumn(chargesGrid,"Charge",0.95) closeButton = guiCreateButton(308,274,115,30,"Close",false,chargesWindow) addEventHandler("onClientGUIClick", closeButton, function() guiGridListClear(chargesGrid) guiSetVisible(chargesWindow, false) showCursor(false) end, false) function drawJailTime() dxDrawBorderedText(seconds_left.." seconds remaining.",(653/1024)*sWidth,(678/768)*sHeight,(1010/1024)*sWidth,(725/768)*sHeight,tocolor(50,150,255,255),(sWidth/1024)*2.0,"sans","left","top",false,false,false) end function dxDrawBorderedText( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI ) dxDrawText ( text, x - 1, y - 1, w - 1, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) -- black dxDrawText ( text, x + 1, y - 1, w + 1, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x - 1, y + 1, w - 1, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y + 1, w + 1, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x - 1, y, w - 1, h, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x + 1, y, w + 1, h, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y - 1, w, h - 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y + 1, w, h + 1, tocolor ( 0, 0, 0, 255 ), scale, font, alignX, alignY, clip, wordBreak, false ) dxDrawText ( text, x, y, w, h, color, scale, font, alignX, alignY, clip, wordBreak, postGUI ) end addEvent("startJailCounter", true) addEventHandler("startJailCounter", client, function (theTime, crimes, x, y, z, bool) pos[1], pos[2], pos[3] = x, y, z if theTime < 1000.5 then seconds_left = 0.5 else seconds_left = theTime/1000.5 end jailTimer = setTimer(minusOneForCounter, 1000, seconds_left) addEventHandler("onClientRender", root, drawJailTime) for ind, ent in pairs(crimes) do if (ent[1] == "1") then theString = ent[1].." Count of "..ent[2].." commit a total of "..ent[3].." times in life." else theString = ent[1].." Counts of "..ent[2].." commit a total of "..ent[3].." times in life." end local row = guiGridListAddRow(chargesGrid) guiGridListSetItemText(chargesGrid, row, chargeColumn, theString, false, false) end guiSetVisible(chargesWindow, true) showCursor(true) disableTimer = setTimer(toggleControlsInJail, 1000, seconds_left - 1, false) end) function minusOneForCounter() if (seconds_left == 1) then removeEventHandler("onClientRender", root, drawJailTime) triggerServerEvent("releasePlayerFromJail", client, client, pos[1], pos[2], pos[3]) toggleControlsInJail(true) else seconds_left = seconds_left - 1 setElementData(localPlayer,"jailTime",tonumber(seconds_left*1000)) end end function antiJailDamage() if (isTimer(jailTimer)) then cancelEvent() end end addEventHandler("onClientPlayerDamage", client, antiJailDamage) function toggleControlsInJail(bool) for ind, control in pairs(controls) do toggleControl(control, bool) end end function release() removeEventHandler("onClientRender", root, drawJailTime) triggerServerEvent("releasePlayerFromJail", client, client, pos[1], pos[2], pos[3]) if isTimer(jailTimer) then killTimer(jailTimer) end if isTimer(disableTimer) then killTimer(disableTimer) end for ind, control in pairs(controls) do toggleControl(control, true) end end addEvent("releaseJ",true) addEventHandler("releaseJ",getRootElement(),release) addEvent("onClientPlayerLogout",true) addEventHandler("onClientPlayerLogout",root, function () if isTimer(jailTimer) then killTimer(jailTimer) end removeEventHandler("onClientRender", root, drawJailTime) seconds_left = 0 end) local policeStationLocations = { {X=2246.100830, Y=2453.19531, Z=9.8203}, {X=-1406.90722, Y=2655.09277, Z=55.6875}, {X=-209.9542, Y=977.7558, Z=18.1889}, {X=-1628.26196, Y=676.620056, Z=6.190120}, {X=624.66278, Y=-605.72027, Z=15.923292}, {X=1536.264, Y=-1675.483, Z=12.0}, {X=-2164.37792, Y=-2389.53320, Z=29.61720}, {X=135.560, Y=1949.906, Z=18.3} } local blip = {} local marker = {} function createArrestZones(alpha) if (alpha == 255) then for index, entry in pairs(policeStationLocations) do blip[index] = createBlip(entry.X, entry.Y, entry.Z, 30, 3, 0, 0, 255, 255) setBlipColor(blip[index], 0, 0, 0, 0) marker[index] = createMarker(entry.X, entry.Y, entry.Z, "cylinder", 6, 0, 0, 255, 200) end else for index, entry in pairs(blip) do if (entry and isElement(entry)) then destroyElement(entry) end end for index, entry in pairs(marker) do if (entry and isElement(entry)) then destroyElement(entry) end end end end addEvent("showArrestZones", true) addEventHandler("showArrestZones", client, createArrestZones) local cop = nil local prisoner = getLocalPlayer() function walkThePrisoner() if(getPedOccupiedVehicle(prisoner) == false) then local copX, copY, copZ = getElementPosition(cop) local prisonerX, prisonerY, prisonerZ = getElementPosition(prisoner) local copDim = getElementDimension(cop) local copInt = getElementInterior(cop) local crimDim = getElementDimension(prisoner) local crimInt = getElementInterior(prisoner) local copAngle = (360 - math.deg(math.atan2((copX - prisonerX),(copY - prisonerY))))%360 setPedRotation(prisoner, copAngle) setCameraTarget(prisoner, prisoner) if (copDim ~= crimDim or copInt ~= crimInt) then triggerServerEvent("setPrisonerInterior", prisoner, cop, copDim, copInt, copX, copY, copZ) end local dist = getDistanceBetweenPoints2D(copX, copY, prisonerX, prisonerY) if(dist > 35) then triggerServerEvent("freePlayer",prisoner,prisoner) removeEventHandler("onClientPreRender",getRootElement(),walkThePrisoner) elseif (dist > 15) then setControlState("sprint", false) setControlState("walk", false) setControlState("forwards", true) setControlState("jump", true) elseif (dist > 10) then setControlState("sprint", true) setControlState("walk", false) setControlState("forwards", true) setControlState("jump", false) elseif (dist > 5) then setControlState("sprint", false) setControlState("walk", false) setControlState("forwards", true) setControlState("jump", false) elseif (dist > 1.5) then setControlState("sprint", false) setControlState("walk", true) setControlState("forwards", true) setControlState("jump", false) elseif (dist < 1.5) then setControlState("sprint", false) setControlState("walk", false) setControlState("forwards", false) setControlState("jump", false) end local vehicle = getPedOccupiedVehicle(cop) if (vehicle) then triggerServerEvent("gotoVehicle",prisoner,cop,prisoner) end end end addEvent("onClientPlayerArrested", true) addEventHandler("onClientPlayerArrested", getLocalPlayer(), function(Cop) cop = Cop addEventHandler("onClientPlayerDamage",localPlayer,cancelEvent) addEventHandler("onClientPreRender",getRootElement(),walkThePrisoner) end ) addEvent("onClientPlayerEscaped", true) addEventHandler("onClientPlayerEscaped", getLocalPlayer(), function() cop = nil removeEventHandler("onClientPlayerDamage",getLocalPlayer(),cancelEvent) removeEventHandler("onClientPreRender",getRootElement(),walkThePrisoner) end ) addEvent("onClientPlayerJailed", true) addEventHandler("onClientPlayerJailed", getLocalPlayer(), function() cop = nil removeEventHandler("onClientPlayerDamage",getLocalPlayer(),cancelEvent) removeEventHandler("onClientPreRender",getRootElement(),walkThePrisoner) end ) function showPlayerCharges(crimes, message) if (message and message == "T-RPG Police Database: Your criminal record") then guiSetText(chargesWindow, message) for ind, ent in pairs(crimes) do if (ent[1] == "1") then theString = ent[1].." Count of "..ent[2].."." else theString = ent[1].." Counts of "..ent[2].."." end local row = guiGridListAddRow(chargesGrid) guiGridListSetItemText(chargesGrid, row, chargeColumn, theString, false, false) end else guiSetText(chargesWindow, "Terrible RPG charges against you") for ind, ent in pairs(crimes) do if (ent[1] == "1") then theString = ent[1].." Count of "..ent[2].." worth "..ent[4].." seconds in prison." else theString = ent[1].." Counts of "..ent[2].." worth "..ent[4].." seconds in prison." end local row = guiGridListAddRow(chargesGrid) guiGridListSetItemText(chargesGrid, row, chargeColumn, theString, false, false) end end guiSetVisible(chargesWindow, true) showCursor(true) end addEvent("showCharges", true) addEventHandler("showCharges", client, showPlayerCharges) function doBeanBag(attacker, weapon) if (attacker and weapon == 25 or weapon == 27) then if getElementData(attacker, "beanbagRound") then if getPlayerTeam(attacker) and not lawTeams[getTeamName(getPlayerTeam(attacker))] then setElementData(attacker, "beanbagRound", false) return end cancelEvent() toggleAllControls(false, true, false) setTimer(toggleAllControls, 4000, 1, true, true, false) exports["(SAUR)Info"]:sendClientMessage("You were shot with a bean bag by the police.", 255, 100, 0) end end end addEventHandler("onClientPlayerDamage", localPlayer, doBeanBag) function weaponSwitch(previousWeaponID, currentWeaponID) local teamName = getTeamName(getPlayerTeam(localPlayer)) if lawTeams[teamName] then if currentWeaponID ~= 25 and currentWeaponID ~= 27 then return end if getElementData(client, "beanbagRound") then exports["(SAUR)Info"]:sendClientMessage("Bean bag: Press SPACE while using a Shotgun to use a lethal bean bag rounds.", 255, 50, 0) else exports["(SAUR)Info"]:sendClientMessage("Bean bag: Press SPACE while using a Shotgun to use a non lethal bean bag round.", 0, 255, 0) end end end addEventHandler("onClientPlayerWeaponSwitch", client, weaponSwitch) Topic #2 the second topic talks about saving the walk style ,it doesn't get saved. actually i didn't make it someone gave it to me. function saveWalkStyle() local acc = getPlayerAccount(source) if acc and not isGuestAccount(acc) then local walk = getPedWalkingStyle (source) setAccountData(acc, "walkStyle", tonumber(walk)) end end addEventHandler("onPlayerQuit", root, saveWalkStyle) function loadWalkStyle(_, acc) local walk = getAccountData(acc, "wstyle") or 0 setPedWalkingStyle(source, tonumber(walk)) end addEventHandler("onPlayerLogin", root, loadWalkStyle) Link to comment
Captain Cody Posted December 17, 2016 Share Posted December 17, 2016 function SaveWalkStyle(acc, _) local walk = getPedWalkingStyle (source) setAccountData(acc, "wstyle", tonumber(walk)) end addEventHandler("onPlayerLogout", root, saveWalkStyle) function loadWalkStyle(_, acc) local walk = getAccountData(acc, "wstyle") or 0 setPedWalkingStyle(source, tonumber(walk)) end addEventHandler("onPlayerLogin", root, loadWalkStyle) Fixed mismatched variable, and made it a tad more simplified. Link to comment
Deep thinker Posted December 17, 2016 Author Share Posted December 17, 2016 10 hours ago, CodyL said: function SaveWalkStyle(acc, _) local walk = getPedWalkingStyle (source) setAccountData(acc, "wstyle", tonumber(walk)) end addEventHandler("onPlayerLogout", root, saveWalkStyle) function loadWalkStyle(_, acc) local walk = getAccountData(acc, "wstyle") or 0 setPedWalkingStyle(source, tonumber(walk)) end addEventHandler("onPlayerLogin", root, loadWalkStyle) Fixed mismatched variable, and made it a tad more simplified. didn't work,I tested it. Link to comment
pa3ck Posted December 17, 2016 Share Posted December 17, 2016 Change the eventHandler to this: addEventHandler("onPlayerLogout", root, SaveWalkStyle) Link to comment
Deep thinker Posted December 17, 2016 Author Share Posted December 17, 2016 13 minutes ago, pa3ck said: Change the eventHandler to this: addEventHandler("onPlayerLogout", root, SaveWalkStyle) which one? Link to comment
pa3ck Posted December 17, 2016 Share Posted December 17, 2016 addEventHandler("onPlayerLogout", root, saveWalkStyle) --> addEventHandler("onPlayerLogout", root, SaveWalkStyle) Link to comment
Best-Killer Posted December 17, 2016 Share Posted December 17, 2016 and about timer use : GetTimerDetails better Link to comment
Deep thinker Posted December 17, 2016 Author Share Posted December 17, 2016 6 hours ago, Best-Killer said: and about timer use : GetTimerDetails better i think i should use a better compare than mine ,my compare makes this 0.5 ,i have discovered this. 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