Question about some functions/scripts

» Siedler Map Source Forum » Siedler DEdK Script Forum » Question about some functions/scripts

Seiten: 1

Qba331PL
#1
07.03.2018 11:01
Beiträge: 102

Question about some functions/scripts

Hello

I'm working at my new map and I want to use some new functions. I've got a little problem with them. Can you help me?

1st: I want to use function that change fraction of entities that hasn't been created in editor but in game. For example, when you create serf and then he moves to position1, his faction changes. Can you show me how this function looks like?

2nd: When bulding's HP isn't full (for example 50%), something happens.

3rd: Function that checks if the bulding was built on position2

Best Regards,
Qba331PL

mcb
#2
07.03.2018 16:26
Beiträge: 1472

1: You mean player? Just use ChangePlayer(entity, player) .
Changing player, when near a position would look like this:

function startSerf()
   CreateEntity(5, Entities.PU_Serf, GetPosition("serfSpawn"), "serf") -- create a serf and set its scriptname to serf
   Move("serf", GetPosition("serfTarget")) -- move him
   StartSimpleJob("serfCheckPosJob") -- call this function every second, to check its position
end

function serfCheckPosJob()
   if IsNear("serf", "serfTarget", 500) then -- check if the serf is near the target pos
      ChangePlayer("serf", 1) -- change player
      return true -- end job
   end
end



2: Health check works with Logic.GetEntityHealth and Logic.GetEntityMaxHealth (both only accept the entity id)
50% health would be something like this:

local id = GetID("serf")
local hpPerc = Logic.GetEntityHealth(id) / Logic.GetEntityMaxHealth(id) * 100
if hpPerc < 50 then
   something()
end



3: Only way would be checking the area for entities with Logic.GetPlayerEntitiesInArea(_playerId, _entityType, _posX, _posY, _range, _amount) :

local pos = GetPosition("somewhere")
local t = {Logic.GetPlayerEntitiesInArea(1, Entities.PB_Farm1, pos.X, pos.Y, 1000, 16)} -- max amount is 16, returns numberOfIds, id1, id2...
table.remove(t, 1) -- throw away numberOfIds
for _,id in ipairs(t) then -- iterate over the ids
   if Logic.IsConstructionComplete(id)==1 then -- checks if the construction is completed
      SetEntityName(id, "farmNearSomewhere") -- this seths the entityname, so you can do whatever you want with this entity
      break -- end the iteration, if you assign the same name to more than one entity you get problems
   end
end

Qba331PL
#3
08.03.2018 10:27
Beiträge: 102

Zitat von mcb:
1: You mean player? Just use ChangePlayer(entity, player) .
Changing player, when near a position would look like this:

function startSerf()
   CreateEntity(5, Entities.PU_Serf, GetPosition("serfSpawn"), "serf") -- create a serf and set its scriptname to serf
   Move("serf", GetPosition("serfTarget")) -- move him
   StartSimpleJob("serfCheckPosJob") -- call this function every second, to check its position
end

function serfCheckPosJob()
   if IsNear("serf", "serfTarget", 500) then -- check if the serf is near the target pos
      ChangePlayer("serf", 1) -- change player
      return true -- end job
   end
end



But how to change player of serf that was created in castle by someone, not by script.

mcb
#4
08.03.2018 14:34
Beiträge: 1472

Combine 1) and 3) from my last post:

local pos = GetPosition("somewhere")
local t = {Logic.GetPlayerEntitiesInArea(1, Entities.PU_Serf, pos.X, pos.Y, 1000, 16)} -- max amount is 16, returns numberOfIds, id1, id2...
table.remove(t, 1) -- throw away numberOfIds
for _,id in ipairs(t) then
   ChangePlayer(id, 5)
end

Qba331PL
#5
08.03.2018 15:59
Beiträge: 102

Zitat von mcb:
Combine 1) and 3) from my last post:

local pos = GetPosition("somewhere")
local t = {Logic.GetPlayerEntitiesInArea(1, Entities.PU_Serf, pos.X, pos.Y, 1000, 16)} -- max amount is 16, returns numberOfIds, id1, id2...
table.remove(t, 1) -- throw away numberOfIds
for _,id in ipairs(t) then
   ChangePlayer(id, 5)
end



Ok but when I test script it showes me LUA_ERRSYNTAX.

mcb
#6
08.03.2018 16:06
Beiträge: 1472

Oh, yes, it is for ... do instead of for ... then:

local pos = GetPosition("somewhere")
local t = {Logic.GetPlayerEntitiesInArea(1, Entities.PU_Serf, pos.X, pos.Y, 1000, 16)} -- max amount is 16, returns numberOfIds, id1, id2...
table.remove(t, 1) -- throw away numberOfIds
for _,id in ipairs(t) do
   ChangePlayer(id, 5)
end

Qba331PL
#7
08.03.2018 16:32
Beiträge: 102

Thanks

Now it works perfect. Much thanks

Seiten: 1

SiteEngine v1.5.0 by nevermind, ©2005-2007
Design by SpiderFive (www.siedler-games.de) - English translation by juja

Impressum