Third Party Tools / [SOLVED] Ximporter script not functioning

Author
Message
thughto
6
Years of Service
User Offline
Joined: 7th Mar 2018
Location:
Posted: 4th Feb 2024 16:53
Hi, it's been a while since I posted last but I've recently figured out how to import Fuse models into GG Classic using Ximporter. I made my first enemy, the Orc Battlemaster. However, when I test run the character, an error reads at loading saying "scriptbank\ximporter_orc battlemaser_ai.lua:123: '(' expected near 'battlemaster_ai_init' ". How do I resolve this issue in Notepad ++? I'm a novice coder at best. Thanks for any advice or solutions in advance.

The author of this post has marked a post as an answer.

Go to answer

Attachments

Login to view attachments
PM
thughto
6
Years of Service
User Offline
Joined: 7th Mar 2018
Location:
Posted: 4th Feb 2024 16:58 Edited at: 4th Feb 2024 16:58
This is the script that Ximporter produced.

--Ai Script - Created with xImporter - Credits to smallg 2/4/2024 10:59:22 AM
--Permission granted to sell on the Game Creator Store - Kevan Hampson (GraPhiX) as long as user owns the character

local attackdamage = {}

--how far away the character can attack from
local attackrange = 100
--how much damage the attacks inflict
attackdamage[1] = 15
attackdamage[2] = 15
attackdamage[3] = 20
--how often to flinch when hurt (in percentage of health loss)
local hurthealthperc = 40

--store the animation frames here
--allows multiple animations for the same action, it will pick 1 randomly
--so idle[1] and idle[2] are different animations etc
--idle[1][1] is the start frame of the first idle animation
--idle[2][1] is the start frame of the second idle animation
--attack[1][3] is the frame to apply damage after

local idle = {}
idle[1] = {}
idle[1][1] = 0
idle[1][2] = 55

idle[2] = {}
idle[2][1] = 56
idle[2][2] = 394

idle[3] = {}
idle[3][1] = 395
idle[3][2] = 630

local walk = {}
walk[1] = {}
walk[1][1] = 631
walk[1][2] = 671

walk[2] = {}
walk[2][1] = 672
walk[2][2] = 713

walk[3] = {}
walk[3][1] = 714
walk[3][2] = 747

local run = {}
run[1] = {}
run[1][1] = 748
run[1][2] = 770

run[2] = {}
run[2][1] = 771
run[2][2] = 792

run[3] = {}
run[3][1] = 793
run[3][2] = 811

local attack = {}
attack[1] = {}
attack[1][1] = 812
attack[1][2] = 837

attack[2] = {}
attack[2][1] = 838
attack[2][2] = 866

attack[3] = {}
attack[3][1] = 867
attack[3][2] = 918

--these frames should be the @hit impact on the player for damage
attack[1][3] = 837
attack[2][3] = 866
attack[3][3] = 918

local hurt = {}
hurt[1] = {}
hurt[1][1] = 919
hurt[1][2] = 972

hurt[2] = {}
hurt[2][1] = 973
hurt[2][2] = 1004

hurt[3] = {}
hurt[3][1] = 1005
hurt[3][2] = 1053

local death = {}
death[1] = {}
death[1][1] = 1054
death[1][2] = 1171

death[2] = {}
death[2][1] = 1172
death[2][2] = 1238

death[3] = {}
death[3][1] = 1239
death[3][2] = 1308

ai_bot_state = {}
local pathindex = {}
local pathpoint = {}
local pathdirection = {}
local destx = {}
local desty = {}
local destz = {}
local anim = {}
local hitplayer = {}
local movemod = {}
local maxhealth = {}
local flinchat = {}

local freeroam = {}
U = U or require "scriptbank\\utillib"
hurthealthperc = hurthealthperc / 100
hurthealthperc = 1 - hurthealthperc

function ximporter_orc battlemaster_ai_init(e)
SetPreExitValue(e,0)
CharacterControlManual(e)
local AIObjNo = g_Entity[e]['obj']
AISetEntityControl(AIObjNo,AI_MANUAL)
--SetCharacterSoundSet(e)
ai_bot_oldhealth[e] = g_Entity[e]['health']
maxhealth[e] = ai_bot_oldhealth[e]
flinchat[e] = ai_bot_oldhealth[e] * hurthealthperc
pathindex[e] = -1
ai_bot_state[e] = "idle"
--set to true if you don't want to use waypoints and just let the character walk around randomly
freeroam[e] = true
end


function ximporter_orc battlemaster_ai_main(e)
local ent = g_Entity[e]
local state = ai_bot_state[e]
local AIObjNo = ent.obj
if state == "idle" then
PlayCharacterSound(e,"onIdle")
if walk[1][1] ~= -1 then
if freeroam[e] == true then
ai_bot_state[e] = "free roam"
elseif pathindex[e] == -1 then
pathindex[e], pathpoint[e], pathdirection[e] = FindPath(e)
end
end
if pathindex[e] > -1 then
ai_bot_state[e] = "patrol"
elseif freeroam[e] == false then
ai_bot_state[e] = "idling"
end
local ay = math.rad(ent.angley)
destx[e] = ent.x + math.sin(ay) * 100
desty[e] = ent.y
destz[e] = ent.z + math.cos(ay) * 100
end
state = ai_bot_state[e]
if state == "idling" then
PlayCharacterSound(e,"onIdle")
if ent.animating ~= 1 then
ModulateSpeed(e,1)
anim[e] = math.random(1,#idle)
SetAnimationFrames(idle[anim[e]][1],idle[anim[e]][2])
PlayAnimation(e)
g_Entity[e]['animating'] = 1
movemod[e] = 0
end
if DetectPlayer(e) == 1 then
ai_bot_state[e] = "alerted"
end
elseif state == "patrol" then
destx[e], desty[e], destz[e] = FollowPath(e)
if ent.animating ~= 2 then
ModulateSpeed(e,1)
anim[e] = math.random(1,#walk)
SetAnimationFrames(walk[anim[e]][1],walk[anim[e]][2])
LoopAnimation(e)
g_Entity[e]['animating'] = 2
movemod[e] = 1
end
if DetectPlayer(e) == 1 then
ai_bot_state[e] = "alerted"
end
elseif state == "free roam" then
local x1,z1 = g_Entity[e]['x'],g_Entity[e]['z']
local x2,z2 = destx[e],destz[e]
if CloseTo(x1,z1,x2,z2) < 80*80 then
local ay = math.rad(ent.angley * math.random(-90,90))
destx[e] = ent.x + math.sin(ay) * 500
desty[e] = ent.y
destz[e] = ent.z + math.cos(ay) * 500
else
if ent.animating ~= 2 then
ModulateSpeed(e,1)
anim[e] = math.random(1,#walk)
SetAnimationFrames(walk[anim[e]][1],walk[anim[e]][2])
LoopAnimation(e)
g_Entity[e]['animating'] = 2
movemod[e] = 1
end
end
if DetectPlayer(e) == 1 then
ai_bot_state[e] = "alerted"
end
end
state = ai_bot_state[e]
if state == "alerted" then
PlayCharacterSound(e,"onAlert")
if attack[1][1] ~= -1 then
ai_bot_state[e] = "move to attack"
else
ai_bot_state[e] = "run away"
end
end
state = ai_bot_state[e]
if state == "move to attack" then
destx[e] = g_PlayerPosX
desty[e] = g_PlayerPosY
destz[e] = g_PlayerPosZ
if ent.animating ~= 3 then
ModulateSpeed(e,1.4)
anim[e] = math.random(1,#run)
SetAnimationFrames(run[anim[e]][1],run[anim[e]][2])
LoopAnimation(e)
g_Entity[e]['animating'] = 3
movemod[e] = 1
end
if GetPlayerDistance(e) < attackrange and ent.plrvisible == 1 then
ai_bot_state[e] = "attack"
end
elseif state == "run away" then
local ang = AngleToPoint(e, g_PlayerPosX, g_PlayerPosZ)
local ay = math.rad(ang+180)
destx[e] = ent.x + math.sin(ay) * 500
desty[e] = ent.y
destz[e] = ent.z + math.cos(ay) * 500
local pDist = GetPlayerDistance(e)
if pDist > 2000 then
ai_bot_state[e] = "idle"
elseif pDist > 1200 and walk[1][1] ~= -1 then
if ent.animating ~= 2 then
ModulateSpeed(e,1.4)
anim[e] = math.random(1,#walk)
SetAnimationFrames(walk[anim[e]][1],walk[anim[e]][2])
LoopAnimation(e)
g_Entity[e]['animating'] = 2
movemod[e] = 1
end
else
if ent.animating ~= 3 then
ModulateSpeed(e,1.4)
anim[e] = math.random(1,#run)
SetAnimationFrames(run[anim[e]][1],run[anim[e]][2])
LoopAnimation(e)
g_Entity[e]['animating'] = 3
movemod[e] = 1
end
end
end
state = ai_bot_state[e]
if state == "attack" then
local ay = math.rad(ent.angley)
destx[e] = ent.x + math.sin(ay) * 100
desty[e] = ent.y
destz[e] = ent.z + math.cos(ay) * 100
if DetectPlayer(e) == 0 or GetPlayerDistance(e) > attackrange * 1.1 then
ai_bot_state[e] = "idle"
return
end
if ent.animating ~= 4 then
ModulateSpeed(e,1)
anim[e] = math.random(1,#attack)
SetAnimationFrames(attack[anim[e]][1],attack[anim[e]][2])
PlayAnimation(e)
g_Entity[e]['animating'] = 4
hitplayer[e] = false
movemod[e] = 0
ai_bot_state[e] = "attacking"
end
end
state = ai_bot_state[e]
if state == "attacking" then
PlayCharacterSound(e,"onHurtPlayer")
if ent.animating == 0 then
ai_bot_state[e] = "attack"
return
elseif not hitplayer[e] then
local tframe = GetAnimationFrame(e)
if tframe >= attack[anim[e]][3] - 2 and tframe <= attack[anim[e]][3] + 2 then
HurtPlayer(e, attackdamage[anim[e]])
hitplayer[e] = true
end
end
end
state = ai_bot_state[e]
if state == "flinch" then
local ay = math.rad(ent.angley)
destx[e] = ent.x + math.sin(ay) * 100
desty[e] = ent.y
destz[e] = ent.z + math.cos(ay) * 100
if ent.animating ~= 5 then
PlayCharacterSound(e,"onAlert")
ModulateSpeed(e,1)
anim[e] = math.random(1,#hurt)
SetAnimationFrames(hurt[anim[e]][1],hurt[anim[e]][2])
PlayAnimation(e)
g_Entity[e]['animating'] = 5
movemod[e] = 0
ai_bot_state[e] = "flinching"
end
end
state = ai_bot_state[e]
if state == "flinching" then
PlayCharacterSound(e,"onHurt")
if ent.animating == 0 then
if attack[1][1] ~= -1 then
ai_bot_state[e] = "move to attack"
else
ai_bot_state[e] = "run away"
end
end
end

--triple damage for a headshot
if string.find(string.lower(ent.limbhit), "head") ~= nil then
SetEntityHealth(e,ent.health-(ai_bot_oldhealth[e]-ent.health)*2)
ResetLimbHit(e)
end

if movemod[e] > 0 then

AIEntityGoToPosition(AIObjNo, destx[e], desty[e], destz[e])

end

local movespeed = AIGetEntitySpeed(AIObjNo)
state = ai_bot_state[e]
if state == "idling" then
elseif state ~= "idle" and state ~= "attacking" and state ~= "flinching" then
RotateToPointSlowly(e, destx[e], destz[e], movespeed / 20)
SetRotation(e,0,AIGetEntityAngleY(AIObjNo),0)
if movemod[e] > 0 then
MoveForward(e,movespeed * movemod[e])
end
elseif state ~= "flinching" then
RotateToPlayer(e)
end

AISetEntityPosition(AIObjNo,GetEntityPositionX(e),GetEntityPositionY(e),GetEntityPositionZ(e))

if ent.health < ai_bot_oldhealth[e] then
ai_bot_oldhealth[e] = ent.health
if ai_bot_oldhealth[e] <= flinchat[e] then
flinchat[e] = ai_bot_oldhealth[e] * hurthealthperc
ai_bot_state[e] = "flinch"
end
end
end


function ximporter_orc battlemaster_ai_preexit(e)
SetPreExitValue(e,1)
if ai_bot_state[e] ~= "dead" then
PlayCharacterSound(e,"onDeath")
anim[e] = math.random(1,#death)
SetAnimationFrames(death[anim[e]][1],death[anim[e]][2])
PlayAnimation(e)
g_Entity[e]['animating'] = 5
ai_bot_state[e] = "dead"
elseif g_Entity[e]['animating'] == 0 then
SetPreExitValue(e,2)
end
end

function ximporter_orc battlemaster_ai_exit(e)
CollisionOff(e)
end

function DetectPlayer(e)
local playerdist = GetPlayerDistance(e)
local AIObjNo = g_Entity[e]['obj']
if (playerdist < AIGetEntityViewRange(AIObjNo) and g_Entity[e]['plrvisible'] == 1) or AIGetEntityHeardSound(AIObjNo) == 1 or playerdist < AIGetEntityViewRange(AIObjNo) * 0.25 then
return 1
else
return 0
end
end

function CloseTo(x1,z1,x2,z2)
local DX = x1 - x2
local DZ = z1 - z2
local Dist = DX*DX+DZ*DZ
return Dist
end

function FindPath(e)
local pi = -1
local pp = 0
local pClosest = 999999
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
local pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po)
local pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po)
local pDist = pDX*pDX+pDZ*pDZ
if pDist < pClosest and pDist < 6000 then
pClosest = pDist
pi = pa
pp = po
end
end -- po
end -- pa
local pd = math.random(0,1)
return pi, pp, pd
end

function FollowPath(e)
local px = AIPathGetPointX(pathindex[e],pathpoint[e])
local pz = AIPathGetPointZ(pathindex[e],pathpoint[e])
local tDistX = g_Entity[e]['x'] - px
local tDistZ = g_Entity[e]['z'] - pz
local DistFromPath = tDistX*tDistX+tDistZ*tDistZ
if DistFromPath < 4000 then
if pathdirection[e] == 1 then
pathpoint[e] = pathpoint[e] + 1
local maxp = AIGetPathCountPoints(pathindex[e])
if pathpoint[e] > maxp then
pathpoint[e] = maxp - 1
pathdirection[e] = 0
end
else
pathpoint[e] = pathpoint[e] - 1
if pathpoint[e] < 1 then
pathpoint[e] = 2
pathdirection[e] = 1
end
end
px = AIPathGetPointX(pathindex[e],pathpoint[e])
pz = AIPathGetPointZ(pathindex[e],pathpoint[e])
end
local py = GetTerrainHeight(px,pz)
return px,py,pz
end

function RotateToPoint(e,x,z)
if g_Entity[e] ~= nil and x > 0 and z > 0 then
local destx = x - g_Entity[e]['x']
local destz = z - g_Entity[e]['z']
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle < 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
SetRotation(e,0,angle,0)
return angle
end
end

function AngleToPoint(e,x,z)
if g_Entity[e] ~= nil and x > 0 and z > 0 then
local destx = x - g_Entity[e]['x']
local destz = z - g_Entity[e]['z']
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle < 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
--SetRotation(e,0,angle,0)
return angle
end
end
function RotateToPointSlowly(e,x,z,v)
if g_Entity[e] ~= nil and x > 0 and z > 0 then
if v == nil then
v = 1
end
local destx = x - g_Entity[e]['x']
local destz = z - g_Entity[e]['z']
local angleneeded = math.atan2(destx,destz)
angleneeded = angleneeded * (180.0 / math.pi)
if angleneeded < 0 then
angleneeded = 360 + angleneeded
elseif angleneeded > 360 then
angleneeded = angleneeded - 360
end
local current_angy = g_Entity[e]['angley']
while current_angy < 0 or current_angy > 360 do
if current_angy <= 0 then
current_angy = 360 + current_angy
elseif current_angy > 360 then
current_angy = current_angy - 360
end
end
local L = angleneeded - v
local R = angleneeded + v
if L <= 0 then
L = 360 + L
elseif L > 360 then
L = L - 360
end
if R <= 0 then
R = 360 + R
elseif R > 360 then
R = R - 360
end

--if not already facing the target direction (+/- the rotation speed)
if current_angy < L or current_angy > R then
--do it in 2 halfs so we can account for 0/360 wrap
if current_angy > 180 then
if angleneeded > current_angy - 180 and angleneeded < current_angy then
current_angy = current_angy - v
else
current_angy = current_angy + v
end
else
if angleneeded < current_angy + 180 and angleneeded > current_angy then
current_angy = current_angy + v
else
current_angy = current_angy - v
end
end
SetRotation(e,0,current_angy,0)
return current_angy
end
end
end
PM
GraPhiX
Forum Support
19
Years of Service
User Offline
Joined: 15th Feb 2005
Playing:
Posted: 8th Feb 2024 08:29
This post has been marked by the post author as the answer.
Hi
You have a space in the character name ximporter_orc battlemaster_ai_init(e)
try ximporter_orcbattlemaster_ai_init(e) change ai_man name too and also the name of the script
Welcome to the real world!
Main PC - Windows 10 Pro x64 - Core i7-9700K @4.2GHz - 64GB DDR4 RAM - GeForce RTX 2070 SUPER 8GB - 2TB NVe, 1TB NVe, 2TB Hybrid Data Drive
Test PC - Windows 10 Pro x64 - Core i7-7700K @4.2GHz - 32GB DDR4 RAM - GeForce GTX 1060-6G 6GB - 1TB NVe SSD
Laptop - Helios 300 Predator - i7 7700HQ - 32GB - Nvidia GTX1060 6GB - 525GB M2 - 500 SSD - 17.3" IPS LED Panel - Windows 10 Pro x64
Asset Manager
xRange No Nonsense Tools

Login to post a reply

Server time is: 2024-12-21 14:24:36
Your offset time is: 2024-12-21 14:24:36