Jump to content

Общий мини "HELP ME" топик по скриптингу


Recommended Posts

Условия правильные. Значит забивай дебаг-сообщения в части нерабочего кода ("outputChatBox") и проверяй срабатывает ли он вообще. Возможно у тебя просто не прописаны изображения в мета-файле, проверь и это тоже.

to Astari:

Не, это тоже неправильно. Вот нормальное объяснение: http://www.lua.org/pil/4.3.1.html

Edited by Guest
Link to comment

ТаНkер, твой последний пример кода должен работать. Чтобы найти причину почему не работает, ответь на эти вопросы:

1. Если скрипт не твой, то этот кусок кода - все что ты изменил?

2. Все картинки прописаны в мета-файле ресурса?

3. Ты вставлял дебаг-сообщения в места которые не работают?

Link to comment

Амарант, а это никак нельзя упростить? Или все таки придется на 5 дат забивать по 100 территорий?

area1 = createRadarArea ( 2415, -2049, 125, 120, 255, 255, 255, 150, getRootElement() ) 
area2 = createRadarArea ( 2540, -2049, 58, 200, 255, 255, 255, 150, getRootElement() ) 
function nolik() 
    setElementData(area1, "gang", 0) 
    setElementData(area2, "gang", 0) 
end 
addEventHandler("onResourceStart", getRootElement(), nolik) 
  
function capture(thePlayer) 
    local player = getElementPosition(thePlayer) 
    local posX, posY = getElementPosition(thePlayer) 
    local g1 = getElementData(area1, "gang") 
        local g2 = getElementData(area2, "gang") 
    if ( getAccountData(getPlayerAccount(thePlayer), "rifaData") > 6 ) then 
            if ( g1 == 0 ) or ( g2 == 0 ) then 
                if (isInsideRadarArea (area1, posX, posY )) then 
                    setRadarAreaColor( area1, 35, 25, 255, 150) 
                    setElementData(area1, "gang", 1) else 
                if (isInsideRadarArea (area2, posX, posY )) then  
                    setRadarAreaColor( area2, 35, 25, 255, 150)  
                    setElementData(area2, "gang", 1) else 
                end end 
            else 
            end 
    else 
    end 
end 
addCommandHandler("capture", capture) 

Link to comment
ТаНkер, твой последний пример кода должен работать. Чтобы найти причину почему не работает, ответь на эти вопросы:

1. Если скрипт не твой, то этот кусок кода - все что ты изменил?

2. Все картинки прописаны в мета-файле ресурса?

3. Ты вставлял дебаг-сообщения в места которые не работают?

1. скрипт полностью мой

2. да

3.а вот это я не понял как вставлять

Link to comment

ага!

я попробовал сначала так:

local screenWidth,screenHeight = guiGetScreenSize() 
  
function drawHealth ( )          
         health = getElementHealth ( getLocalPlayer() ) 
         if ( health >= 98 and health =< 100 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h100.png' ) 
         end 
         if ( health >= 93 and health < 98 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h95.png' ) 
         end 
         if ( health >= 88 and health < 93 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h90.png' ) 
         end 
         if ( health >= 83 and health < 88 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h85.png' ) 
         end 
         if ( health >= 78 and health < 83 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h80.png' ) 
         end 
         if ( health >= 73 and health < 78 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h75.png' ) 
         end 
         if ( health >= 68 and health < 73 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h70.png' ) 
         end 
         if ( health >= 63 and health < 68 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h65.png' ) 
         end 
         if ( health >= 58 and health < 63 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h60.png' ) 
         end 
         if ( health >= 53 and health < 58 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h55.png' ) 
         end 
         if ( health >= 48 and health < 53 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h50.png' ) 
         end 
end 
  
  
function HandleTheRendering ( ) 
    addEventHandler("onClientRender", getRootElement(), drawHealth)  
end 
addEventHandler("onClientResourceStart",resourceRoot, HandleTheRendering) 
  

не пашет

а потом попробовал вторую половину

local screenWidth,screenHeight = guiGetScreenSize() 
  
function drawHealth ( )          
         health = getElementHealth ( getLocalPlayer() ) 
         if ( health >= 48 and health < 53 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h50.png' ) 
         end 
         if ( health >= 43 and health < 48 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h45.png' ) 
         end 
         if ( health >= 38 and health < 43 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h40.png' ) 
         end 
         if ( health >= 33 and health < 38 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h35.png' ) 
         end 
         if ( health >= 28 and health < 33 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h30.png' ) 
         end 
         if ( health >= 23 and health < 28 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h25.png' ) 
         end 
         if ( health >= 18 and health < 23 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h20.png' ) 
         end 
         if ( health >= 13 and health < 18 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h15.png' ) 
         end 
         if ( health >= 8 and health < 13 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h10.png' ) 
         end 
         if ( health >= 3 and health < 8 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h5.png' ) 
         end 
         if ( health >= 0 and health < 3 ) then 
         dxDrawImage ( screenWidth/2 - 50, 0, 128, 256, 'images/h0.png' ) 
         end 
end 
  
  
function HandleTheRendering ( ) 
    addEventHandler("onClientRender", getRootElement(), drawHealth)  
end 
addEventHandler("onClientResourceStart",resourceRoot, HandleTheRendering) 
  

и вуаля-работает, сейчас ищу ошибку в первой половине...

Link to comment

TaHkep, в части кода где не работает (судя по всему где картинка отрисовывается) вставить например:

outputChatBox("It's working") 

В результате ты будешь видить в чате что происходит. Если код будет выполняться, то оно будет тебе это выбивать.

Astari, что за "rifaData"? И вообще в таких случаях рекомендуется использовать таблицы и зоны на радаре лучше делать прямоугольной формы, а то много геморроя с их созданием.

Link to comment

Все понятно. В операторах сравнения начинать нужно со знака "больше-меньше", а не с "равно". >= - правильно, => - неправильно. А также нельзя в условии писать например health=100, должен быть только знак двойного равенства: health==100.

Link to comment
Все понятно. В операторах сравнения начинать нужно со знака "больше-меньше", а не с "равно". >= - правильно, => - неправильно. А также нельзя в условии писать например health=100, должен быть только знак двойного равенства: health==100.

все работает

ОГРОМНОЕ спасибо :)

Link to comment

Astari, что за "rifaData"? И вообще в таких случаях рекомендуется использовать таблицы и зоны на радаре лучше делать прямоугольной формы, а то много геморроя с их созданием.

Там своя тема, я просто решил РП сервер сделать, с косяком под Адванс РП на сампе :D

Link to comment

Ну тогда могу тебе только посоветовать использовать для таких целей XML или SQL базы данных. В них можно забивать что угодно, включая твои данные с координатами, игроками, зонами и т.д.

Link to comment

клиент:

marker = createMarker(2792.17, -1944.59, 16.32031, 'cylinder', 1.5, 255, 0, 0, 150) 
function createm(thePlayer) 
    if isElementWithinMarker(thePlayer, marker) then 
        GUIEditor_Window = {} 
        GUIEditor_Window[1] = guiCreateWindow(376,254,294,375,"",false) 
    else 
    end   
end 
addCommandHandler("ast", createm) 

Когда в маркере стоишь и пишешь /ast должно окно открываться, но не открывается

Link to comment

Ну тогда зачем ты создаешь на клиенте серверный вариант функции "addCommandHandler"?

marker = createMarker(2792.17, -1944.59, 16.32031, 'cylinder', 1.5, 255, 0, 0, 150) 
function createm() 
    if isElementWithinMarker(getLocalPlayer(), marker) then 
        GUIEditor_Window = {} 
        GUIEditor_Window[1] = guiCreateWindow(376,254,294,375,"",false) 
    else 
    end   
end 
addCommandHandler("ast", createm) 

Link to comment
клиент:
marker = createMarker(2792.17, -1944.59, 16.32031, 'cylinder', 1.5, 255, 0, 0, 150) 
function createm(thePlayer) 
    if isElementWithinMarker(thePlayer, marker) then 
        GUIEditor_Window = {} 
        GUIEditor_Window[1] = guiCreateWindow(376,254,294,375,"",false) 
    else 
    end   
end 
addCommandHandler("ast", createm) 

Когда в маркере стоишь и пишешь /ast должно окно открываться, но не открывается

Если бы ты врубил дебаг, ты бы увидел, что вместо элемента у тебя строка. Я про переменную thePlayer.
Link to comment

привет, у меня сервер ругается на ресурс рейс топ таймс, вот что пишет:

WARNING: [gamemodes]/[race]/[addons]/race_toptimes/toptimes_server.lua:32: Bad argument @ 'outputChatBox' 
  

вот что в 31-33 строчках содержится(решил выложить, мало ли это нужно):

if model == 425 then 
                outputChatBox ( source, "has got the Hunter", getRootElement(), 255, 255, 255, true ) 
                if g_SToptimesManager then 

в чём тут загвоздка может быть?

Link to comment

Что интересно, у меня в этом же ресурсе ничего подобного нет.

Попробуй так:

  
     if model == 425 then 
                    outputChatBox(getPlayerName(source) .. " has got the Hunter", getRootElement(), 255, 255, 255, true) 
                    if g_SToptimesManager then 
  

Link to comment

Как сделать чтобы проверяло заблокирована ли машина в колСфере?

hacking = createColSphere(posX, posY, posZ, 4) 
local cars = getElementsWithinColShape( hacking, "vehicle") 
for index, aVehicle in ipairs(cars) do 
        if isVehicleLocked(theVehicle) then 

Link to comment
hacking = createColSphere(posX, posY, posZ, 4) 
local cars = getElementsWithinColShape( hacking, "vehicle") 
for index, aVehicle in ipairs(cars) do 
        if isVehicleLocked(aVehicle) then 
        outputChatBox(getVehicleName(aVehicle).." is locked.") 
        end 
end 

Link to comment

что не так в этой проверке на запрещенные символы?

for k = 0, string.len(username) do 
    if username[k] == "[" or username[k] == "]" then 
        outputChatBox("   В нике запрещенные символы!", source, 255, 0, 0, true) 
        return true 
    end 
end 

не срабатывает проверка на символы [ ], тупо пропускает.

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