So I run a server, and I'm trying to make it so that whenever two rounds in the gamemode have passed (zombie survival), the mapvote menu is opened.
As I'm new to Lua, I don't have a very firm grasp on how it works. I can read the language fine, but I don't really know how to write it, or how to execute it.
I understand what hooks are, although I think compatibility between Zombie Survival and the mapvote system I'm using may be questionable.
From the ZS Hooks and Configs file:
[QUOTE]Zombie Survival now sports the following custom hooks and stuff.
If you're adding new game features then you would probably want to use hooks instead of overwriting files that may be updated.
You're a big boy, you know how to make hooks and use autorun so I won't go in to that. Just use them as if they were any other hook.
Returning anything besides nil in a hook will override the gamemode's stuff.
If you're going to be calling gamemode functions then use gamemode.Call so hooks are called and everything works properly.
gamemode.Call("EndRound", TEAM_HUMAN) instead of GAMEMODE:EndRound(TEAM_HUMAN)
MOST OF THE TIME THERE IS A HOOK CALLED AFTER THE FIRST ONE CALLED PostHookName[/QUOTE]
The hook I'm sure I need to use:
[QUOTE]Hook and function. Loads the next map. HERE IS WHERE YOU PUT YOUR MAP VOTING AND STUFF. RETURN TRUE TO OVERRIDE.
GM:LoadNextMap()[/QUOTE]
And the ReadMe from the mapvote system I'm using: (excl Mapvote)
[QUOTE]Hooks that you may use are:
- EXCL_MAPVOTE.DoFinish (args: string Winner), this hook is called right after the voting is done.
- EXCL_MAPVOTE.Finish (args: string Winner), this hook is called 4 seconds after the voting is done. Do map changes, extentions, etc. here.
- EXCL_MAPVOTE.Start, this hook is called when voting starts.
To add special compatability stuff for your own gamemode, check out the sv_compat.lua file in lua/excl_mapvote/.
To prevent a changelevel from running, set EXCL_MAPVOTE.SupressChange to true in either the DoFinish or Finish hook. This change is reverted after a single mapchange
is supressed.
To implement your own maploader (for when you want to use MySQL, MongoDB, an API, etc...), change the maploader config option in the configuration values file.
Load your own maploader under an if-statement. Your implementation should populate a table at EXCL_MAPVOTE.MapSelection with a maximum (no more) of 8 key-value integer
pairs (this means, each key is a number and each value is the name of the map that can be voted for).
Check sv_load.lua to see how the default (filesystem) maplist-loader is implemented. This may be helpful when making your own. [/QUOTE]
I'm not sure what to script exactly, or where to put the finished script so it can run.
I'm at a loss here. If anyone could help me, that'd be greatly appreciated.
First of all, nice job picking out the relevant parts of the documentation. You're already quite a bit farther than most people who post here asking for help. (Dunno about the nazi stuff on your profile though).
Anyway, here's some knowledge:
- Any scripts inside the folder `garrysmod/lua/autorun/server/` are ran automatically on the server (which is where your mapvote addon is)
- Judging by the documentation and [URL="https://github.com/kurt-stolle/mapvote/blob/master/lua/excl_mapvote/sv_compatability.lua"]the sv_compat file[/URL], you should just need to create a hook for the gamemode's LoadNextMap function. That function will then be called at the end of the game and is where you should put your code to start the map vote.
- Reading [URL="https://github.com/kurt-stolle/mapvote/blob/7f10ac591c3fc9ffed3e1640936b058dbfdd9f4c/lua/excl_mapvote/sv_core.lua#L81"]the code for the map vote addon[/URL], it seems that it will automatically change the map after the vote has finished, so you won't need to worry about changing the level yourself.
Here's where you could stop reading and try to implement it yourself. If you fail, here's code that should work.
[lua]
-- this file should be placed in lua/autorun/server/ so that it is ran
-- on the server automatically.
-- register a callback for the Zombie Survival LoadNextMap hook
hook.Add("LoadNextMap", "MapVote_ZombieSurvival", function()
-- start the map vote by calling the map vote addon's Start function
EXCL_MAPVOTE:Start()
-- block the Zombie Survival default map change code
return true
end)
[/lua]
[QUOTE=zerf;51806966]First of all, nice job picking out the relevant parts of the documentation. You're already quite a bit farther than most people who post here asking for help. (Dunno about the nazi stuff on your profile though).
Anyway, here's some knowledge:
- Any scripts inside the folder `garrysmod/lua/autorun/server/` are ran automatically on the server (which is where your mapvote addon is)
- Judging by the documentation and [URL="https://github.com/kurt-stolle/mapvote/blob/master/lua/excl_mapvote/sv_compatability.lua"]the sv_compat file[/URL], you should just need to create a hook for the gamemode's LoadNextMap function. That function will then be called at the end of the game and is where you should put your code to start the map vote.
- Reading [URL="https://github.com/kurt-stolle/mapvote/blob/7f10ac591c3fc9ffed3e1640936b058dbfdd9f4c/lua/excl_mapvote/sv_core.lua#L81"]the code for the map vote addon[/URL], it seems that it will automatically change the map after the vote has finished, so you won't need to worry about changing the level yourself.
Here's where you could stop reading and try to implement it yourself. If you fail, here's code that should work.
[lua]
-- this file should be placed in lua/autorun/server/ so that it is ran
-- on the server automatically.
-- register a callback for the Zombie Survival LoadNextMap hook
hook.Add("LoadNextMap", "MapVote_ZombieSurvival", function()
-- start the map vote by calling the map vote addon's Start function
EXCL_MAPVOTE:Start()
-- block the Zombie Survival default map change code
return true
end)
[/lua][/QUOTE]
Heyyyy it worked! Thanks man!
Sorry, you need to Log In to post a reply to this thread.