Sign in to follow this  
Pikachu

[HELP] Team Winning

Recommended Posts

Script Name: Team Winning

Script Problem: WARNING: [gameplay]\Winning\teams.lua:16: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Maybe there are some other problems in my script, because i couldn't test it yet due to console error. Tell me if there are some other problems with my script.

Script Code(Paste bin or code tags):

local poisonTeam = getTeamFromName ( "Poison" ) 
local ninjaTeam = getTeamFromName ( "Ninja" ) 
local poisonPlayers = getPlayersInTeam ( poisonTeam ) 
local ninjaPlayers = getPlayersInTeam ( ninjaTeam ) 
  
function Winning() 
    alivePlayers = getAlivePlayers () 
    if alivePlayers == poisonPlayers then 
        outPutChatBox("Poison Team won the round!", 255, 25, 0) 
    elseif alivePlayers == ninjaPlayers then 
        outPutChatBox("Ninja Team won the round!", 255, 25, 0) 
    elseif alivePlayers == nil then 
        outPutChatBox("#00ff00[#ffffffThe round was a tie!#00ff00]", 255, 255, 255, true) 
    end 
end 
addEventHandler("onPlayerWasted", alivePlayers, Winning) 
  
  

Script Explanation(What is it supposed to do): When the player dies, it scans if there are alive players in each team. If the team's players are dead, it outputs a message in chatbox adverting that, the team with alive players won the round. If there are no alive players in both team, it outputs a message to advert that the round was a tie.

Share this post


Link to post
local poisonTeam = getTeamFromName ( "Poison" ) 
local ninjaTeam = getTeamFromName ( "Ninja" ) 
  
function Winning ( ) 
    local poisonPlayers = countPlayersInTeam ( poisonTeam ) 
    local ninjaPlayers = countPlayersInTeam ( ninjaTeam ) 
    if ( ninjaPlayers == 0 ) then 
        outputChatBox ( "Poison Team won the round!", 255, 25, 0 ) 
    elseif ( poisonPlayers == 0 ) then 
        outputChatBox ( "Ninja Team won the round!", 255, 25, 0 ) 
    elseif ( poisonPlayers == 0 and ninjaPlayers == 0 ) then 
        outputChatBox ( "#00ff00[#ffffffThe round was a tie!#00ff00]", 255, 255, 255, true ) 
    end 
end 
addEventHandler ( "onPlayerWasted", root, Winning ) 

Try that.

Share this post


Link to post

Try

local poisonTeam = getTeamFromName("Poison") 
local ninjaTeam = getTeamFromName("Ninja") 
  
function Winning () 
     local poisonPlayers = #getAlivePlayersInTeam(poisonTeam) or 0 
     local ninjaPlayers = #getAlivePlayersInTeam(ninjaTeam) or 0 
     if (ninjaPlayers == 0) then 
          outputChatBox("Poison Team won the round!", root, 255, 25, 0) 
     elseif (poisonPlayers == 0) then 
          outputChatBox("Ninja Team won the round!", root, 255, 25, 0) 
     elseif (poisonPlayers == 0 and ninjaPlayers == 0) then 
          outputChatBox("#00ff00[#ffffffThe round was a tie!#00ff00]", root, 255, 255, 255, true) 
     end 
end 
addEventHandler("onPlayerWasted", root, Winning) 
  
function getAlivePlayersInTeam(theTeam) 
    local theTable = { } 
    local players = getPlayersInTeam(theTeam) 
  
    for i,v in pairs(players) do 
        if not isPedDead(v) then 
            theTable[#theTable+1]=v 
        end 
    end 
  
    return theTable 
end 

Share this post


Link to post

Tested it and it's not working at all :/

Well, i want it to output the message when a team wins at Mate's BaseMode 1.0

Share this post


Link to post
Tested it and it's not working at all :/

Well, i want it to output the message when a team wins at Mate's BaseMode 1.0

The BaseMode has their way to get the Alive players, the Alive player has element data

the teams also has element data, but i don't remember the team one, also this can be done in another way.

Try this

local poisonTeam = getTeamFromName("Poison") 
local ninjaTeam = getTeamFromName("Ninja") 
  
function Winning () 
     local poisonPlayers = #getAlivePlayersInTeam(poisonTeam) or 0 
     local ninjaPlayers = #getAlivePlayersInTeam(ninjaTeam) or 0 
     if (ninjaPlayers == 0) then 
          outputChatBox("Poison Team won the round!", root, 255, 25, 0) 
     elseif (poisonPlayers == 0) then 
          outputChatBox("Ninja Team won the round!", root, 255, 25, 0) 
     elseif (poisonPlayers == 0 and ninjaPlayers == 0) then 
          outputChatBox("#00ff00[#ffffffThe round was a tie!#00ff00]", root, 255, 255, 255, true) 
     end 
end 
addEventHandler("onPlayerWasted", root, Winning) 
  
function getAlivePlayersInTeam(theTeam) 
    local theTable = { } 
    local players = getPlayersInTeam(theTeam) 
  
    for i,v in pairs(players) do 
        if getElementData(v, "IsSpawned") ~= 1 then 
            theTable[#theTable+1]=v 
        end 
    end 
  
    return theTable 
end 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.