2013-04-06 2 views
-1

이 코드의 문제점이 무엇인지 압니까? 당신이 솔루션을 한 경우루아 - 전역 'contains'(아무 값도)를 호출하려고 시도

state1={10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,40,45,46,47,48,49,50,51,69,72,73,74,85} 
state3={78} 
state4={1,2,3,4,5,6} 

playerskin=initArray2(32,0) 
wepskin=initArray2(32,0) 

function getPlayerData(id,d) 
if (d=="team") then 
    if (player(id,"team")==1) then 
     return "red" 
    end 
    if (player(id,"team")==2) then 
     return "blu" 
    end 
end 
if (d=="class") then 
    return string.lower(tf2.classes.name[tf2.classes.class[id]]) 
end 
end 

function changeSkin(id,w) 
if (contains(state1,w)) then 
    if (playerskin[id]~=0) then 
     freeimage(playerskin[id]) 
    end 
    playerskin[id]=image("gfx/tf2/skins/"..getPlayerData(id,"team").." /"..getPlayerData(id,"class").."/"..getPlayerData(id,"team").."_"..getPlayerData(id,"class").."_1.png",1,0,200+id) 
end 
if (contains(state3,w)) then 
    if (playerskin[id]~=0) then 
     freeimage(playerskin[id]) 
    end 
    playerskin[id]=image("gfx/tf2/skins/"..getPlayerData(id,"team").."/"..getPlayerData(id,"class").."/"..getPlayerData(id,"team").."_"..getPlayerData(id,"class").."_3.png",1,0,200+id) 
end 
if (contains(state4,w)) then 
    if (playerskin[id]~=0) then 
     freeimage(playerskin[id]) 
    end 
    playerskin[id]=image("gfx/tf2/skins/"..getPlayerData(id,"team").."/"..getPlayerData(id,"class").."/"..getPlayerData(id,"team").."_"..getPlayerData(id,"class").."_4.png",1,0,200+id) 
end 
if (hat[id]~=0 and tf2.classes.hatunlock[id][tf2.classes.class[id]]~=0) then 
    freeimage(hat[id]) 
    hat[id]=image(crafts[tf2.classes.hatunlock[id] [tf2.classes.class[id]]].image,1,0,200+id) 
end 
end 

--[[function changeWeaponSkin(id,w) 
if (wepskin[id]~=0) then 
    freeimage(wepskin[id]) 
end 
wepskin[id]=image("gfx/tf2/skins/weapons/"..getPlayerData(id,"class").." /"..string.lower(tf2.classes.weaponnames[w])..".png",1,0,200+id) 
end 
]] 

addhook("select","tf2.classes.images") 
function tf2.classes.images(id,w) 
if (player(id,"armor")~=206) then 
    changeSkin(id,player(id,"weapontype")) 
    --changeWeaponSkin(id,w) 
end 
end 

addhook("spawn","tf2.classes.spawndebug") 
function tf2.classes.spawndebug(id) 
if (player(id,"armor")~=206) then 
    changeSkin(id,player(id,"weapontype")) 
    timer(10,"parse","lua changeSkin("..id..",player("..id..",\"weapontype \"))") 
    if (tf2.classes.hatunlock[id][tf2.classes.class[id]]~=0) then 
     timer(10,"parse","lua freeimage("..hat[id]..")") 
     timer(10,"parse","lua hat["..id.."]=image(crafts[tf2.classes.hatunlock["..id.."][tf2.classes.class["..id.."]]].image,1,0,200+"..id..")") 
    else 
     timer(10,"parse","lua freeimage("..hat[id]..")") 
     timer(10,"parse","lua hat["..id.."]=0") 
    end 
end 
end 

addhook("attack2","tf2.classes.spycloak") 
function tf2.classes.spycloak(id) 
if (tf2.classes.class[id]==9 and player(id,"armor")==0) then 
    if (playerskin[id]~=0) then 
     freeimage(playerskin[id]) 
    end 
    --[[ 
    if (wepskin[id]~=0) then 
     freeimage(wepskin[id]) 

것은 도와주세요 : 여기

코드입니다

'포함'글로벌 통화 시도 ''(A 전무 값) '': 난 항상이 오류가 나를.

감사합니다,

마이클

답변

0

당신은 당신의 코드 세그먼트에서

if(contains(...)) then 

있습니다. 호출하려면 함수 contains을 정의해야합니다. 함수 정의가 누락되었습니다.

function contains(tPassed, iValue) 
    for _, v in pairs(tPassed) do 
     if tonumber(v) == tonumber(iValue) then 
      return true 
     end 
    end 
    return nil 
end 
+0

감사 hjpotter92을 (당신이 테이블 내부 w를 찾으려면)

는이 같은 것을 사용할 수 있습니다! 코드 전에 첫 줄에 쓴이 코드를 추가했는데 이제 작동합니다! 다시 한번 감사드립니다 :) – user2252099