Scripts / Need help with the code in my script

Author
Message
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 14:37
Hey Guys, I hope someone can help me with my problem.

If I use multiple skeleton soldiers, the decals will only work with one skeleton soldier or give me an error.

How can I place a decal by each skeleton soldier and have it work with each skeleton soldier ?

example: I put this code at the top of the script flamedecal = {}

Then I put the code right below the the _init(e) flamedecal[e]

Then I use this code in to spawn and follow the skeleton around.
Spawn(flamedecal[e])
CollisionOff(flamedecal[e])
SetPosition(flamedecal[e],GetEntityPositionX(e),GetEntityPositionY(e)+50,GetEntityPositionZ(e))

Now if I do flamedecal[e]= the entity # of the decal for one skeleton it works perfectly, but obviously that only works for one skeleton.

Do you have to add another small script to each decal for it to work in the main ai_fantasycharacter_skeleton script with multiple skeleton soldiers ?

Thanks



Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Apr 2020 15:09
Use particles, a single particle emitter can produce 100 particles by default, each of which can be associated with a separate BPC.
Been there, done that, got all the T-Shirts!
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 15:41
Thanks Amenmoses,

But the only way I know how to do it is to spawn in a entity with a particle attached, so I seem to be in the same boat.

How would you do this ?
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Apr 2020 17:04
I would load the decal as a particle sheet, create an emitter, then for each AI spawn a single particle at a specific position.

You will have to spawn a particle every frame and handle the animation in the script, i.e. increment the frame count and call the appropriate particle command.

What are you actually trying to achieve btw?
Been there, done that, got all the T-Shirts!
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 17:50
The script I posted only works with one skeleton soldier. I would like to use multiple soldiers with the same script, but the way the script is it will only allow one decal and I have to use the entity # of that decal to link to the skeleton.

In the video you can see it works perfectly for one skeleton, but if I add more skeletons with decals next to them it will not work cause it only accepts the one decal entity #

So how can I add more skeletons and decals and have it all work with one script ?







PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Apr 2020 18:34 Edited at: 18th Apr 2020 18:46
In a script attached to the decal add the 'e' value to a list along with a flag saying if it's used or not. Also Hide(e) it.
Then add a global function to find the first unused decal, set the flag for it to used and return the 'e' value.
In the AI script call the function once to get an unused decal and then if one is found Show it and position it each frame.

Something like:

Been there, done that, got all the T-Shirts!
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 18:57
That's what I figured, Make a small script to attach to the decal or entity that the main script recognizes.

I understand the concept, but unfortunately I don't understand how you would go about doing it.

PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 19:08
Strange, your script didn't show up when I first looked at your post.
I will check it now.
Thanks AmenMoses
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Apr 2020 19:08
I added the code.
Been there, done that, got all the T-Shirts!
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 19:32
Is that what you meant ? it didn't seem to work

PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 19:33
script
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 19:39
sorry, I seem to be having problems uploading the scripts for some reason.

I hope this is what you meant. I added this code to the decal script.

local decals = {}
function decal_facing2_init(e)
decals[ e ] = { used = false }
Hide( e )
end
function getDecal()
for k, v in pairs( decals ) do
if not v.used then
v.used = true
Show( k )
return k
end
end
end
function decal_facing2_main(e)
RotateToCamera(e)
if g_Entity[e]['activated'] == 1 then
Destroy(e)
end
end
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 18th Apr 2020 19:40
And this to the Fantasy script.

attackdistance = {}
attackstart = {}
attackend = {}
attacktype = {}
viewrange = {}
damageframestart = {}
damageframeend = {}
lastroar = {}
lastswipe = {}
flamedecal = {}
local decals = {}
function ai_fantasycharacter_skeleton_init(e)

flamedecal[e]= 2
ai_soldier_state[e] = "patrol"
ai_soldier_pathindex[e] = -1
SetAnimationFrames(20010,20137)
LoopAnimation(e)
ModulateSpeed(e,1.0)
SetAnimationSpeed(e,1.0)
attackdistance[e]=65
attackstart[e]=20785
attackend[e]=20825
attacktype[e]=0
damageframestart[e]=20803
damageframeend[e]=20808
lastroar[e] = 0
lastswipe[e] = 0
ai_old_health[e] = -1
SetCharacterSoundSet(e)

end

function ai_fantasycharacter_skeleton_main(e)
local decal = decals[ e ]
if decal == nil and getDecal ~= nil then
decals[ e ] = getDecal()
return
else
-- position decal here
end
PlayerDist = GetPlayerDistance(e)
EntObjNo = g_Entity[e]['obj']
if viewrange[e]==nil then
viewrange[e] = AIGetEntityViewRange(EntObjNo)
end
if ai_soldier_state[e] == "patrol" then
if ai_soldier_pathindex[e] == -1 then
ai_soldier_pathindex[e] = -2
CharacterControlArmed(e)
PathIndex = -1
PathPointIndex = -1
pClosest = 99999
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po)
pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po)
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ))
if pDist < pClosest and pDist < 200 then
pClosest = pDist
PathIndex = pa
PathPointIndex = po
end
end -- po
end -- pa
if PathIndex > -1 then
ai_soldier_pathindex[e] = PathIndex
ai_path_point_index[e] = PathPointIndex
ModulateSpeed(e,1.0)
SetCharacterToWalk(e)
ai_path_point_direction[e] = 1
ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e])
end
end
if ai_soldier_pathindex[e] > -1 then
ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])
AIEntityGoToPosition(EntObjNo,ai_patrol_x[e],ai_patrol_z[e])
tDistX = g_Entity[e]['x'] - ai_patrol_x[e]
tDistZ = g_Entity[e]['z'] - ai_patrol_z[e]
DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistFromPath < 50 then
if ai_path_point_direction[e] == 1 then
ai_path_point_index[e] = ai_path_point_index[e] + 1
if ( ai_path_point_index[e] > ai_path_point_max[e] ) then
ai_path_point_index[e] = ai_path_point_max[e] - 1
ai_path_point_direction[e] = 0
end
else
ai_path_point_index[e] = ai_path_point_index[e] - 1
if ( ai_path_point_index[e] < 1 ) then
ai_path_point_index[e] = 2
ai_path_point_direction[e] = 1
end
end
end
end
end
if PlayerDist < viewrange[e] then
if GetPlayerDistance(e)<attackdistance[e] and g_PlayerHealth>0 then
if ai_soldier_state[e] ~= "attack" then
AIEntityStop(EntObjNo)
ai_soldier_state[e] = "attack"
CharacterControlLimbo(e)
attacktype[e] = 1
SetAnimationFrames(attackstart[e],attackend[e])
PlayAnimation(e)
lastswipe[e] = 0
else
if lastswipe[e]==0 and GetAnimationFrame(e)<attackend[e]-1 then
lastswipe[e]=1
end
if lastswipe[e]==1 and GetAnimationFrame(e)>=attackend[e]-1 then
ai_soldier_state[e] = "patrol"
StopAnimation(e)
lastswipe[e]=2
end
end
else
if ai_soldier_state[e] == "attack" then
if GetAnimationFrame(e)<attackstart[e] or GetAnimationFrame(e)>=attackend[e]-1 then
ai_soldier_state[e] = "patrol"
StopAnimation(e)
end
else
if ai_soldier_state[e] ~= "charge" then
ai_soldier_state[e] = "charge"
CharacterControlArmed(e)
SetCharacterToWalk(e)
ModulateSpeed(e,1.5)
if lastroar[e]==0 then
PlayCharacterSound(e,"onAlert")
lastroar[e]=1
end
end
end
end
if ai_soldier_state[e] == "charge" then
RotateToPlayer(e)
AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ)
Spawn(flamedecal[e])
CollisionOff(flamedecal[e])
SetPosition(flamedecal[e],GetEntityPositionX(e),GetEntityPositionY(e)+50,GetEntityPositionZ(e))
end
if ai_soldier_state[e] == "attack" then
RotateToPlayer(e)
if GetAnimationFrame(e)>damageframestart[e] and GetAnimationFrame(e)<damageframeend[e] then
if attacktype[e] ~= 0 then
PlaySound(e,1)
tdamage = 1+math.random(damageframeend[e]-damageframestart[e])
if attacktype[e]==2 then tdamage=tdamage*2 end
HurtPlayer(e,tdamage)
attacktype[e]=0
end
end
end
end
if ai_old_health[e]==-1 then
ai_old_health[e] = g_Entity[e]['health']
end
if g_Entity[e]['health'] < ai_old_health[e] then
ai_old_health[e] = g_Entity[e]['health']
PlayCharacterSound(e,"onHurt")
end
if PlayerDist >= viewrange[e] and ai_soldier_state[e]~="patrol" then
ai_soldier_state[e] = "patrol"
SetCharacterToWalk(e)
ModulateSpeed(e,1.0)
end
if string.find(string.lower(g_Entity[e]['limbhit']), "head") ~= nil then
SetEntityHealth(e,0)
ResetLimbHit(e)
end
end
function ai_fantasycharacter_skeleton_exit(e)
PlayCharacterSound(e,"onDeath")
CollisionOff(e)
Hide(flamedecal[e])
end
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 18th Apr 2020 21:29
You need to replace "-- position decal here" with some code to actually position the decal!
Been there, done that, got all the T-Shirts!
PM
bluemeenie195
5
Years of Service
User Offline
Joined: 28th Oct 2018
Location:
Posted: 19th Apr 2020 11:29
Thanks for all your help. I'll give it a try
PM

Login to post a reply

Server time is: 2024-04-25 16:44:03
Your offset time is: 2024-04-25 16:44:03