Jump to content

Help with isElementWithinMarker


Hutchpe

Recommended Posts

Hi everyone

I'm having some trouble working out what's wrong with my script. What it is supposed to do is create a marker, when a player enters it check if they are on a certain team and if they are then reload 2 resources and spawn the player at a spawn point. At the moment it is creating the marker but nothing happens when a player from either team enters it.

objectivemarker = createMarker( 2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255 ) 
function objective(thePlayer, matchingDimensions) 
local team = getPlayerTeam (source) 
    if isElementWithinMarker(thePlayer, objectivemarker) and (team == teamMexicans) then 
        outputChatBox ( "Mexicans Have Won!" ) 
        outputChatBox ( "Loading Next Round! Please Wait" ) 
        setTimer ( function() 
            local players = getElementByType ( "player" ) 
            reloadResource "Mexihunt" 
            reloadResource "Teamblips" 
            spawnPlayer( players, 1544.4279785156, -1353.2464599609, 329.47442626953 ) 
        end, 5000, 1 ) 
    else outputChatBox ( "You aren't a Mexican" ) 
    end 
end 
addEventHandler ( "objective", getRootElement(), objective ) 

I'm not getting any errors in the console with the following script.

Any help is greatly appreciated.

(Also sorry for my recent spate of requests for help :oops: . I'm rather new to programming and learning as quickly as I can :) )

Link to comment

Line 138 has the following

local team = getPlayerTeam (source) 

This is start of the script as it is currently

function objective(thePlayer, matchingDimensions) 
local team = getPlayerTeam (source) 
    if isElementWithinMarker(thePlayer, objectivemarker) and getTeamName(team) == teamMexicans then 

With the above script I am now getting the previous error and the below error I go into the marker

WARNING: Mexihunt\script.lua:139: Bad argument @ 'getTeamName'
Edited by Guest
Link to comment
    objectivemarker = createMarker( 2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255 ) 
    function objective(thePlayer, matchingDimensions) 
    local team = getPlayerTeam(source) 
        if isElementWithinMarker(thePlayer, objectivemarker) and (team == teamMexicans) then 
            outputChatBox ( "Mexicans Have Won!" ) 
            outputChatBox ( "Loading Next Round! Please Wait" ) 
            setTimer ( function() 
                local players = getElementByType ( "player" ) 
                reloadResource "Mexihunt" 
                reloadResource "Teamblips" 
                spawnPlayer( players, 1544.4279785156, -1353.2464599609, 329.47442626953 ) 
            end, 5000, 1 ) 
        else outputChatBox ( "You aren't a Mexican" ) 
        end 
    end 
    addEventHandler ( "objective", getRootElement(), objective ) 

Link to comment

Just got on my computer, your code was and is a mess. Try this.

You need to be in the "Mexicans" team to make it work. If you don't have that team, then create it using createTeam.

Server-side

local objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255) 
  
addEventHandler("onMarkerHit", objectivemarker, 
    function(hitElement, matchingDimension) 
        if getElementType(hitElement) == "player" and matchingDimension then 
            if getPlayerTeam(hitElement) == "Mexicans" then 
                outputChatBox("Mexicans have won!", root, 0, 255, 0, false) 
                outputChatBox("Loading next round! Please wait...", root, 255, 180, 0, false) 
                setTimer(function() 
                    for i,v in ipairs(getElementsByType("player")) do 
                        restartResource(getResourceFromName("Mexihunt")) 
                        restartResource(getResourceFromName("Teamblips")) 
                        spawnPlayer(v, 1544.4279785156, -1353.2464599609, 329.47442626953) 
                    end 
                end, 5000, 1) 
            else 
                outputChatBox("You aren't in the Mexicans team.", hitElement, 255, 0, 0, false) 
            end 
        end 
    end 
) 

Link to comment

try this p:

for i,player in ipairs(getElementsByType("player")) do 
if(getTeamName(getPlayerName(player)=="Mexicans")then 
local objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255,player) 
end 
end 
      
    addEventHandler("onMarkerHit", objectivemarker, 
        function(hitElement, matchingDimension) 
            if getElementType(hitElement) == "player" and matchingDimension then 
                    outputChatBox("Mexicans have won!", root, 0, 255, 0, false) 
                    outputChatBox("Loading next round! Please wait...", root, 255, 180, 0, false) 
                    setTimer(function() 
                        for i,v in ipairs(getElementsByType("player")) do 
                            restartResource(getResourceFromName("Mexihunt")) 
                            restartResource(getResourceFromName("Teamblips")) 
                            spawnPlayer(v, 1544.4279785156, -1353.2464599609, 329.47442626953) 
                        end 
                    end, 5000, 1) 
                end 
            end 
        end 
    ) 

Link to comment
try this p:
for i,player in ipairs(getElementsByType("player")) do 
if(getTeamName(getPlayerName(player)=="Mexicans")then 
local objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255,player) 
end 
end 

Wrong a little. And it updates rarely so new players can't see the marker.

addEventHandler("onPlayerSpawn", root, 
    function() 
        if getPlayerTeam(source) and getTeamName(getPlayerTeam(source)) == "Mexicans" then 
            objectivemarker = createMarker(2491.2993164063, -1665.7626953125, 12.34375, "cylinder", 2.0, 255, 0, 0, 255, source) 
        end 
    end 
) 
  
addEventHandler("onMarkerHit", objectivemarker, 
    function(hitElement, matchingDimension) 
        if getElementType(hitElement) == "player" and matchingDimension then 
            outputChatBox("Mexicans have won!", root, 0, 255, 0, false) 
            outputChatBox("Loading next round! Please wait...", root, 255, 180, 0, false) 
            setTimer(function() 
                for i,v in ipairs(getElementsByType("player")) do 
                    restartResource(getResourceFromName("Mexihunt")) 
                    restartResource(getResourceFromName("Teamblips")) 
                    spawnPlayer(v, 1544.4279785156, -1353.2464599609, 329.47442626953) 
                end 
            end, 5000, 1) 
        end 
    end 
) 

Edited by Guest
Link to comment

Thankyou so much myonlake and MJNONFIK and sorry that my code was such a mess :oops: . Anyway I have tried both your scripts.

myonlake yours says that I'm not on the Mexican team even though I am.

MJNONFIK yours gives me the following errors in the console when I start the resource.

Quote
SCRIPT ERROR: Mexihunt\script.Lua:138: ')' expected near 'then'
Quote
WARNING: Loading script failed: Mexihunt\script.Lua:138: ')' expected near 'then'
Link to comment

The team name is Mexicans so I'm not sure why it isn't working. Below is the code I have to create the teams and then for the player to join the teams.

function createTeamsOnStart () 
    createBlip ( 2491.2993164063, -1665.7626953125, 13.34375, 3 ) --snuck this in here 
    BorderControl = createTeam ( "Border Control", 0, 0, 255 ) 
    Mexicans = createTeam ( "Mexicans", 255, 0, 0 ) 
end 
addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart) 

addCommandHandler("joinmexicans", 
function(thePlayer, commandName) 
    spawnPlayer(thePlayer, 364.96685791016, 2507.6645507813,16.496768951416, 0,173,0,0,Mexicans) 
    outputChatBox("You are a Mexican.",thePlayer) 
    end 
) 
  
addCommandHandler("joinbordercontrol", 
function(thePlayer, commandName) 
    spawnPlayer(thePlayer, -1602.9626464844,660.72479248047,7.1875, 0,71,0,0,BorderControl) 
    outputChatBox("You are the Border Control.",thePlayer) 
    end 
) 

Is there anything wrong with the code I have here that would be causing your script not to work?

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