Jump to content

script not working(setPedOnFire)


Recommended Posts

hello

i wanted to make a script with which i could set a player on fire by doing /fire partofplayername

however it doesnt work

function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function trollRandomPlayerWithFire(commandName,thePlayer,theTarget) 
  
local target = getPlayerFromNamePart ( theTarget ) 
local troller = getPlayerName(thePlayer) 
     if ( theTarget ) then 
             setPedOnFire(theTarget,true) 
             outputChatBox("You've been set on fire by" .. troller .. "",255,0,0) 
             outputDebugString( .. target .. "has been set on fire by" .. troller .. "" ) 
   end 
end 
addCommandHandler("fire",trollRandomPlayerWithFire) 

this is error

[20:34:18] SCRIPT ERROR: trollcmds\fire.lua:20: unexpected symbol near '..'

[20:34:18] ERROR: Loading script failed: trollcmds\fire.lua:20: unexpected symbol near '..'

i've tried commenting out the line with outputDebugString just to see would this thing even work,but this script didnt work at all,and didnt give any error.

edit: wrote a wrong line in () at function line but gives this error

[20:38:14] WARNING: trollcmds\fire.lua:16: Bad argument @ 'getPlayerName' [Expected element at argument 1, got string 'fire']

please help

Link to comment
function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function trollRandomPlayerWithFire(commandName,thePlayer,theTarget) 
  
local target = getPlayerFromNamePart ( theTarget ) 
local troller = getPlayerName(thePlayer) 
     if ( theTarget ) then 
             setPedOnFire(theTarget,true) 
             outputChatBox("You've been set on fire by" .. troller .. "",255,0,0) 
             outputDebugString( target .. "has been set on fire by" .. troller .. "" ) -- If your argument is first what you want to add in chat/debug then you don't have to put ".." before it or if it's the last argument and it close your message then you don't have to put ".." after it. 
   end 
end 
addCommandHandler("fire",trollRandomPlayerWithFire) 

Link to comment
You have also switched around the arguments for the source and the command name. Try
  
function trollRandomPlayerWithFire(thePlayer,commandName,theTarget) 
  

actually i tried that at start but it didnt work at all lol.

now my code is like this

function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function trollRandomPlayerWithFire(commandName,thePlayer,theTarget) 
  
local target = getPlayerFromNamePart ( theTarget ) 
local troller = getPlayerName(root,thePlayer) 
     if ( theTarget ) then 
             setPedOnFire(target,true) 
             outputChatBox("You've been set on fire by" .. troller .. "",root,255,0,0,true) 
             outputDebugString( target .. "has been set on fire by" .. troller .. "" ) 
   end 
end 
addCommandHandler("fire",trollRandomPlayerWithFire) 

it makes the fire but this is still an error

[21:41:36] ERROR: trollcmds\fire.lua:19: attempt to concatenate local 'troller' (a boolean value)

also it doesnt output on chatbox that i've been set on fire by *name*

Link to comment
local troller = getPlayerName(root,thePlayer) - wat? 

There root isn't needed. Try this:

function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function trollRandomPlayerWithFire(commandName,thePlayer,theTarget) 
  
local target = getPlayerFromNamePart ( theTarget ) 
local troller = getPlayerName( getLocalPlayer() ) 
     if ( theTarget ) then 
             setPedOnFire(target,true) 
             outputChatBox("You've been set on fire by" .. troller .. "",root,255,0,0,true) 
             outputDebugString( target .. "has been set on fire by" .. troller .. "" ) 
   end 
end 
addCommandHandler("fire",trollRandomPlayerWithFire) 

Link to comment
function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
      
function trollRandomPlayerWithFire(playerSource,commandName,theTarget) 
        local target = getPlayerFromNamePart(theTarget) -- this function returns the element representing the player, not a name. 
        local troller = getPlayerName(playerSource) 
        if (target) then 
            setPedOnFire(target,true) 
            outputChatBox("You've been set on fire by" .. troller .. "!",root,255,0,0,true) 
            outputDebugString(getPlayerName(target) .. "has been set on fire by" .. troller .. "" ) 
        end 
end 
addCommandHandler("fire",trollRandomPlayerWithFire) 

Tested this serverside and it works. You needed to switch around the two arguments in line 13, and you used theTarget in stead of target in line 16

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