Jump to content

Weird ..


Tete omar

Recommended Posts

Hello, I've made a disguise code, the player'd be undisguised when some event is triggered, but it's kinda weird to proceed, here's code

client-side

function undisguise(player) 
    if(getPlayerTeam(player) == getTeamFromName("Blu"))then 
        triggerServerEvent("undisguising", player, "Blue") 
    elseif(getPlayerTeam(player) == getTeamFromName("Red"))then 
        triggerServerEvent("undisguising", player, "Red") 
    end 
end 
  
addEventHandler("onClientPlayerDamage", root, 
    function(damager) 
        if(damager and getElementData(damager, "playerClass") == "Spy")then 
            if(getElementData(damager, "playerState") == "playing.disguised")then 
                undisguise(damager) 
            end 
        end 
    end 
) 
  
addEventHandler("onClientPlayerWasted", root, 
    function(killer) 
        if(killer and getElementData(killer, "playerClass") == "Spy")then 
            if(getElementData(killer, "playerState") == "playing.disguised")then 
                undisguise(killer) 
            end 
        end 
    end 
) 

server-side

addEventHandler("undisguising", root, 
    function(team) 
        setElementData(client, "playerState", "playing") 
        if(team == "Blue")then 
            addPedClothes(client, "balaclava", "balaclava", 17) 
            addPedClothes(client, "suit1blue", "suit1", 0) 
            addPedClothes(client, "suit1trblue", "suit1tr", 2) 
            addPedClothes(client, "sneakerproblu", "sneaker", 3) 
            setPlayerNametagText(client, getPlayerName(client)) 
            setElementModel(client, getElementData(client, "playerSkin")) 
            setPlayerNametagColor(client, 0, 0, 255) 
        elseif(team == "Red")then 
            addPedClothes(client, "balaclava", "balaclava", 17) 
            addPedClothes(client, "suit1red", "suit1", 0) 
            addPedClothes(client, "suit1trred", "suit1tr", 2) 
            addPedClothes(client, "sneakerprored", "sneaker", 3) 
            setPlayerNametagText(client, getPlayerName(client)) 
            setElementModel(client, getElementData(client, "playerSkin")) 
            setPlayerNametagColor(client, 255, 0, 0) 
        end 
    end 
) 

in client-side when a player damages/kills some other player it'd be triggered to server-side for both??

Link to comment

onClientPlayerDamage will be trigger for all clients, so all the clients will trigger the server event. Just check if you want to undisguise the player you hit, if so, trigger the server event and pass the player who you want to undesguise (do not undesguise the client, because that would be you).

Link to comment

No i don't want to undisguise the player i hit, i want when the player who undisguised is damaging/killing another player, the player who is disguised would be undisguised, and how about attaching 'localPlayer' to both events instead of 'root'?

Link to comment
function undisguise(player) 
    if(getPlayerTeam(player) == getTeamFromName("Blu"))then 
        triggerServerEvent("undisguising", player, "Blue") 
    elseif(getPlayerTeam(player) == getTeamFromName("Red"))then 
        triggerServerEvent("undisguising", player, "Red") 
    end 
end 
  
addEventHandler("onClientPlayerDamage", localPlayer, 
    function(damager) 
        if(damager and getElementData(damager, "playerClass") == "Spy")then 
            if(getElementData(damager, "playerState") == "playing.disguised")then 
                undisguise(damager) 
            end 
        end 
    end 
) 
  
addEventHandler("onClientPlayerWasted", localPlayer, 
    function(killer) 
        if(killer and getElementData(killer, "playerClass") == "Spy")then 
            if(getElementData(killer, "playerState") == "playing.disguised")then 
                undisguise(killer) 
            end 
        end 
    end 
) 

I've tried with this, but it's just triggering for the player who's got damaged not the damager :roll:

Link to comment

You're not doing what I said.

In that case, check if localPlayer is disguised and is attacker (damager), then send the event to server.

So, if YOU are the attacking Spy and YOU are disguised, then tell the server to undisguise you.

Link to comment

Hi, it worked yes and thanks, but sometimes when the damager undiguises, the tag name color won't be changed, or tag name text won't be their name, and sometimes it totally work, but its fine with clothes, do you know know how do i fix that?

edit :

here's my code

client-side

addEventHandler("onClientPlayerDamage", root, 
    function(damager) 
        if(damager and  damager == localPlayer and getElementData(damager, "playerClass") == "Spy")then 
            if(getElementData(damager, "playerState") == "playing.invisible")then 
                showingWhenFire(damager) 
            elseif(getElementData(damager, "playerState") == "playing.disguised")then 
                undisguise(damager) 
            end 
        end 
    end 
) 
  
addEventHandler("onClientPlayerWasted", root, 
    function(killer) 
        if(killer and killer == localPlayer and getElementData(killer, "playerClass") == "Spy")then 
            if(getElementData(killer, "playerState") == "playing.invisible")then 
                showingWhenFire(killer) 
            elseif(getElementData(killer, "playerState") == "playing.disguised")then 
                undisguise(killer) 
            end 
        end 
    end 
) 

server-side

addEventHandler("undisguising", root, 
    function(team) 
        setElementData(client, "playerState", "playing") 
        if(team == "Blue")then 
            addPedClothes(client, "balaclava", "balaclava", 17) 
            addPedClothes(client, "suit1blue", "suit1", 0) 
            addPedClothes(client, "suit1trblue", "suit1tr", 2) 
            addPedClothes(client, "sneakerproblu", "sneaker", 3) 
            setPlayerNametagText(client, getPlayerName(client)) 
            setElementModel(client, getElementData(client, "playerSkin")) 
            setPlayerNametagColor(client, 0, 0, 255) 
            outputChatBox(getPlayerName(client) .. " undisguised") 
        elseif(team == "Red")then 
            addPedClothes(client, "balaclava", "balaclava", 17) 
            addPedClothes(client, "suit1red", "suit1", 0) 
            addPedClothes(client, "suit1trred", "suit1tr", 2) 
            addPedClothes(client, "sneakerprored", "sneaker", 3) 
            setPlayerNametagText(client, getPlayerName(client)) 
            setElementModel(client, getElementData(client, "playerSkin")) 
            setPlayerNametagColor(client, 255, 0, 0) 
            outputChatBox(getPlayerName(client) .. " undisguised") 
        end 
    end 
) 

Link to comment

For people browsing this topic and trying to help, Tete and I have spoken about this problem on IRC and showed me some more code which may have caused some issues, so ignore the above code which is perfectly fine.

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