dandylion
03-29-2011, 04:39 PM
I saw in the big "how to" post there was a link for how to implement custom UI to do something like a scoreboard. The link is however non-existant. More or less two things I want to do:
Announce when a team reaches 50 "points" (I'm using charges on an ability to store the value if that makes any difference).
Create a scoreboard which shows what the score for each team is.
Any tips or examples I could draw some inspiration from?
Oloko
03-30-2011, 07:18 AM
To display a message to everyone, you will need to create an overlay UI like they do in the tutorial.s2 map. To create your own overlay, you can try by following the tutorial, but instead of using the "download this mod and place it on your map...", simply use your own file. So it would be something like:
Create a overlay file, here I will use custommap_interface.interface. The file will go into the "ui" folder of your map. Put this content in the file:
<?xml version="1.0" encoding="UTF-8"?>
<interface name="custommap_interface" temp="true">
</interface>
Add this line to game.resources: <interface file="/ui/custommap_interface.interface"/>
Add this line to fe2.interfaceset: <interface name="custommap_interface" file="/ui/custommap_interface.interface" precache="true" />
Add this line to <onaddplayer>: <setoverlayinterface entity="target_entity" name="custommap_interface" />
This will show your custom overlay to the player when he's added to the game. Now you can add content to it, it will show up on top of the original UI. This way you can ADD content to the UI, without actually editing anything (so people can still use their custom UI mods with your map). If you want to change existing part of the UI, I think you will need to add them to your map and change what you need.
Now back to displaying a message, I would add this to your interface file.
<trigger name="custommap_message" />
<panel noclick="1" watch="custommap_message" ontrigger="LocalChat('My custom message is awesome!');" />So here I have now a trigger that will print a message into the chat if triggered. So now we need to go into our entity file to script it. Find where in your scripting the message should be displayed and then write this line:
<clientuitrigger name="custommap_message" param="1" />
This will change the trigger value, thus making the message appear. The param can be used by the UI as the variable "param". Sadly you can't send variables in it, only text, so its pretty limited.
You can do thing that would look better than simply writing the text in the chat (like a popup or notification board). You can look into the tutorial if you want some example of custom UI interaction with scripting.
For your scoreboard, like I said, there is no way to actually send a variable in the param attribute. So you can either to a bunch of compare like this:
<compare a="var0" b="1" op="eq">
<clientuitrigger name="score" param="1" />
</compare>
<else>
<compare a="var0" b="2" op="eq">
<clientuitrigger name="score" param="2" />
</compare>
<else>
...
</else>
</else>But that would be pretty useless in most case. Another more viable solution would be to always send an update of the score that is stored on an entity (using charges, accumulator or param). So you will always send a param of 1 to the UI, and the UI will only increment its score value. You can do it by adding this to your UI:
<trigger name="custommap_score" />
<!-- Score -->
<panel y="50" width="59.6h" height="7.45h" align="center" valign="top" noclick="1">
<label x="0.3h" width="40%" height="100%" textalign="left" textvalign="center" font="dyn_9" color="white" content="author"/>
<label onload="CreateInt('_custommap_score', 0); SetText('Score: ^r0');" width="60%" height="100%" align="center" textalign="center" textvalign="center" font="dyn_9" color="white" watch="custommap_score" ontrigger="SetText('Score: ^r' # Round(_custommap_score + param)); _custommap_score = _custommap_score + param;"/>
</panel>So this will create a panel under the team score that will display "Score: " and the score in red. On the panel label creation, it will create a LOCAL variable of type integer named "_custommap_score" that will be used to store the score. This mean that this variable can be edited via the console by the client. That's why all the validation for the score is done with your entity script and not the UI script, since they can't edit your entity property, but they can change the score display. Now to send an update to the score, go where the score is updated in your entity and add this line:
<clientuitrigger name="custommap_message" param="10" />
This will add 10 "points" to the score. So the first time its called, it will display 10. The second time it will then display 20 and so on.
Of course here you could do some compare to add a range of predefined value. For example, my BeHoNeled can add to the score 10 to 60 points at one time. So you can do a simple compare to add the right number to increment.
I don't know much about custom UI, so there might be a better way to do all of this, but I guess for now this could help you.
dandylion
03-30-2011, 07:34 AM
It looks great. Thanks for going to all the trouble. I'll try out what you've got and hopefully I'll have what I need in the end.
dandylion
03-30-2011, 04:07 PM
In what file do you find the <onaddplayer> ?
Schm0ftie
03-30-2011, 04:23 PM
I would say game_info.entity in your maps/resources
Thats taken from the game_info.entity from the tutorial map:
<onaddplayer>
<setteamsize team="0" size="1" />
<changeteam entity="target_entity" team="0" />
<setinterface entity="target_entity" name="game_blank" />
<setoverlayinterface entity="target_entity" name="game_tutorial1" />
<createcamera name="pcam1" position="1000.0 1000.0" pushentity="true" />
<setcamera entity="target_entity" camera="stack_entity" /> <!-- Link player's view to camera1 -->
</onaddplayer>