DarkLink Posted July 11, 2011 Share Posted July 11, 2011 Okay guys I am making my gamemode to work on a server that will continue run it, I mean, when someone win, the resource will be stopped and then can start again. The problem is: When I start my resource and there is no one on server it works fine, but when the gamemode stops, and there is already someone on server, I start the gamemode. And onClientResourceStart will trigger 2xTimes (I am testing with 2 players online when I restart), and that will trigger on of my events on server side, doing things like 2x, and it gets all bugged Timer bugged, spawn gui bugged... well thats the problem. I dont know how to get around this.. Thanks in advance guys!! Link to comment
Castillo Posted July 11, 2011 Share Posted July 11, 2011 Could you post the script which get's bugged? Link to comment
DarkLink Posted July 11, 2011 Author Share Posted July 11, 2011 Could you post the script which get's bugged? Its about a timer starting from 30 to 0 and a gui spawn for teams, and its big I think the solution was, if there were already 2 or more players on server wont trigger onClientResourceStart but would trigger onResourceStart instead , but I cant do this I guess. Thanks castillo Link to comment
Castillo Posted July 11, 2011 Share Posted July 11, 2011 What I understand is that is triggering everything * player count? so ex: 5 players, triggers 5 times the same thing. Link to comment
DarkLink Posted July 11, 2011 Author Share Posted July 11, 2011 What I understand is that is triggering everything * player count? so ex: 5 players, triggers 5 times the same thing. Yes I guess , is there some function to see if players have already download resources then dont trigger onClientResourceStart but onResourceStart instead. client side addEventHandler("onClientResourceStart", getRootElement(getThisResource()), function() outputChatBox("Welcome to my server bro! This is only for Borderpatrol gamemode! ENJOY") triggerServerEvent("checkTwoPlayersOnMode", getLocalPlayer()) end) So when the resource stops (reach the end) I will make it to start again, and when I test this, this event is triggered * (players on server). And the event "checkTwoPlayersOnMode" will be trigger a big amout of times (depending on players online) server side segundos = 30 timerEnabled = false gamemodeStarted = false addEvent("checkTwoPlayersOnMode", true) function checkTwoAndNotStartedRunIT () if gamemodeStarted == false then if timerEnabled == false then if(getPlayerCount() >= 2) then setTimer(escreve, 200, 1) triggerClientEvent("canShowGUISPAWN",getRootElement()) else outputChatBox("NOTE: This gamemode need at least 2 players online to start!", source) end else setElementData(source,"secondsRemaining",tostring(segundos)) triggerClientEvent ( source, "showDX", source ) triggerClientEvent(source,"canShowGUISPAWN",source) end else outputChatBox("You will need to wait the gamemode to finish, sorry", source) end end addEventHandler("checkTwoPlayersOnMode", getRootElement(), checkTwoAndNotStartedRunIT) function escreve () timerEnabled = true for i,v in pairs(getElementsByType("player")) do setElementData(v,"secondsRemaining",tostring(segundos)) triggerClientEvent ( v, "showDX", v ) end setTimer(countDown,1000,30) end function countDown() segundos = segundos -1 for i,v in pairs(getElementsByType("player")) do setElementData(v,"secondsRemaining",tostring(segundos)) end if segundos == 3 then triggerClientEvent("hadChosenTeam", getRootElement()) end if segundos == 0 then triggerClientEvent ( "hideDX", getRootElement() ) triggerClientEvent("hideSpawnGUI", getRootElement()) timerEnabled = false gamemodeStarted = true if(#playersForIMI==#playersForPOL or #playersForIMI == #playersForIMI + 1 or #playersForPOL == #playersForIMI + 1) then spawn() else outputChatBox("---Gamemode will run auto-balance---", getRootElement(), 255, 64, 64) autobalance() end end end function onStart () timerEnabled = false if(getPlayerCount() >= 2) then setTimer(escreve, 1500, 1) end end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart ) And this is the function that will call the timer to start writing on all the clients, its working on the first time they join server, but if I restart and there are players on, the timer gets bugged because this event its called x amount of times, and the segundos get decrease - 2/-3/-4 (depending on players online) instead of -1 . Did you guys understand? Thanks in advance, this is a major bug that I dont know how to fix it Thanks. Link to comment
DarkLink Posted July 11, 2011 Author Share Posted July 11, 2011 Guys I fixed this, changing the onStart function, added the remove handler if there were more than 2 players Thanks anyway!! Link to comment
qaisjp Posted July 11, 2011 Share Posted July 11, 2011 here is something that could be used: Client: me = getLocalPlayer() addEventHandler("onClientResourceStart", root, function(res) triggerServerEvent("onPlayerClientResourceStarted",me, me, res) end ) Server: addEvent("onPlayerClientResourceStarted", true) addEventHandler("onPlayerClientResourceStarted", root, function(pl,res) if res == getThisResource() then outputChatBox("*"..getPlayerName(pl).." has downloaded the gamemode and is ready to play!") end end ) Link to comment
DarkLink Posted July 11, 2011 Author Share Posted July 11, 2011 here is something that could be used:Client: me = getLocalPlayer() addEventHandler("onClientResourceStart", root, function(res) triggerServerEvent("onPlayerClientResourceStarted",me, me, res) end ) Server: addEvent("onPlayerClientResourceStarted", true) addEventHandler("onPlayerClientResourceStarted", root, function(pl,res) if res == getThisResource() then outputChatBox("*"..getPlayerName(pl).." has downloaded the gamemode and is ready to play!") end end ) Thanks for ur help, I fixed the problem. but that is a good solution, to see when client had started the resource thanks bro Link to comment
JR10 Posted July 11, 2011 Share Posted July 11, 2011 Why you even want to stop the resource, why not make a function that will start the game all over, start the Count down. Link to comment
DarkLink Posted July 11, 2011 Author Share Posted July 11, 2011 Why you even want to stop the resource, why not make a function that will start the game all over, start the Count down. Well I could do it. but I made all the script in this way. when a game ends, the resource is stoped. and then someone starts it again. Thanks jacob 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