Jump to content

Bet script


Recommended Posts

Привет всем, помогите получить имя guy. Всяко разно пробовал, никак не получается, то вобще не получает имя, то выводится как "userdata цифры".

Вот один из вариантов кода.

function onPlaceBet (playerSource, cmd, guy, amount) 
  amount = tonumber(amount) 
  local guyName = getPlayerFromName(guy) 
  if (guyName and amount) and amount > 0 then 
    local money = getPlayerMoney(playerSource) 
    if money < amount then  
      outputChatBox("Not enough money for betting!", playerSource, 255,255,255, true) 
    else    
      setElementData(playerSource, "guy", tostring(guyName)) 
      setElementData(playerSource, "amount", amount) 
      takePlayerMoney(playerSource, amount) 
      outputChatBox("*"..getPlayerName(playerSource).." #9ACD32Placed a bet on "..tostring(guyName).."#9ACD32!", getRootElement(), 255,255,255, true) 
    end 
  else 
    outputChatBox("Server: Syntax: /bet [name] [amount]", playerSource, 255,255,255, true) 
  end 
end 
addCommandHandler("bet", onPlaceBet) 
  
function check() 
   local alive = getAlivePlayers() 
   for _,v in ipairs(getElementsByType("player")) do 
           local betGuy = tostring(getElementData(v, "guy")) 
           local betAmount = tonumber(getElementData(v, "amount")) 
             if (#alive == 1) then 
                  local winner = alive[1] 
                  local winnerName = getPlayerName(winner) 
                          if betGuy then 
                                if (betGuy == winnerName) then 
                                      givePlayerMoney(v, amount*2) 
                                      outputChatBox("*"..winnerName.." won and you got "..(amount*2).."$", v, 255,255,255, true) 
                                 else 
                                      outputChatBox("*"..betGuy.." lost and you did not got money", v, 255,255,255, true) 
                                end 
                          end 
             end 
   end 
end 
addEventHandler("onPlayerWasted",getRootElement(),check) 

Edited by Guest
Link to comment

Функция getPlayerFromName возвращает элемент - игрок если аргумент это ник игрока, поэтому тебе и выводит userdata в чат. Там где у тебя tostring(guyName) замени на guy, на 12ой и на 9ой строке.

Похоже, что ты сам не понимаешь что ты написал.

Link to comment
offtop:

guy и gay совсем разные слова :D

Ой ой ой, не заметил, уже исправил) Всегда боялся перепутать их при написании :D

По скрипту: Я понимал, что пишу, просто я пробовал и getPlayerName() (ошибку выдаёт, не может получить) и ещё "кучу" чего. Ничего не получалось и начал перебирать всё что с связано с Name из wiki.

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