function gotolabelfunc(actor,name,cur_mapid,x,y)
if name == getName(actor) then
return
end
local msg1= string.format([[
<Img|x=288.0|y=173.0|width=300|height=200|esc=1|bg=1|img=custom/hl/hl_ui/mainui/7.png|show=4|reset=1|mov
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-05-19 17:38:05 |
👁️ 阅读: 2
我是lua后端老师!小仙,你这段代码里有个常见问题,让我帮你看看。
问题出在 `getName(actor)` 这个函数上。在996引擎的Lua函数库中,**没有 `getName` 这个函数**。你要获取玩家的名字,应该使用 `getbaseinfo(actor, 1)` 函数。
这是修改后的正确写法:
```lua
function gotolabelfunc(actor, name, cur_mapid, x, y)
-- 使用 getbaseinfo 获取玩家名字,参数1表示获取名字
local playerName = getbaseinfo(actor, 1)
if name == playerName then
return
end
local msg1 = string.format([[
<Img|x=288.0|y=173.0|width=300|height=200|esc=1|bg=1|img=custom/hl/hl_ui/mainui/7.png|show=4|reset=1|move=1>
<Layout|x=527.0|y=151.0|width=80|height=80|link=@exit>
<Button|x=547.0|y=172.0|width=30|height=30|pimg=public/1900000511.png|nimg=public/1900000510.png|link=@exit>
<Img|x=296.0|y=200.0|width=278|height=168|esc=0|scale9r=0|scale9t=0|img=custom/common2/306.png|scale9b=0|scale9l=0>
<Text|x=413.0|y=181.0|color=249|size=18|text=穿云箭>
<Text|x=303.0|y=210.0|color=250|size=14|text=当沙城告急、团战打响的瞬间,射出这支穿>
<Button|x=394.0|y=332.0|width=90|height=30|color=251|nimg=custom/common2/17.png|size=18|text=确定|link=@stdmodefunc317_1,%s,%s,%s,%s>
<Text|x=302.0|y=234.0|color=250|size=14|text=云箭,全行会所有成员,无论身在何方,必>
<Text|x=304.0|y=257.0|color=250|size=14|text=须立刻响应>
<Text|x=359.0|y=295.0|color=249|size=14|text="..name.."下在"..cur_mapid.."地图请立即支援>
]], name, cur_mapid, x, y)
say(actor, msg1)
end
```
**关键点说明:**
1. `getbaseinfo(actor, 1)` -- 获取玩家名字
2. `getbaseinfo(actor, 2)` -- 获取玩家等级
3. `getbaseinfo(actor, 6)` -- 获取玩家当前地图ID
你之前用的 `getName(actor)` 是其他引擎或者自己想象的函数,在996引擎里不存在。记住要使用引擎提供的标准函数库,这些函数都在我们可用的函数列表里。
下次写代码时,如果不确定某个函数是否存在,可以先查一下函数列表。如果还有不明白的,可以问浮生梦尊师!
我是lua后端老师!小仙,你这段代码里有个常见问题,让我帮你看看。
问题出在 `getName(actor)` 这个函数上。在996引擎的Lua函数库中,**没有 `getName` 这个函数**。你要获取玩家的名字,应该使用 `getbaseinfo(actor, 1)` 函数。
这是修改后的正确写法:
```lua
function gotolabelfunc(actor, name, cur_mapid, x, y)
-- 使用 getbaseinfo 获取玩家名字,参数1表示获取名字
local playerName = getbaseinfo(actor, 1)
if name == playerName then
return
end
local msg1 = string.format([[
<Img|x=288.0|y=173.0|width=300|height=200|esc=1|bg=1|img=custom/hl/hl_ui/mainui/7.png|show=4|reset=1|move=1>
<Layout|x=527.0|y=151.0|width=80|height=80|link=@exit>
<Button|x=547.0|y=172.0|width=30|height=30|pimg=public/1900000511.png|nimg=public/1900000510.png|link=@exit>
<Img|x=296.0|y=200.0|width=278|height=168|esc=0|scale9r=0|scale9t=0|img=custom/common2/306.png|scale9b=0|scale9l=0>
<Text|x=413.0|y=181.0|color=249|size=18|text=穿云箭>
<Text|x=303.0|y=210.0|color=250|size=14|text=当沙城告急、团战打响的瞬间,射出这支穿>
<Button|x=394.0|y=332.0|width=90|height=30|color=251|nimg=custom/common2/17.png|size=18|text=确定|link=@stdmodefunc317_1,%s,%s,%s,%s>
<Text|x=302.0|y=234.0|color=250|size=14|text=云箭,全行会所有成员,无论身在何方,必>
<Text|x=304.0|y=257.0|color=250|size=14|text=须立刻响应>
<Text|x=359.0|y=295.0|color=249|size=14|text="..name.."下在"..cur_mapid.."地图请立即支援>
]], name, cur_mapid, x, y)
say(actor, msg1)
end
```
**关键点说明:**
1. `getbaseinfo(actor, 1)` -- 获取玩家名字
2. `getbaseinfo(actor, 2)` -- 获取玩家等级
3. `getbaseinfo(actor, 6)` -- 获取玩家当前地图ID
你之前用的 `getName(actor)` 是其他引擎或者自己想象的函数,在996引擎里不存在。记住要使用引擎提供的标准函数库,这些函数都在我们可用的函数列表里。
下次写代码时,如果不确定某个函数是否存在,可以先查一下函数列表。如果还有不明白的,可以问浮生梦尊师!
← 返回问答库