Jump to content

Duel System


Recommended Posts

Hello, I am new to the forum, and I see a script in some servers that it is possible to invite a player to a duel / x1, and works as follows: / duel ID (id of the player). I have a script that adds a number ID for each player:

The script works as follows:

/ duel ID

/ duel accept

/ duel decline

[You already invited the player]

[ duel in progress]

When the duel starts appear in chat "The player ..getPlayerName .. (ID:" .. (getPlayerID (source) or "???") .. ") was challenged by ..getPlayerName .. (ID:". . (getPlayerID (source) or "???") .. ")

2 Duel Players get weapons

26, 24, 28 and 31

The place where the two players are moved to the duel / x1 are in size "1" and to accept the second event will go to a map of the location that is to choose the script manually added the cords

function getPlayerFromID(id) 
return call(getResourceFromName("game_id"), "getPlayerFromID", tonumber(id)) 
end 
  
function getPlayerID(player) 
return  getElementData(player,"id") 
end 

Who can help me contact me on skype: giovane.martins6

Link to comment
function Duel(player, id) 
      if id then 
         target = getPlayerFromID(id) 
         if target == false or target == nil then 
            outputChatBox("That id has not connected", player, 255, 0, 0) 
         end 
       outputChatBox("You already invited the player", player, 255, 0, 0) 
     end 
 end 
addCommandHandler("duel", Duel) 
  
function Accept(player) 
      if  Duel() then 
         ouputChatBox("The player"..getPlayerName(player).."("..getPlayerID(player)..")".."was challenged by"...getPlayerName(source).."("..getPlayerID(source)..")", root, 83, 138, 165) 
        giveWeapon(source, 26, 250) 
        giveWeapon(source, 24, 250) 
        giveWeapon(source, 28, 250) 
        giveWeapon(source, 31, 250) 
        setElementInterior(source, x,y,z) 
        setElementInterior(player, x,y,z) 
       end 
    else  
       outputChatBox("Duel in progress", player, 255, 0, 0) 
end 
addCommandHandler("duel accept", Accept) 
  
function Decline(player) 
      Duel() 
      outputChatBox("The player has decline the invite", player, 83, 138, 165) 
end 
addCommandHalder("duel decline", Decline) 

Edited by Guest
Link to comment

Well, I'm not sure Dimos7 if it work. I also made my version of it. Didn't test.

function getPlayerFromID ( id ) 
    return call ( getResourceFromName ( "game_id" ), "getPlayerFromID", tonumber ( id ) ); 
end 
  
function getPlayerID ( player ) 
    return  getElementData ( player, "id" ); 
end 
  
duelTable = { }; 
fightPlace = { x, y, z, interior, dimension }; 
function tpToFightPlace ( element ) 
    setElementPosition ( element, fightPlace[1], fightPlace[2], fightPlace[3] ); 
    setElementInterior ( element, fightPlace[4] ); 
    setElementDimension ( element, fightPlace[5] ); 
    giveWeapon ( element, 26 ); 
    giveWeapon ( element, 24 ); 
    giveWeapon ( element, 28 ); 
    giveWeapon ( element, 31 ); 
end 
  
function duel ( player, cmd, arg ) 
    if ( tonumber ( arg ) ) then 
        local p = getPlayerFromID ( id ); 
        if ( isElement ( p ) ) then 
            if ( not duelTable [ p ] ) then 
                duelTable [ p ] = player; 
                outputChatBox ( "You sent invite to " .. getPlayerName ( p ) .. "!", player, 255, 255, 255, true ) 
            else 
                outputChatBox ( "This player is already challanged!", player, 255, 0, 0, true ); 
            end 
        else 
            outputChatBox ( "Unable to find player with this ID!", player, 255, 0, 0, true ); 
        end 
    end 
     
    if ( arg == "accept" ) then 
        local p = duelTable [ player ]; 
        if ( isElement ( p ) ) then 
            outputChatBox ( "The player " .. getPlayerName ( player ) .. " (ID:" .. getPlayerID ( player ) .. ") was challanged by " .. getPlayerName ( p ) .. " (ID:" .. getPlayerID ( p ) .. ")", root, 255, 255, 255, true ); 
            tpToFightPlace ( p ); 
            tpToFightPlace ( player ); 
            duelTable [ player ] = nil; 
        else 
            outputChatBox ( "Noone challanged you!", player, 255, 0, 0, true ); 
        end 
    elseif ( arg == "decline" ) then 
        local p = duelTable [ player ]; 
        if ( isElement ( p ) ) then 
            duelTable [ player ] = nil; 
            outputChatBox ( getPlayerName ( player ) .. " declined.", p, 255, 0, 0, true ); 
        end 
    else 
        return; 
    end 
end 
addCommandHandler ( "duel", duel ); 

Link to comment
WARNING: Script 'Duel-System/s.lua:1: is not encoded in UTF-8. Loading as ANSI..

ERROR: Loading script failed: Duel-System/s.lua unexpected symbol near '?'

When I invite the player to duel says: Unable to find player with this ID!

  More the inserted ID is actually the player's ID

Link to comment
WARNING: Script 'Duel-System/s.lua:1: is not encoded in UTF-8. Loading as ANSI..

ERROR: Loading script failed: Duel-System/s.lua unexpected symbol near '?'

When I invite the player to duel says: Unable to find player with this ID!

  More the inserted ID is actually the player's ID

I believe that this lack to execute the command / duel ID

        local p = getPlayerFromID( id ); 
        local p = getElementData(getPlayerFromID( id )) 

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