Jump to content

Abstimmungssystem help


Recommended Posts

Hallo @Otto vn sakoa , ich habe ein Abstimmungssystem für dich, ich kann es mit dir teilen, wenn es dir gefällt, kannst du es zeigen, indem du meine Nachricht magst.

 

setElementData(resourceRoot,"VotesYes",0)
setElementData(resourceRoot,"VotesNo",0)
setElementData(resourceRoot,"VoteStarted",false)
setElementData(resourceRoot,"Question","")
setElementData(resourceRoot,"voteYesLabelText","")
setElementData(resourceRoot,"voteNoLabelText","")


function createVote(playerSource)
	if getElementData(resourceRoot,"VoteStarted") == true then return end
	setElementData(resourceRoot,"VoteStarted",true)
	local accountName = (getAccountName(getPlayerAccount(playerSource)))
	if isObjectInACLGroup("user."..accountName,aclGetGroup("Console")) or isObjectInACLGroup("user."..accountName,aclGetGroup("Admin")) then
		triggerClientEvent("showCreateVoteGuiEvent",playerSource)
	end
end
addCommandHandler("createvote",createVote)

function closeVote(playerSource)
	if getElementData(resourceRoot,"VoteStarted") == false then return end
	setElementData(resourceRoot,"VoteStarted",false)
	local accountName = (getAccountName(getPlayerAccount(playerSource)))
	if isObjectInACLGroup("user."..accountName,aclGetGroup("Console")) or isObjectInACLGroup("user."..accountName,aclGetGroup("Admin")) then
		accountNameTable = {}
		setElementData(resourceRoot,"VotesYes",0)
		setElementData(resourceRoot,"VotesNo",0)
		triggerClientEvent("closeVoteScoreGuiEvent",root)
	end
end
addCommandHandler("closevote",closeVote)

accountNameTable = {}

function voteYes(playerSource)
	if getElementData(resourceRoot,"VoteStarted") == false then return end
	local accountName = (getAccountName(getPlayerAccount(playerSource)))
	for key,value in pairs(accountNameTable) do
		if accountName == value then
			outputChatBox("You already voted.",playerSource)
			return
		end
	end
	accountNameTable[#accountNameTable + 1] = accountName
	setElementData(resourceRoot,"VotesYes",getElementData(resourceRoot,"VotesYes") + 1)
	triggerClientEvent("updateVoteYesEvent",root)
end
addCommandHandler("voteyes",voteYes)

function voteNO(playerSource)
	if getElementData(resourceRoot,"VoteStarted") == false then return end
	local accountName = (getAccountName(getPlayerAccount(playerSource)))
	for key,value in pairs(accountNameTable) do
		if accountName == value then
			outputChatBox("You already voted.",playerSource)
			return
		end
	end
	accountNameTable[#accountNameTable + 1] = accountName
	setElementData(resourceRoot,"VotesNo",getElementData(resourceRoot,"VotesNo") + 1)
	triggerClientEvent("updateVoteNoEvent",root)
end
addCommandHandler("voteno",voteNO)

function showVoteScore()
	Question = getElementData(resourceRoot,"Question")
	YES = getElementData(resourceRoot,"voteYesLabelText")
	NO = getElementData(resourceRoot,"voteNoLabelText")
	for i = 1,#getElementsByType("player") do
		triggerClientEvent("showVoteScoreGuiEvent",getElementsByType("player")[i],Question,YES,NO)
	end
end
addEvent("showVoteScoreEvent",true)
addEventHandler("showVoteScoreEvent",resourceRoot,showVoteScore)

function bindVoteKeys()
	bindKey(source,"F3","down","voteyes")
	bindKey(source,"F4","down","voteno")
	if getElementData(resourceRoot,"VoteStarted") == true then
		triggerClientEvent("showVoteScoreGuiEvent",source,getElementData(resourceRoot,"Question"),getElementData(resourceRoot,"voteYesLabelText"),getElementData(resourceRoot,"voteNoLabelText"))
	end
end
addEventHandler("onPlayerLogin",root,bindVoteKeys)

function bindVoteStartup()
	for i = 1,#getElementsByType("player") do
		bindKey(getElementsByType("player")[i],"F3","down","voteyes")
		bindKey(getElementsByType("player")[i],"F4","down","voteno")
	end
end
addEventHandler("onResourceStart",resourceRoot,bindVoteStartup)

Dieser Code befindet sich auf der server.lua-Seite

 


function showVoteScoreGui(Question,Yes,No)
	guiSetText(voteQuestionLabel,Question)
	if string.len(guiGetText(voteQuestionLabel)) > 35 then
		guiSetPosition(voteQuestionLabel,0.35,0.17,true)
	elseif string.len(guiGetText(voteQuestionLabel)) < 14 then
		guiSetPosition(voteQuestionLabel,0.43,0.17,true)
	else
		guiSetPosition(voteQuestionLabel,0.4,0.17,true)
	end
	guiSetText(voteYesLabel,Yes..": "..getElementData(resourceRoot,"VotesYes"))
	guiSetText(voteNOLabel,No..": "..getElementData(resourceRoot,"VotesNo"))
	guiSetVisible(voteYesLabel,true)
	guiSetVisible(voteNOLabel,true)
	guiSetVisible(voteQuestionLabel,true)
	guiSetVisible(voteF3Label,true)
	guiSetVisible(voteF4Label,true)
end
addEvent("showVoteScoreGuiEvent",true)
addEventHandler("showVoteScoreGuiEvent",localPlayer,showVoteScoreGui)

function closeVoteScoreGui()
	guiSetVisible(voteYesLabel,false)
	guiSetVisible(voteNOLabel,false)
	guiSetVisible(voteQuestionLabel,false)
	guiSetVisible(voteF3Label,false)
	guiSetVisible(voteF4Label,false)
end
addEvent("closeVoteScoreGuiEvent",true)
addEventHandler("closeVoteScoreGuiEvent",root,closeVoteScoreGui)

function updateVoteYes()
	guiSetText(voteYesLabel,getElementData(resourceRoot,"voteYesLabelText")..": "..getElementData(resourceRoot,"VotesYes"))
end
addEvent("updateVoteYesEvent",true)
addEventHandler("updateVoteYesEvent",root,updateVoteYes)

function updateVoteNo()
	guiSetText(voteNOLabel,getElementData(resourceRoot,"voteNoLabelText")..": "..getElementData(resourceRoot,"VotesNo"))
end
addEvent("updateVoteNoEvent",true)
addEventHandler("updateVoteNoEvent",root,updateVoteNo)

function voteButtonAction()
	if source == voteButton1 then
		showCursor(false)
		guiSetInputEnabled(false)
		guiSetVisible(voteEdit1,false)
		guiSetVisible(voteEdit2,false)
		guiSetVisible(voteEdit3,false)
		guiSetVisible(voteButton1,false)
		guiSetVisible(voteButton2,false)
		setElementData(resourceRoot,"Question",guiGetText(voteEdit1))
		setElementData(resourceRoot,"voteYesLabelText",guiGetText(voteEdit2))
		setElementData(resourceRoot,"voteNoLabelText",guiGetText(voteEdit3))
		triggerServerEvent("showVoteScoreEvent",resourceRoot)
	end
	
	if source == voteButton2 then
		showCursor(false)
		guiSetInputEnabled(false)
		guiSetVisible(voteEdit1,false)
		guiSetVisible(voteEdit2,false)
		guiSetVisible(voteEdit3,false)
		guiSetVisible(voteButton1,false)
		guiSetVisible(voteButton2,false)
		setElementData(resourceRoot,"VoteStarted",false)
	end
end

function createVoteGui()

voteYesLabel = guiCreateLabel(0.4,0.2,0.3,0.05,"",true)
voteNOLabel = guiCreateLabel(0.5,0.2,0.3,0.05,"",true)
voteQuestionLabel = guiCreateLabel(0.4,0.17,1,0.05,"",true)
voteF3Label = guiCreateLabel(0.445,0.95,1,0.05,"Press F3 to vote option 1.",true)
voteF4Label = guiCreateLabel(0.445,0.97,1,0.05,"Press F4 to vote option 2.",true)
guiSetVisible(voteYesLabel,false)
guiSetVisible(voteNOLabel,false)
guiSetVisible(voteQuestionLabel,false)
guiSetVisible(voteF3Label,false)
guiSetVisible(voteF4Label,false)

voteEdit1 = guiCreateEdit(0.3,0.3,0.3,0.05,"Vote Question",true)
voteEdit2 = guiCreateEdit(0.415,0.355,0.073,0.05,"YES",true)
voteEdit3 = guiCreateEdit(0.49,0.355,0.073,0.05,"NO",true)
guiEditSetMaxLength(voteEdit1,50)
guiEditSetMaxLength(voteEdit2,10)
guiEditSetMaxLength(voteEdit3,10)
voteButton1 = guiCreateButton(0.305,0.355,0.05,0.05,"Accept",true)
voteButton2 = guiCreateButton(0.36,0.355,0.05,0.05,"Cancel",true)
guiSetVisible(voteEdit1,false)
guiSetVisible(voteEdit2,false)
guiSetVisible(voteEdit3,false)
guiSetVisible(voteButton1,false)
guiSetVisible(voteButton2,false)
addEventHandler("onClientGUIClick",voteButton1,voteButtonAction,false)
addEventHandler("onClientGUIClick",voteButton2,voteButtonAction,false)
end
createVoteGui()

function showCreateVoteGui()
	showCursor(true)
	guiSetInputEnabled(true)
    guiSetVisible(voteEdit1,true)
	guiSetVisible(voteEdit2,true)
	guiSetVisible(voteEdit3,true)
	guiSetVisible(voteButton1,true)
	guiSetVisible(voteButton2,true)
end
addEvent("showCreateVoteGuiEvent",true)
addEventHandler("showCreateVoteGuiEvent",localPlayer,showCreateVoteGui)

fileDelete("gui_client.lua")

Dieser Code befindet sich auf der Seite gui_client.lua.

Ich hoffe, es wird für Sie funktionieren.

<meta>
	<info type="script"/>
	<script src="gui_client.lua" type="client"/>
	<script src="server.lua" type="server"/>
</meta>

meta.xml

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...