CJGrove Posted February 16, 2008 Share Posted February 16, 2008 Hello, I tried to make a script that would it make impossible for guests to spawn. (enter is spawn button) But i got some errors but it is like this documented on wiki. script: function isguest ( playerSource ) sourceAccount = getClientAccount ( playerSource ) if isGuestAccount ( sourceAccount ) then toggleControl ( source, "enter", false ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else toggleControl ( source, "enter", true ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () toggleControl ( source, "enter", true ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () toggleControl ( source, "enter", false ) end addEventHandler("onClientLogout",getRootElement(),guestlogout) Errors: [11:37:00] WARNING: functionscript.lua: Bad argument @ 'getClientAccount' - Line: 815 [11:37:00] WARNING: functionscript.lua: Bad argument @ 'isGuestAccount' - Line: 816 Please help me. Greetings CJGrove Link to comment
Mr.Hankey Posted February 16, 2008 Share Posted February 16, 2008 you don't have to define any arguments in the function just use: function isguest ( ) sourceAccount = getClientAccount ( source ) if isGuestAccount ( sourceAccount ) then toggleControl ( source, "enter", false ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else toggleControl ( source, "enter", true ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) The onPlayerJoin event doesn't pass any arguments it just gives you the source and that is the player that joined just like the wiki says. http://development.mtasa.com/index.php?title=OnPlayerJoin Link to comment
CJGrove Posted February 16, 2008 Author Share Posted February 16, 2008 Thanks for fast and good reply Mr.Hankey, Still got a lot to learn i gues... But were not quite there yet Using this code: function isguest ( ) sourceAccount = getClientAccount ( source ) if isGuestAccount ( sourceAccount ) then toggleControl ( source, "enter", false ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else toggleControl ( source, "enter", true ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () toggleControl ( source, "enter", true ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () toggleControl ( source, "enter", false ) end addEventHandler("onClientLogout",getRootElement(),guestlogout) Getting this error: [12:04:29] WARNING: functionscript.lua: Bad 'player' pointer @ 'enableControl'(1) - Line: 826 Thanks in advance, CJGrove Link to comment
Mr.Hankey Posted February 16, 2008 Share Posted February 16, 2008 the problem is that the source of the onClientLogin is the ClientElement and not the PlayerElement but you need the playerElement for the toggleControl fucntion try his: function isguest ( ) sourceAccount = getClientAccount ( source ) if isGuestAccount ( sourceAccount ) then toggleControl ( source, "enter", false ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else toggleControl ( source, "enter", true ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () local player = getPlayerFromNick (getClientName (source)) toggleControl ( player, "enter", true ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () local player = getPlayerFromNick (getClientName (source)) toggleControl ( player, "enter", false ) end addEventHandler("onClientLogout",getRootElement(),guestlogout) hm... i have no idea if it works but give it a try^^ Link to comment
CJGrove Posted February 16, 2008 Author Share Posted February 16, 2008 (edited) (Forgot what was in it.) Edited February 16, 2008 by Guest Link to comment
Mr.Hankey Posted February 16, 2008 Share Posted February 16, 2008 Hm... maybe you should use the (un)bindKey functions and unbind the "enter" key if someone isn't registered or not logged in and bind it to the spawn function if he logged in. Example: function isguest ( ) sourceAccount = getClientAccount ( source ) if isGuestAccount ( sourceAccount ) then unbindKey ( source, "enter" ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else bindKey( source, "enter", --[[enter here the function that spawns the player]] ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () local player = getPlayerFromNick (getClientName (source)) bindKey( player, "enter", --[[enter here the function that spawns the player]] ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () local player = getPlayerFromNick (getClientName (source)) unbindKey( player, "enter") end addEventHandler("onClientLogout",getRootElement(),guestlogout) Link to comment
CJGrove Posted February 16, 2008 Author Share Posted February 16, 2008 (edited) Error: [12:45:09] SCRIPT ERROR: ...n/MTA Server/mods/deathmatch/resources/functionscript/functionscript.lua:820: unexpected symbol near ')' [12:45:09] INFO: Loading script failed: ...n/MTA Server/mods/deathmatch/resources/functionscript/functionscript.lua:820: unexpected symbol near ')' Edit: Using this code function isguest ( ) sourceAccount = getClientAccount ( source ) if isGuestAccount ( sourceAccount ) then unbindKey ( player, "enter" ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else bindKey ( player, "enter", "down", cdm_spawn, player ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () local player = getPlayerFromNick (getClientName (source)) bindKey ( player, "enter", "down", cdm_spawn, player ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () local player = getPlayerFromNick (getClientName (source)) unbindKey( player, "enter") end addEventHandler("onClientLogout",getRootElement(),guestlogout ) Getting this error: [12:50:10] WARNING: cdm.lua: Bad argument @ 'unbindKey' - Line: 259 Edit2: Using this code function isguest ( ) player = getClientAccount ( source ) if isGuestAccount ( sourceAccount ) then unbindKey ( player, "enter" ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else bindKey ( player, "enter", "down", cdm_spawn, player ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () local player = getPlayerFromNick (getClientName (source)) bindKey ( player, "enter", "down", cdm_spawn, player ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () local player = getPlayerFromNick (getClientName (source)) unbindKey( player, "enter") end addEventHandler("onClientLogout",getRootElement(),guestlogout ) Getting no errors but no effect what so ever. Edited February 16, 2008 by Guest Link to comment
Mr.Hankey Posted February 16, 2008 Share Posted February 16, 2008 you should really read the code instead of just copy'n'pasting it and repost the erros that occure... where the --[[enter here the function that spawns the player]] comment is you have to replace it with the function that spawns the player Link to comment
lil Toady Posted February 16, 2008 Share Posted February 16, 2008 local player = getPlayerFromNick (getClientName (source)) Erm? that's the same as local player = source but with the unnesessary code The problem is that 'enter' is not a control i suppose. Link to comment
CJGrove Posted February 16, 2008 Author Share Posted February 16, 2008 Read edit2. Edit: function isguest ( ) player = getClientAccount ( source ) if isGuestAccount ( player ) then unbindKey ( player, "enter", "down", cdm_spawn ) outputChatBox ( "You need to login before you can spawn. (/login password) (/register password)", sourceAccount ) else bindKey ( player, "enter", "down", cdm_spawn ) end end addEventHandler ( "onPlayerJoin", getRootElement(), isguest ) function guestlogin () local player = getPlayerFromNick (getClientName (source)) bindKey ( player, "enter", "down", cdm_spawn ) end addEventHandler("onClientLogin",getRootElement(),guestlogin) function guestlogout () local player = getPlayerFromNick (getClientName (source)) unbindKey( player, "enter", "down", cdm_spawn ) end addEventHandler("onClientLogout",getRootElement(),guestlogout ) [12:58:02] WARNING: cdm.lua: Bad 'player' pointer @ 'unbindKey'(1) - Line: 259 Link to comment
CJGrove Posted February 16, 2008 Author Share Posted February 16, 2008 The problem is that 'enter' is not a control i suppose. Wait is enter not a control? It is becose it stands in the script of cdm: Copied from cdm. bindKey ( player, "enter", "down", cdm_spawn, player ) Link to comment
CJGrove Posted February 16, 2008 Author Share Posted February 16, 2008 Nevemind this, I got it working. It's realy silly acutly. The key was bind in an other function (original). Forgot to delete that line so. It works now thanks for evrything . Greetings CJGrove. 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