Multiplayer scripts

» Siedler Map Source Forum » Siedler DEdK Script Forum » Multiplayer scripts

Seiten: 1

Qba331PL
#1
04.05.2018 16:23
Beiträge: 102

Multiplayer scripts

Hi!

I don't know how to use script that checks name of the player (in multiplayer game) and puts it in message.
For example: My in game name is Qba. Script take it and then start message function:

Message("<<Qba>> destroyed your castle."

Can you help me?

Best regards,
Qba331PL

mcb
#2
04.05.2018 18:02
Beiträge: 1472

In SP UserTool_GetPlayerName returns exactly your username. (Looking at the function, it should also work in MP, but i didn't test this)

So your Message should look like this:

Message(" @color:255,0,0 "..UserTool_GetPlayerName(player).." destroyed your castle!")

Qba331PL
#3
04.05.2018 18:44
Beiträge: 102

Zitat von mcb:
In SP UserTool_GetPlayerName returns exactly your username. (Looking at the function, it should also work in MP, but i didn't test this)

So your Message should look like this:

Message(" @color:255,0,0 "..UserTool_GetPlayerName(player).." destroyed your castle!")



Ok, and when I want to use another player name I should use:
"..UserTool_GetPlayerName(player2).."
???

mcb
#4
04.05.2018 18:55
Beiträge: 1472

You have to replace it with the number you want. So for player 1 UserTool_GetPlayerName(1) and for player 2 UserTool_GetPlayerName(2) .

RitterLeo
#5
04.05.2018 19:33
Beiträge: 237

Look in the Script-Wiki that can all help.

____________________
Die Gier eines Menschen kann man mit der einer Pflanze vergleichen:
Hat sie einmal genug Wasser und Sonne wächst sie um noch mehr zu bekommen.

Qba331PL
#6
04.05.2018 21:07
Beiträge: 102

Thank you very much guys

Qba331PL
#7
05.05.2018 12:05
Beiträge: 102

Oh, one more thing.
I want to make script that counts how many towers has been destroyed and then shows it in message. I guess I must use a variable.

It should be something like that:


Variable --> t=0


StartSimpleJob("Tower1")
StartSimpleJob("Tower2")

function Tower1
if IsDestroyed("Tower1") then
t=t+1
Message("You have destroyed "t" enemy towers.")
return true
end
end

function Tower1
if IsDestroyed("Tower2") then
t=t+1
Message("You have destroyed "t" enemy towers.")
return true
end
end



but I'm not sure if it is ok and I don't really know create/initiate variable. Can you help me?

mcb
#8
05.05.2018 14:45
Beiträge: 1472

Creating+initializing a variable looks like this:

destroyedTowers = 0


You can use any name you want, but for a global variable like this, it is best to use a name which says what is stored in it (so no other function uses the same ).

But your code has an error:

Message("You have destroyed "t" enemy towers.")


should look like this:

Message("You have destroyed "..t.." enemy towers.")


The .. is an operator like + which concatenates its two arguments (and converts them to strings if they aren't).

Another thing: You write two (or more) functions Tower1, Tower2, ... that are basically the same. Putting the only difference into a parameter allowes you to use only one function:

function checkTowerDestroyed(towername)
   if IsDestroyed(towername) then
      destroyedTowers = destroyedTowers + 1
      Message("You have destroyed "..destroyedTowers.." enemy towers.")
      return true
   end
end

destroyedTowers = 0
Trigger.RequestTrigger(Events.LOGIC_EVENT_EVERY_SECOND, nil, "checkTowerDestroyed", 1, nil, {"Tower1"})
Trigger.RequestTrigger(Events.LOGIC_EVENT_EVERY_SECOND, nil, "checkTowerDestroyed", 1, nil, {"Tower2"})


(This is not an optimal example, because StartSimpleJob does not accept parameters and i have to use Trigger.RequestTrigger instead.)
(Also a more efficient solution would use an EntityDestroyed-Trigger, but that is a bit more complicated. If you want to see it, just ask.)

Qba331PL
#9
05.05.2018 15:47
Beiträge: 102

Thank you mcb. Now I understand it.
You are real Lua genius.

Best regards,
Qba331PL

Seiten: 1

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

Impressum