Jump to content

[Request] Mode Vote Starter if no mode running


DazzaJay

Recommended Posts

Ive searched around, and only found a thread of somone else trying to do the same thing, but that didnt work properly.

https://forum.multitheftauto.com/viewtop ... de#p268362

Basically, im looking for a script that works like this:

On player join, Check to see if a Game mode is running.

If No game mode is running, then start a VoteMode.

If a mode is running, Do nothing.

Im sure more than just me are looking for a script like this.

Link to comment

Such a script might really come in handy.

Here's what I got so far (untested)

mm = getResourceFromName ("mapmanager") 
--vm = getResourceFromName ("votemanager") 
  
function join () --on player join 
    if getPlayerCount() == 1 then --check if he's the only player 
        if call (mm, "getRunningGamemode") == false then --if no gamemode is running 
            --call (vm, "voteBetweenModes", --no idea how to use that properly 
            executeCommandHandler ("votemode", source) --start a gamemode poll 
        elseif call (mm, "getRunningGamemodeMap") == false then --elseif no map is running 
            executeCommandHandler  ("votemap", source, call (mm, "getRunningGamemode")) --start a map poll for the running gamemode 
        else --else 
            call (mm, "changeGameModeMap", call (mm, "getRunningGamemodeMap")) --restart the currently running map 
        end 
    end 
end 
  
addEventHandler ("onPlayerJoin", getRootElement(), join) 

It still uses the not so nice executeCommandHandler way but there is no appropriate votemode function exported by the votemanager resource and "voteBetweenModes" is hard to use as I couldn't figure out a way to pass all gamemode pointers as arguments for that function.

Link to comment

Another solution now using exported votemanager functions instead of executeCommandHandler:

mm = getResourceFromName ("mapmanager") 
vm = getResourceFromName ("votemanager") 
  
function join () --on player join 
    if getPlayerCount() == 1 then --check if he's the only player 
        if call (mm, "getRunningGamemode") == false then --if no gamemode is running 
            local gamemodes = call (mm, "getGamemodes") 
            call (vm, "voteBetweenModes", unpack(gamemodes)) 
            --executeCommandHandler ("votemode", source) --start a gamemode poll 
        elseif call (mm, "getRunningGamemodeMap") == false then --elseif no map is running 
            --executeCommandHandler  ("votemap", source, call (mm, "getRunningGamemode")) --start a map poll for the running gamemode 
            local maps = call (mm, "getMapsCompatibleWithGamemode", call (mm, "getRunningGamemode"))  
            call (vm, "voteBetweenMaps", unpack (maps)) 
        else --else 
            call (mm, "changeGameModeMap", call (mm, "getRunningGamemodeMap")) --restart the currently running map 
        end 
    end 
end 
  
addEventHandler ("onPlayerJoin", getRootElement(), join) 

Again, this is untested as im too lazy to setup a new resource :D

Link to comment

The first one didnt work, i didnt see any errors or anything, iil check that new one in a sec.

But, How would i go about Exporting a Votemode function? is it as simple as adding to the Meta? or is there other stuff that would be needed?

:::EDIT:::

That one responds the same.

i do see an error : "ERROR: call: Check the function exists, its exported and you've passed the correct arguments"

Which could be anything.

Link to comment

getRunningGamemode will never return false that's the problem

I modified the if checks a bit and fixed a typo that caused the error. So now there is actually the possibility that the script reaches the point where to start a vote^^

mm = getResourceFromName ("mapmanager") 
vm = getResourceFromName ("votemanager") 
  
function join () --on player join 
    if getPlayerCount() == 1 then --check if he's the only player 
        if call(mm, "isGamemode", call (mm, "getRunningGamemode")) == false then --if no gamemode is running 
            local gamemodes = call (mm, "getGamemodes") 
            call (vm, "voteBetweenModes", unpack(gamemodes)) 
            --executeCommandHandler ("votemode", source) --start a gamemode poll 
        elseif call(mm, "isMap", call (mm, "getRunningGamemodeMap")) == false then --elseif no map is running 
            --executeCommandHandler  ("votemap", source, call (mm, "getRunningGamemode")) --start a map poll for the running gamemode 
            local maps = call (mm, "getMapsCompatibleWithGamemode", call (mm, "getRunningGamemode"))  
            call (vm, "voteBetweenMaps", unpack (maps)) 
        else --else 
            call (mm, "changeGamemodeMap", call (mm, "getRunningGamemodeMap")) --restart the currently running map 
        end 
    end 
end 
  
addEventHandler ("onPlayerJoin", getRootElement(), join) 

Link to comment

iil check into it, as i know that after a vote finishess, Race Mode often starts another one on its own (Cos its retarded)

Yeah, thats a bug ive never seen before.

also, can it be put on a timer, so it starts a mode vote 5 seconds after the player joins? instead of on the spot, as it often starts the vote before the client can recoeve the votemanager, so, it dosent appear, then, reconnects result in lots of "You must wait 300 seconds before starting another vote"

Link to comment

This bug is really really strange, and i cant for the life of me work it out.

I see that you use the folllowing to start the mode vote.

executeCommandHandler ("votemode", source)

So im guessing it acts the same as if i just typed /votemode into the chat

Diffrerence is, when i type /votemode it dosent get stuck.

heres a stupid idea, (but worth a shot) i know i can type /votemode into console, and "Console" will start a vote. How would i change that command handler so the vote gets started by console?

Would it be as simple as changing it to

executeCommandHandler ("votemode", console)

?

:::EDIT:::

I think i may have found the issue.

This error only happens when the modestarter script starts a mode vote.

votemanager_client.lua: addEventHandler: onClientRender is already handled - line: 222

But i dont see how.

this is line 222:

addEventHandler("onClientRender", rootElement, updateTime)

Either way, i still have a hunch that if it thaught "Console" was starting the vote, and not the player, it might work fine.

Link to comment

That looks like the Standard Votemanager resource you linked to.

Which is completley pointless.

Concidering im trying to make an Automatic Votemode function if a player joins and no mode is runing, and intergrate it with a FIXED version of that votetemanager. Which, has all the same functions of that.

Link to comment

thanks guys, i just made some slight adjustments, as i thaught "if more than one person joins at same time, say 2 people on a LAN, it would recognise more than one player and not start the vote"

so i set it to If theres less than 5 players, and no mode running, then start the mode vote.

i also added a timer that checks every so often if there is no modes running, and starts a mode vote. (just incase a moron joins and votes "Cancel Vote") (I have seen a lot of morons vote 9, then bitch about "i cant spawn"

so it should kep poping up till a mode is started.

i will edit with link soon.

:::EDIT:::

https://community.multitheftauto.com/index.html?p ... anddescr=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...