quality Posted May 16, 2015 Share Posted May 16, 2015 (edited) Hi guys. I have the following. The script works perfectly. but. function toggleGodMode(thePlayer) local account = getPlayerAccount(thePlayer) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then if getElementData(thePlayer,"invincible") then setElementData(thePlayer,"invincible",false) outputChatBox("GOD if off",thePlayer,0,255,0) else setElementData(thePlayer,"invincible",true) outputChatBox("GOD is on",thePlayer,0,255,0) end end end addCommandHandler("god",toggleGodMode) the server side. How do I make so I do not need to type each time /god ? How do I make it on start.? I tried addEventHandler( "onPlayerLogin", getRootElement(), toggleGodMode ) instead of the addCommandHandler, what am I doing wrong? the client side. addEventHandler ( "onClientPlayerDamage",root, function () if getElementData(source,"invincible") then cancelEvent() end end) addEventHandler("onClientPlayerStealthKill",localPlayer, function (targetPlayer) if getElementData(targetPlayer,"invincible") then cancelEvent() end end) Edited May 17, 2015 by Guest Link to comment
AMARANT Posted May 16, 2015 Share Posted May 16, 2015 function toggleGodMode() local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then if getElementData(source,"invincible") then setElementData(source,"invincible",false) outputChatBox("GOD if off",source,0,255,0) else setElementData(source,"invincible",true) outputChatBox("GOD is on",source,0,255,0) end end end addEventHandler("onPlayerLogin",getRootElement(),toggleGodMode) Link to comment
quality Posted May 17, 2015 Author Share Posted May 17, 2015 function toggleGodMode() local account = getPlayerAccount(source) if (not account or isGuestAccount(account)) then return end local accountName = getAccountName(account) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then if getElementData(source,"invincible") then setElementData(source,"invincible",false) outputChatBox("GOD if off",source,0,255,0) else setElementData(source,"invincible",true) outputChatBox("GOD is on",source,0,255,0) end end end addEventHandler("onPlayerLogin",getRootElement(),toggleGodMode) I appreacite that man. Fast and right. I have a question. What is it that I did not do right? It seems like I put the same eventHandler as you did, now everything works perfectly, when I did it, it never did, and the GOD is on did not even pop up in chat, only if i used the /god. What is it exactly you changed?" Thanks! Link to comment
AMARANT Posted May 17, 2015 Share Posted May 17, 2015 Actually it was the only one argument - thePlayer. You see, the event "onPlayerLogin" returns player element named as source. So you don't need thePlayer argument anymore, especially when it returns nil (like in your case). Here you can find that source element and learn what it means. Btw, On MTA Wikia you can find every source element of every event. Link to comment
Walid Posted May 17, 2015 Share Posted May 17, 2015 simply it can be like this function toggleGodMode(_,cur) local accountName = getAccountName(cur) if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( "Admin" ) ) ) then if getElementData(source,"invincible") then setElementData(source,"invincible",false) outputChatBox("GOD if off",source,0,255,0) else setElementData(source,"invincible",true) outputChatBox("GOD is on",source,0,255,0) end end end addEventHandler("onPlayerLogin",getRootElement(),toggleGodMode) 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