Jump to content

Command execute inside Script


BieHDC

Recommended Posts

Hello,

i want to make inside of a script something that starts commands like /mcreate in chat or mcreate in F8 console.

In console this works but inside script it doesnt and i dont know why?

It schould delete a current object, create a Ramp, rorate it.

The commands after "do" are in the same script.

I hope you will help me again :)

Here is one of that i already tried:

  
function makejump (player) 
do mdestroy 
do mcreate 1655 
do rz -130 
end 
addCommandHandler( "mjump", makejump ) 
  

Link to comment

Is this what you want?

The command triggers a function, which deletes an existing ramp or creates a new one with the z-rotation -130.

addCommandHandler("mjump", 
    function(player, cmd) 
        if (isElement(ramp)) then 
            destroyElement(ramp) 
            outputChatBox("* Ramp object destroyed.", player, 255, 0, 0, false) 
        else 
            local x, y, z = getElementPosition(player) 
            local rx, ry, rz = getElementRotation(player) 
            ramp = createObject(1655, x, y, z, rx, ry, -130) 
            setElementInterior(ramp, getElementInterior(player)) 
            setElementDimension(ramp, getElementDimension(player)) 
            outputChatBox("* Ramp object created.", player, 0, 255, 0, false) 
        end 
    end 
) 

Link to comment

No i only wanna execute the 3 commands not more.

I will post the full script

Everything works exept last funktion

  
local playerobj = {} 
local marker = {} 
objectid = {} 
maxobjects = 500 
  
function playerLeave () 
    setElementData ( source, "tempbuilder", false ) 
    setElementData ( source, "permbuilder", false ) 
end 
  
function playerJoin () 
    setElementData ( source, "tempbuilder", false ) 
    setElementData ( source, "permbuilder", false ) 
    local pname = getClientName(source) 
    if (pname == "example") 
    or (pname == "example2") 
    then 
        setElementData ( source, "permbuilder", true ) 
    end 
end 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        setElementData ( v, "tempbuilder", false ) 
        setElementData ( v, "permbuilder", false ) 
        local pname = getClientName(v) 
    if (pname == "example") 
    or (pname == "example2") 
        then 
            setElementData ( v, "permbuilder", true ) 
        end 
    end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), thisResourceStart ) 
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerLeave ) 
  
function createCurrentObject (player,cmd,objid) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        outputChatBox ( "You are already editing an object.  Please save or delete to make another.", player ) 
    else 
        local x, y, z = getElementPosition(player) 
        destroyMObj (player) 
        playerobj[player] = createObject(tonumber(objid), x + 5, y + 5, z - 1) 
        if marker[player] then destroyElement(marker[player]) end 
        if playerobj[player] then 
            marker[player] = createMarker ( x, y, z, "arrow", 5, 255, 255, 0, 255) 
            attachElementToElement ( marker[player], playerobj[player], 0, 0, 10) 
        else 
            outputChatBox ( "" ..objid.. " does not appear to be a valid model ID.", player ) 
        end 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "mcreate", createCurrentObject ) 
  
function moveObjZ (player,cmd,newz) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        local x, y, z = getElementPosition(playerobj[player]) 
        moveObject ( playerobj[player], 200, x, y, z + tonumber(newz) ) 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "oz", moveObjZ ) 
  
function moveObjX (player,cmd,newx) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        local x, y, z = getElementPosition(playerobj[player]) 
        moveObject ( playerobj[player], 200, x + tonumber(newx), y, z ) 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "ox", moveObjX ) 
  
function moveObjY (player,cmd,newy) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        local x, y, z = getElementPosition(playerobj[player]) 
        moveObject ( playerobj[player], 200, x, y + tonumber(newy), z ) 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "oy", moveObjY ) 
  
function moveRotZ (player,cmd,newrz) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        local x, y, z = getElementPosition(playerobj[player]) 
        moveObject ( playerobj[player], 200, x, y, z, 0, 0, tonumber(newrz) ) 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "rz", moveRotZ ) 
  
function moveRotX (player,cmd,newrx) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        local x, y, z = getElementPosition(playerobj[player]) 
        moveObject ( playerobj[player], 200, x, y, z, tonumber(newrx), 0, 0 ) 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "rx", moveRotX ) 
  
function moveRotY (player,cmd,newry) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        local x, y, z = getElementPosition(playerobj[player]) 
        moveObject ( playerobj[player], 200, x, y, z, 0, tonumber(newry), 0 ) 
    end 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "ry", moveRotY ) 
  
function destroyMObj (player,cmd) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true) or (getElementData ( player, "tempbuilder" ) == true) then  
    if playerobj[player] then 
        for i=0,maxobjects do 
            if objectid[i] == playerobj[player] then  
                local numstr = tostring(i) 
                outputChatBox ( "Object ID deleted: " ..numstr.. "", player ) 
                local succeed = destroyElement(playerobj[player]) 
                if marker[player] then destroyElement(marker[player]) end 
                objectid[i] = nil 
                playerobj[player] = nil 
                break 
            end 
        end 
    end 
    if marker[player] then destroyElement(marker[player]) end 
    if playerobj[player] then destroyElement(playerobj[player]) end 
    playerobj[player] = nil 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "mdestroy", destroyMObj ) 
  
function clearObjects (player) 
if ( hasObjectPermissionTo ( player, "function.unbanSerial", true)) or (getElementData ( player, "permbuilder" ) == true)  then  
    for i=0,maxobjects do 
        if objectid[i] then 
            destroyElement(objectid[i]) 
        end 
    end 
    objectid = nil 
    objectid = {} 
    local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        if marker[v] then destroyElement(marker[v]) end 
        if playerobj[v] then destroyElement(playerobj[v]) end 
        playerobj[v] = nil 
    end 
    if marker[player] then destroyElement(marker[player]) end 
    if playerobj[player] then destroyElement(playerobj[player]) end 
    playerobj[player] = nil 
    outputChatBox ( "Map cleared.", player ) 
else  
    outputChatBox ( "You do not have permission to build.", player ) 
end 
end 
addCommandHandler( "mclear", clearObjects ) 
  
function makejump (player) 
do mdestroy 
do mcreate 1655 
do rz -130 
end 
addCommandHandler( "mjump", makejump ) 
  

Link to comment

Would that look like:

  
function makejump (player) 
addCommandHandler("cmd", mdestroy) 
addCommandHandler("cmd", mcreate 1655) 
addCommandHandler("cmd", rz -130) 
end 
addCommandHandler( "mjump", makejump ) 
  

Does it execute command "mdestroy" and then "mcreate 1655 .....

It schould execute the commands like i type in in F8 Command Panel

Link to comment

Would it look like this?

  
function makejump(plr) 
  executeCommandHandler("mdestroy", plr) 
  executeCommandHandler("mcreate 1655", plr) 
  executeCommandHandler("rz -130", plr) 
end 
addCommandHandler("mjump", makejump) 
  

Link to comment
  • Moderators
function makejump(plr) 
  executeCommandHandler("mdestroy", plr) 
  executeCommandHandler("mcreate", plr,1655) 
  executeCommandHandler("rz", plr,-130) 
end 
addCommandHandler("mjump", makejump) 
  

Edited by Guest
Link to comment
  • Moderators

It depends what the script request.

If the script needs to kick a player or remove a file. Yes then it needs admin rights.

If the script gives an error like that, it is missing his rights.

resource.NAME

Link to comment

Now i get this:

WARNING: [gamem.....\offedit.lua:185: Bad argument @ ´executeCom..ler´[Expected element at argument 2, got number ´1655´]

some for line 186 with -130

So the numbers are not translated sucsessfully?

Link to comment
  • Moderators
function makejump(plr) 
  executeCommandHandler("mdestroy", plr) 
  executeCommandHandler("mcreate", plr,1655) 
  executeCommandHandler("rz", plr,-130) 
end 
addCommandHandler("mjump", makejump) 
  

Link to comment
  • 2 weeks later...

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