Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2016-12-20, 14:10


flimbo123







Wiek: 33
Na forum: 5776 dni
Posty: 93
Nick w MP: Flimbo

Piwa: 190

Respekt: 60

addCommandHandler("zaparkuj",function(plr)
    if getPedOccupiedVehicle(plrthen
        if getElementData(getPedOccupiedVehicle(plr),"owner")==getPlayerName(plrthen
            local x,y,z=getElementPosition(getPedOccupiedVehicle(plr))
            local _,_,rot1=getVehicleRotation(getPedOccupiedVehicle(plr))
            setElementData(getPedOccupiedVehicle(plr),"x",x)
            setElementData(getPedOccupiedVehicle(plr),"y",y)
            setElementData(getPedOccupiedVehicle(plr),"z",z)
            setElementData(getPedOccupiedVehicle(plr),"rot",rot)
            outputChatBox("*Tw?j pojazd zosta? zaparkowany.",plr,255,255,255)
            executeCommandHandler("save",plr)
        end
    end
end)


Chodzi o to, ?eby zamiast GetPlayerName u?ywa?o getAccountName. Jestem pocz?tkujacy w LUA i niezbyt umiem to rozkmini?, bo prosta zamiana na GetAccountName zamiast GetPlayerName nie funkcjonuje poprawnie.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-12-20, 14:14


marcin778

Krytyk serwerów MTA






Wiek: 24
Na forum: 4149 dni
Posty: 2268
Nick w MP: Marcineg

Piwa: 4662

Respekt: 1436,8
Respekt: 1436,8

addCommandHandler("zaparkuj",function(plr)
    if getPedOccupiedVehicle(plrthen
      local kt getPlayerAccount(plr)
         if kt then
        if getElementData(getPedOccupiedVehicle(plr),"owner")==getAccountName(ktthen
            local x,y,z=getElementPosition(getPedOccupiedVehicle(plr))
            local _,_,rot1=getVehicleRotation(getPedOccupiedVehicle(plr))
            setElementData(getPedOccupiedVehicle(plr),"x",x)
            setElementData(getPedOccupiedVehicle(plr),"y",y)
            setElementData(getPedOccupiedVehicle(plr),"z",z)
            setElementData(getPedOccupiedVehicle(plr),"rot",rot)
            outputChatBox("*Tw?j pojazd zosta? zaparkowany.",plr,255,255,255)
            executeCommandHandler("save",plr)
             end
        end
    end
end)


Podpis
Moje prace: https://www.youtube.com/c...MuaWGHPp1mhlGnw

-- obecnie
-- obecnie
-- dawniej
-- dawniej
-- dawniej
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-12-20, 22:14


flimbo123







Wiek: 33
Na forum: 5776 dni
Posty: 93
Nick w MP: Flimbo

Piwa: 190

Respekt: 60

Super! Dzia?a! jednak mam jeszcze pare innych funkcji na identycznej zasadzie. Je?li zmienna "kt" ju? jest zdefiniowana to wystarczy tylko doda? "=getAccountName(kt)" [...] i b?dzie git?

Dla przyk?adu:

addCommandHandler("stworzauto",function(plr,cmd,model)
    if isObjectInACLGroup("user."..getPlayerName(plr),aclGetGroup("Admin")) then
        if not model then return end
        local x,y,z=getElementPosition(plr)
        local v=createVehicle(model,x,y,z)
        local _,_,rot=getVehicleRotation(v)
        setElementPosition(plr,x,y,z+2)
        setVehicleRotation(plr,0,0,rot)
        setElementData(v,"owner"==getAccountName(kt))
        setElementData(v,"przeb",0)
        executeCommandHandler("save",plr)
    end
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-12-21, 17:59


marcin778

Krytyk serwerów MTA






Wiek: 24
Na forum: 4149 dni
Posty: 2268
Nick w MP: Marcineg

Piwa: 4662

Respekt: 1436,8
Respekt: 1436,8

Tak, aczkolwiek w przypadku
Więcej informacji znajdziesz w Wikipedii MTA:

setElementData
nie robimy tego tak jak ty to zrobi?e?, tylko:
     setElementData(v,"owner"getAccountName(kt))
to ustawia elementdate "owner" na nazwe konta danego gracza. Znak "==" u?ywamy najcz??ciej gdy sprawdzamy czy co? jest r?wne, np w przypadku
Więcej informacji znajdziesz w Wikipedii MTA:

getElementData
wygl?da?oby to tak:
if getElementData(v"owner")==getAccountData(ktthen
Ponadto 'v' to nie jest ?aden argument poniewa? nie ma nigdzie p?tli ani ?adnej takiej zmiennej, no chyba, ?e poza tym skrawkiem co pokaza?e?. Zmienna 'kt' zdefiniowana jest tylko w komendzie 'zaparkuj' poniewa? jest ona lokalna, mo?esz zrobi? kolejn? tak? zmienn? lokaln?, kt?ra b?dzie dzia?a?a tylko w komendzie 'stworzauto'
addCommandHandler("stworzauto",function(plr,cmd,model)
    if isObjectInACLGroup("user."..getPlayerName(plr),aclGetGroup("Admin")) then
        if not model then return end
        local kt getPlayerAccount(plr)
        local x,y,z=getElementPosition(plr)
        local v=createVehicle(model,x,y,z)
        local _,_,rot=getVehicleRotation(v)
        setElementPosition(plr,x,y,z+2)
        setVehicleRotation(plr,0,0,rot)
        setElementData(v,"owner",getAccountName(kt))
        setElementData(v,"przeb",0)
        executeCommandHandler("save",plr)
    end
end)
lub mo?esz zrobi? z jednej zmiennej lokalnej zmienn? globaln? czyli usun?? przedrostek 'local' wtedy zmienna ta b?dzie dzia?a? na ca?ym kodzie.

Ma?a uwaga, aby pobra? nazw? konta gracza to trzeba najpierw pobra? konto gracza, kt?rego chcemy pobra? nazw?, od tego w?a?nie jest zmienna 'kt'.

Podpis
Moje prace: https://www.youtube.com/c...MuaWGHPp1mhlGnw

-- obecnie
-- obecnie
-- dawniej
-- dawniej
-- dawniej
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-12-21, 18:45


flimbo123







Wiek: 33
Na forum: 5776 dni
Posty: 93
Nick w MP: Flimbo

Piwa: 190

Respekt: 60

marcin778, Drogi Marcinie, nie da si? ukry?, ?e wszystko rzetelnie i zrozumiale wyt?umaczy?e?. Jednak u?ywaj?c podanego przez ciebie wy?ej przyk?adu komendy "stworzauto" niestety nie tworzy ona pojazdu na nazw? konta. Nie dzieje si? nic.

Aby unikn?? niedopowiedze? podaj? ci ca?y kod z komendami dla skryptu:


addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function()
    local q=dbQuery(db,"SELECT * FROM `Save`")
    local x=dbPoll(q,-1)
    dbFree(q)
    for _,v in ipairs(x)do
        local car=createVehicle(v.Model,v.x,v.y,v.z)
        setVehicleColor(car,v.c1,v.c2,v.c3,v.c4,v.c5,v.c6)
        setElementData(car,"owner",v.owner)
        setElementData(car,"przeb",v.przebieg)
        setElementData(car,"fuel",v.paliwo)
        setElementData(car,"v:id",v.ID)
        setElementHealth(car,v.hp)
        setElementData(car,"x",v.x)
        setElementData(car,"y",v.y)
        setElementData(car,"z",v.z)
        setElementData(car,"rot",v.rot)
        setVehicleRotation(car,0,0,v.rot)
        setVehicleHandling(car,"driveType",v.driveType)
        setVehicleHandling(car,"numberOfGears",v.numberOfGears)
        setVehicleHandling(car,"maxVelocity",v.maxVelocity)
        setVehicleHandling(car,"engineAcceleration",v.engineAcceleration)
        setVehicleHandling(car,"steeringLock",v.steeringLock)
        tuning=fromJSON(v.tuning)
        for _,value in ipairs(tuning)do
            addVehicleUpgrade(car,value)
        end
    end
end)

addCommandHandler("stworzauto",function(plr,cmd,model)
    if isObjectInACLGroup("user."..getPlayerName(plr),aclGetGroup("Admin")) then
        if not model then return end
        local kt getPlayerAccount(plr)
        local x,y,z=getElementPosition(plr)
        local v=createVehicle(model,x,y,z)
        local _,_,rot=getVehicleRotation(v)
        setElementPosition(plr,x,y,z+2)
        setVehicleRotation(plr,0,0,rot)
        setElementData(v,"owner",getAccountName(kt))
        setElementData(v,"przeb",0)
        executeCommandHandler("save",plr)
    end
end)

addCommandHandler("zaparkuj",function(plr)
    if getPedOccupiedVehicle(plrthen
      local kt getPlayerAccount(plr)
         if kt then
        if getElementData(getPedOccupiedVehicle(plr),"owner")==getAccountName(ktthen
            local x,y,z=getElementPosition(getPedOccupiedVehicle(plr))
            local _,_,rot1=getVehicleRotation(getPedOccupiedVehicle(plr))
            setElementData(getPedOccupiedVehicle(plr),"x",x)
            setElementData(getPedOccupiedVehicle(plr),"y",y)
            setElementData(getPedOccupiedVehicle(plr),"z",z)
            setElementData(getPedOccupiedVehicle(plr),"rot",rot)
            outputChatBox("*Tw?j pojazd zosta? zaparkowany.",plr,255,255,255)
            executeCommandHandler("save",plr)
             end
        end
    end
end)
        
        
addCommandHandler("przepiszpojazd",function(plr,cmd,nick)
    if getPedOccupiedVehicle(plrthen
        if getElementData(getPedOccupiedVehicle(plr),"owner")==getPlayerName(plrthen
            local auto=getPedOccupiedVehicle(plr)
            local gracz=getPlayerFromName(nick)
            if not gracz then return outputChatBox("*Nie znaleziono takiego gracza.",plr,255,255,255end
            setElementData(auto,"owner",nick)
            executeCommandHandler("save",plr)
            outputChatBox("*Pomy?lne przepisanie pojazdu.",plr,255,255,255)
            outputChatBox("*Otrzymujesz pojazd : "..getVehicleName(auto).." od gracza : "..getPlayerName(plr).."!",gracz,255,255,255)
        end
    end
end)

addEventHandler("onVehicleStartEnter",root,function(plr,seat)
    if seat==0 then
        local own=getElementData(source,"owner")
        if own then
            if own~=getPlayerName(plrthen
                cancelEvent()
                outputChatBox("*To auto nale?y do innego gracza.",plr,255,255,255)
            end
        end
    end
end)


((Wst?p kodu czyli ??czenie si? z baz? danych, formaty zapisu itp pozwoli?em sobie pomin??, bo i tak w tej sprawie jest to bezu?yteczne.))

PS: Oczywi?cie piwami ju? ci? nagrodzi?em :>

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-12-21, 18:52


marcin778

Krytyk serwerów MTA






Wiek: 24
Na forum: 4149 dni
Posty: 2268
Nick w MP: Marcineg

Piwa: 4662

Respekt: 1436,8
Respekt: 1436,8

Nie wina przyk?adu, tylko nie istniej?cej funkcji 'setVehicleRotation'. Wpisz /debugscript 3 na chacie b?d? konsoli i wyskoczy ci debugowanie wszystkich zasob?w, tam zawsze pojawiaj? si? b??dy czy te? ostrze?enia odno?nie b??d?w w skrypcie, wszystko jest tam napisane w jakiej linijce jest b??d oraz na czym on polega. Co do problemu rozwi?zanie jest proste nie istnieje co? takiego jak setVehicleRotation tylko
Więcej informacji znajdziesz w Wikipedii MTA:

setElementRotation


addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),function()
    local q=dbQuery(db,"SELECT * FROM `Save`")
    local x=dbPoll(q,-1)
    dbFree(q)
    for _,v in ipairs(x)do
        local car=createVehicle(v.Model,v.x,v.y,v.z)
        setVehicleColor(car,v.c1,v.c2,v.c3,v.c4,v.c5,v.c6)
        setElementData(car,"owner",v.owner)
        setElementData(car,"przeb",v.przebieg)
        setElementData(car,"fuel",v.paliwo)
        setElementData(car,"v:id",v.ID)
        setElementHealth(car,v.hp)
        setElementData(car,"x",v.x)
        setElementData(car,"y",v.y)
        setElementData(car,"z",v.z)
        setElementData(car,"rot",v.rot)
        setElementRotation(car,0,0,v.rot)
        setVehicleHandling(car,"driveType",v.driveType)
        setVehicleHandling(car,"numberOfGears",v.numberOfGears)
        setVehicleHandling(car,"maxVelocity",v.maxVelocity)
        setVehicleHandling(car,"engineAcceleration",v.engineAcceleration)
        setVehicleHandling(car,"steeringLock",v.steeringLock)
        tuning=fromJSON(v.tuning)
        for _,value in ipairs(tuning)do
            addVehicleUpgrade(car,value)
        end
    end
end)

addCommandHandler("stworzauto",function(plr,cmd,model)
    if isObjectInACLGroup("user."..getPlayerName(plr),aclGetGroup("Admin")) then
        if not model then return end
        local kt getPlayerAccount(plr)
        local x,y,z=getElementPosition(plr)
        local v=createVehicle(model,x,y,z)
        local _,_,rot=getVehicleRotation(v)
        setElementPosition(plr,x,y,z+2)
        setElementRotation(plr,0,0,rot)
        setElementData(v,"owner",getAccountName(kt))
        setElementData(v,"przeb",0)
        executeCommandHandler("save",plr)
    end
end)

addCommandHandler("zaparkuj",function(plr)
    if getPedOccupiedVehicle(plrthen
      local kt getPlayerAccount(plr)
         if kt then
        if getElementData(getPedOccupiedVehicle(plr),"owner")==getAccountName(ktthen
            local x,y,z=getElementPosition(getPedOccupiedVehicle(plr))
            local _,_,rot1=getVehicleRotation(getPedOccupiedVehicle(plr))
            setElementData(getPedOccupiedVehicle(plr),"x",x)
            setElementData(getPedOccupiedVehicle(plr),"y",y)
            setElementData(getPedOccupiedVehicle(plr),"z",z)
            setElementData(getPedOccupiedVehicle(plr),"rot",rot)
            outputChatBox("*Tw?j pojazd zosta? zaparkowany.",plr,255,255,255)
            executeCommandHandler("save",plr)
             end
        end
    end
end)
        
        
addCommandHandler("przepiszpojazd",function(plr,cmd,nick)
    if getPedOccupiedVehicle(plrthen
        if getElementData(getPedOccupiedVehicle(plr),"owner")==getPlayerName(plrthen
            local auto=getPedOccupiedVehicle(plr)
            local gracz=getPlayerFromName(nick)
            if not gracz then return outputChatBox("*Nie znaleziono takiego gracza.",plr,255,255,255end
            setElementData(auto,"owner",nick)
            executeCommandHandler("save",plr)
            outputChatBox("*Pomy?lne przepisanie pojazdu.",plr,255,255,255)
            outputChatBox("*Otrzymujesz pojazd : "..getVehicleName(auto).." od gracza : "..getPlayerName(plr).."!",gracz,255,255,255)
        end
    end
end)

addEventHandler("onVehicleStartEnter",root,function(plr,seat)
    if seat==0 then
        local own=getElementData(source,"owner")
        if own then
            if own~=getPlayerName(plrthen
                cancelEvent()
                outputChatBox("*To auto nale?y do innego gracza.",plr,255,255,255)
            end
        end
    end
end)


Podpis
Moje prace: https://www.youtube.com/c...MuaWGHPp1mhlGnw

-- obecnie
-- obecnie
-- dawniej
-- dawniej
-- dawniej
Postaw piwo autorowi tego posta
 

 
Tagi: wykrywanie :: gracza :: nazwie :: konta :: zamiast :: nicku
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Wykrywanie gracza po nazwie konta zamiast po nicku Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku