Mossy Posted September 23, 2012 Share Posted September 23, 2012 Hi I'm learning scripting very slowly and a resource I'm using has an error (which is in the title). function KeyBind() -- bind the key for all players. if get("g_vote") == 'true' then local players = getElementsByType("player") local pcount = getPlayerCount() triggerClientEvent("onGMStop", getRootElement()) if string.find(getMapName(), get('filterword'), 1, true) then outputDebugString("DD Detected, Halting the ghostmode voting.") else executeSQLQuery("DELETE FROM GmBlockList") VoteCount = 0 for k,v in ipairs (players) do bindKey(v,"g","down",addVote) setElementData( v, "overrideCollide.uniqueblah", nil, false ) end outputChatBox("Ghostmode Disabled by Server",getRootElement(),255,0,0) StartElement() end end end addEventHandler("onMapStarting",getRootElement(),KeyBind) function KeyUnBind(newStateName,oldStateName) if get("g_vote") == 'true' then if newStateName == "Running" then local players = getElementsByType("player") for k,v in ipairs (players) do unbindKey(v,"g","down",addVote) end executeSQLQuery("DELETE FROM GmBlockList") triggerClientEvent("onGMStop", getRootElement()) if VoteCount >= ReqPlayers() then outputChatBox("*Ghostmode: Voting for ghostmode passed!",root,162,82,201) for k,thePlayer in ipairs(getElementsByType('player')) do setElementData( thePlayer, "overrideCollide.uniqueblah", 0, true ) end else --[[for k,thePlayer in ipairs(getElementsByType('player')) do setElementData( thePlayer, "overrideCollide.uniqueblah", 255, false ) end]]-- outputChatBox("*Ghostmode: Voting for ghostmode failed!",root,162,82,201) end end end end addEvent("onRaceStateChanging") addEventHandler("onRaceStateChanging",getRootElement(),KeyUnBind) function addVote(keyPresser) local serial = getPlayerSerial(keyPresser) local serialcheck = executeSQLSelect ( "GmBlockList", "serial","serial = '" .. serial .. "'") if ( type( serialcheck ) == "table" and #serialcheck == 0 ) or not serialcheck then executeSQLInsert ( "GmBlockList", "'"..serial.."'") VoteCount = VoteCount + 1 triggerClientEvent(getRootElement(),"UpdateCount", getRootElement(),VoteCount,ReqPlayers()) else outputChatBox("You have already voted for Ghostmode!",keyPresser,255,0,0) end end function ReqPlayers() local pcount = getPlayerCount() if pcount == 1 then reqPlayers = 1 elseif pcount > 1 and pcount < 4 then reqPlayers = 2 elseif pcount > 3 and pcount < 7 then reqPlayers = 3 elseif pcount > 6 and pcount < 10 then reqPlayers = 5 elseif pcount > 9 and pcount < 15 then reqPlayers = 7 elseif pcount > 14 and pcount < 21 then reqPlayers = 12 elseif pcount > 20 and pcount < 26 then reqPlayers = 17 elseif pcount > 25 then reqPlayers = 21 end return reqPlayers end function StartElement(vcount,pcount) vcount = 0 pcount = ReqPlayers() triggerClientEvent("UpdateCount", getRootElement(),vcount,pcount) triggerClientEvent("onGMStart", getRootElement()) end Also what I noticed is that when I play a DD map the ghostmode text isn't there, yet every time in the Chat it says "Voting for ghostmode passed!" Basically what I'm asking is if either this problem is harmless or if it's a bug and a way to fix it. If you can't help me for any reason I understand. Thanks in advance guys. Link to comment
Jaysds1 Posted September 23, 2012 Share Posted September 23, 2012 try this: local VoteCount --define this as a global function addVote(keyPresser) local serial = getPlayerSerial(keyPresser) local serialcheck = executeSQLSelect ( "GmBlockList", "serial","serial = '" .. serial .. "'") if (type( serialcheck ) == "table" and #serialcheck == 0 ) or not serialcheck then executeSQLInsert ( "GmBlockList", "'"..serial.."'") VoteCount = VoteCount + 1 triggerClientEvent("UpdateCount",root,VoteCount,ReqPlayers()) else outputChatBox("You have already voted for Ghostmode!",keyPresser,255,0,0) end end function ReqPlayers() local reqPeds = 0 --define reqPeds just incase there's no players local pcount = getPlayerCount() if pcount == 1 then reqPeds = 1 elseif pcount > 1 and pcount < 4 then reqPeds = 2 elseif pcount > 3 and pcount < 7 then reqPeds = 3 elseif pcount > 6 and pcount < 10 then reqPeds = 5 elseif pcount > 9 and pcount < 15 then reqPeds = 7 elseif pcount > 14 and pcount < 21 then reqPeds = 12 elseif pcount > 20 and pcount < 26 then reqPeds = 17 elseif pcount > 25 then reqPeds = 21 end return reqPeds end function StartElement(vcount,pcount) if not vcount then --check if vcount is passed vcount = 0 --if it isn't, set it to 0 end if not pcount then pcount = ReqPlayers() end triggerClientEvent("UpdateCount",root,vcount,pcount) triggerClientEvent("onGMStart",root) end addEventHandler("onMapStarting",root,function() -- bind the key for all players. if get("g_vote") == 'true' then local pcount = getPlayerCount() triggerClientEvent("onGMStop",root) if string.find(getMapName(), get('filterword'), 1, true) then outputDebugString("DD Detected, Halting the ghostmode voting.") return end executeSQLQuery("DELETE FROM GmBlockList") VoteCount = 0 for _,v in ipairs(getElementsByType("player"))do bindKey(v,"g","down",addVote) setElementData( v, "overrideCollide.uniqueblah", nil, false ) end outputChatBox("Ghostmode Disabled by Server",getRootElement(),255,0,0) StartElement() end end) addEvent("onRaceStateChanging") addEventHandler("onRaceStateChanging",root,function(newStateName) if get("g_vote") == 'true' then if newStateName == "Running" then for _,v in ipairs(getElementsByType("player"))do unbindKey(v,"g","down",addVote) end executeSQLQuery("DELETE FROM GmBlockList") triggerClientEvent("onGMStop",root) if VoteCount >= ReqPlayers() then outputChatBox("*Ghostmode: Voting for ghostmode passed!",root,162,82,201) for _,v in ipairs(getElementsByType('player')) do setElementData( v, "overrideCollide.uniqueblah", 0, true ) end else --[[for k,thePlayer in ipairs(getElementsByType('player')) do setElementData( thePlayer, "overrideCollide.uniqueblah", 255, false ) end]]-- outputChatBox("*Ghostmode: Voting for ghostmode failed!",root,162,82,201) end end end end) Please read comments Link to comment
Mossy Posted September 23, 2012 Author Share Posted September 23, 2012 Thanks for the script! But I still get the "voting for ghostmode passed" message in the chat And I'm not sure if ghostmode is even on cause no one else is in the server at the moment. Is there maybe any way to automatically turn it off when the demolitionderby.lua script is in play? Link to comment
Jaysds1 Posted September 23, 2012 Share Posted September 23, 2012 (edited) ya,there's a way of turning it off automatically, I'll post the code here again. local VoteCount --define this as a global function addVote(keyPresser) local serial = getPlayerSerial(keyPresser) local serialcheck = executeSQLSelect ( "GmBlockList", "serial","serial = '" .. serial .. "'") if (type( serialcheck ) == "table" and #serialcheck == 0 ) or not serialcheck then executeSQLInsert ( "GmBlockList", "'"..serial.."'") VoteCount = VoteCount + 1 triggerClientEvent("UpdateCount",root,VoteCount,ReqPlayers()) else outputChatBox("You have already voted for Ghostmode!",keyPresser,255,0,0) end end function ReqPlayers() local reqPeds = 0 --define reqPeds just incase there's no players local pcount = getPlayerCount() if pcount == 1 then reqPeds = 1 elseif pcount > 1 and pcount < 4 then reqPeds = 2 elseif pcount > 3 and pcount < 7 then reqPeds = 3 elseif pcount > 6 and pcount < 10 then reqPeds = 5 elseif pcount > 9 and pcount < 15 then reqPeds = 7 elseif pcount > 14 and pcount < 21 then reqPeds = 12 elseif pcount > 20 and pcount < 26 then reqPeds = 17 elseif pcount > 25 then reqPeds = 21 end return reqPeds end function StartElement(vcount,pcount) if not vcount then --check if vcount is passed vcount = 0 --if it isn't, set it to 0 end if not pcount then pcount = ReqPlayers() end triggerClientEvent("UpdateCount",root,vcount,pcount) triggerClientEvent("onGMStart",root) end addEventHandler("onMapStarting",root,function() -- bind the key for all players. if get("g_vote") == 'true' then if get("ghostmode") == 'true' then set("race.ghostmode","false") end local pcount = getPlayerCount() triggerClientEvent("onGMStop",root) if string.find(getMapName(), get('filterword'), 1, true) then outputDebugString("DD Detected, Halting the ghostmode voting.") return end executeSQLQuery("DELETE FROM GmBlockList") VoteCount = 0 for _,v in ipairs(getElementsByType("player"))do bindKey(v,"g","down",addVote) setElementData( v, "overrideCollide.uniqueblah", nil, false ) end outputChatBox("Ghostmode Disabled by Server",getRootElement(),255,0,0) StartElement() end end) addEvent("onRaceStateChanging") addEventHandler("onRaceStateChanging",root,function(newStateName) if get("g_vote") == 'true' then if newStateName == "Running" then for _,v in ipairs(getElementsByType("player"))do unbindKey(v,"g","down",addVote) end executeSQLQuery("DELETE FROM GmBlockList") triggerClientEvent("onGMStop",root) if VoteCount >= ReqPlayers() then if get("ghostmode") == 'false' then set("ghostmode","true") end outputChatBox("*Ghostmode: Voting for ghostmode passed!",root,162,82,201) for _,v in ipairs(getElementsByType('player')) do setElementData( v, "overrideCollide.uniqueblah", 0, true ) end else --[[for k,thePlayer in ipairs(getElementsByType('player')) do setElementData( thePlayer, "overrideCollide.uniqueblah", 255, false ) end]]-- outputChatBox("*Ghostmode: Voting for ghostmode failed!",root,162,82,201) end end end end) Edited September 23, 2012 by Guest Link to comment
Mossy Posted September 23, 2012 Author Share Posted September 23, 2012 Now for some reason even if it doesn't show the poll for ghostmode, if I press G continuously, in says "You have already voted for ghostmode!" and ghostmode enables on a DD map. Hopefully this is just a chat bug and ghostmode isn't enabled after all. I'll let you know when someone else joins the server. Edit: I didn't even press anything and the ghostmode enabled on itself. 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