Jump to content

[SOLVED]onResourceStart


quality

Recommended Posts

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 by Guest
Link to comment
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
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

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

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

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...