The online racing simulator
Creating Button to players error
Hello. I am scripting PRISM for fun, and there is failure when I am creating a button. When I create a button, ant write user's UCID, the button is displaying to host, not to player. I am using PRISM 0.4.4 . Does anyone know fix of this bug?
It is no bug, you are doing something wrong yourself but without showing what you are actually are doing it's pretty difficult to say where you made a mistake.
I will post my code:
class welcome extends Plugins
{
const URL = 'http://lfsforum.net/forumdisplay.php?f=312';
const NAME = 'Welcome & MOTD';
const AUTHOR = 'PRISM Dev Team';
const VERSION = PHPInSimMod::VERSION;
const DESCRIPTION = 'Welcome messages for clients, and Message of the Day (MOTD)';

public function __construct()
{
$this->registerPacket('onPrismConnect', ISP_VER);
$this->registerPacket('onClientConnect', ISP_NCN);
$this->registerSayCommand('komanda', 'cmdTestas', 'Information about the triggers purpose goes here.');
}

public function onPrismConnect(IS_VER $VER)
{
IS_MSX()->Msg('PRISM Version ^3'.PHPInSimMod::VERSION.'^8 Has Connected.')->Send();
}

public function onClientConnect(IS_NCN $NCN)
{
$MTC = IS_MTC()->Sound(SND_SYSMESSAGE)->UCID($NCN->UCID);
$MTC->Text('^1Hello :)')->Send();
}
public function cmdTestas($cmd, $ucid)
{
global $PRISM;
$btn_close = new Button($ucid, 'testbtn', 'test');
$btn_close->Text('Click me');
$btn_close->L(120)->T(40)->W(20)->H(20)->BStyle = ISB_CLICK;
$btn_close->registerOnClick($this, 'click');
$btn_close->send();

return PLUGIN_HANDLED;
}
public function click()
{
IS_MSX()->Msg('Clicked a button!')->Send();
}
}

What I am doing wrong?
You are doing nothing wrong, couldn't see anything wrong but to make absolutely sure I tested your code a moment ago and it should work as you expect it to be. It creates a button on my screen with Clickme when I type komanda and when clicked the hosts responds with "Clicked a button!" in public chat (with 31 people connected )

So something else is going on, you are sure it's using the host $ucid ? Debug with echo $ucid and;


if (($clients = $this->getHostState($hostID)->clients) && $clients !== NULL)
{
var_dump($clients);
}

to check what UCIDs actually are assigned.
Or it could be that the settings are only making the buttons local. I'm pretty sure it's a flag in the ISP_ISI packet.

If your running a host that is also the client in the game, you might be tripping over the ISF_LOCAL flag.
Quote from cargame.nl :You are doing nothing wrong, couldn't see anything wrong but to make absolutely sure I tested your code a moment ago and it should work as you expect it to be. It creates a button on my screen with Clickme when I type komanda and when clicked the hosts responds with "Clicked a button!" in public chat (with 31 people connected )

So something else is going on, you are sure it's using the host $ucid ? Debug with echo $ucid and;


if (($clients = $this->getHostState($hostID)->clients) && $clients !== NULL)
{
var_dump($clients);
}

to check what UCIDs actually are assigned.

When I wrote your code to my script, I got this:
Loaded cvars.ini
Loaded hosts.ini
Loaded http.ini
Listening for http requests on 127.0.0.1:80
Loaded telnet.ini
Loaded admins.ini
Loaded plugins.ini
Loading plugins
Loading plugin: admin
Loading plugin: welcome
2 Plugins Loaded.
Connecting to 192.168.0.30:29999 ... #1
Connected to 192.168.0.30:29999
< IS_VER Packet from Cruise.
> TINY_ISM Packet to Cruise.
> TINY_SST Packet to Cruise.
> TINY_NCN Packet to Cruise.
> TINY_NPL Packet to Cruise.
> TINY_RES Packet to Cruise.
> TINY_GTH Packet to Cruise.
> TINY_SCP Packet to Cruise.
> TINY_REO Packet to Cruise.
> TINY_RST Packet to Cruise.
> TINY_AXI Packet to Cruise.
> TINY_NLP Packet to Cruise.
> TINY_MCI Packet to Cruise.
> TINY_RIP Packet to Cruise.
< IS_ISM Packet from Cruise.
> TINY_NCN Packet to Cruise.
> TINY_NPL Packet to Cruise.
> TINY_RES Packet to Cruise.
< IS_STA Packet from Cruise.
< IS_NCN Packet from Cruise.
< SMALL_RTP Packet from Cruise.
< IS_REO Packet from Cruise.
< IS_RST Packet from Cruise.
< IS_AXI Packet from Cruise.
< IS_RIP Packet from Cruise.
< IS_NCN Packet from Cruise.
< IS_MSO Packet from Cruise.
< IS_NCN Packet from Cruise.
< IS_STA Packet from Cruise.
< IS_MSO Packet from Cruise.
> IS_BTN Packet to Cruise.
array(2) {
[0]=>
object(ClientHandler)#14 (9) {
["players"]=>
array(0) {
}
["UCID":protected]=>
int(0)
["UName":protected]=>
string(0) ""
["PName":protected]=>
string(4) "host"
["Admin":protected]=>
int(1)
["Total":protected]=>
int(1)
["Flags":protected]=>
int(0)
["parent"]=>
object(StateHandler)#12 (47) {
["handles":protected]=>
array(25) {
[1]=>
string(11) "onInSimInit"
[2]=>
string(9) "onVersion"
[3]=>
string(6) "onTiny"
[4]=>
string(7) "onSmall"
[5]=>
string(13) "onStateChange"
[9]=>
string(22) "onCameraPosisionChange"
[10]=>
string(18) "onMultiPlayerStart"
[17]=>
string(11) "onRaceStart"
[36]=>
string(9) "onReorder"
[37]=>
string(15) "onNodeLapPlayer"
[38]=>
string(14) "onMultiCarInfo"
[43]=>
string(11) "onAutoXInfo"
[48]=>
string(19) "onReplayInformation"
[18]=>
string(14) "onClientPacket"
[19]=>
string(14) "onClientPacket"
[20]=>
string(14) "onClientPacket"
[21]=>
string(14) "onPlayerPacket"
[22]=>
string(14) "onPlayerPacket"
[23]=>
string(14) "onPlayerPacket"
[34]=>
string(14) "onPlayerPacket"
[35]=>
string(14) "onPlayerPacket"
[31]=>
array(2) {
[0]=>
string(14) "onClientPacket"
[1]=>
string(14) "onPlayerPacket"
}
[42]=>
string(16) "onButtonFunction"
[46]=>
string(13) "onButtonClick"
[47]=>
string(12) "onButtonText"
}
["clients"]=>
*RECURSION*
["players"]=>
array(0) {
}
["Version":protected]=>
NULL
["Product":protected]=>
NULL
["InSimVer":protected]=>
NULL
["ReplaySpeed":protected]=>
float(1)
["State":protected]=>
int(2560)
["InGameCam":protected]=>
int(0)
["ViewPLID":protected]=>
int(0)
["NumP":protected]=>
int(0)
["NumConns":protected]=>
int(2)
["NumFinished":protected]=>
int(0)
["RaceInProg":protected]=>
int(0)
["QualMins":protected]=>
int(0)
["RaceLaps":protected]=>
int(0)
["Track":protected]=>
string(3) "BL1"
["Weather":protected]=>
int(2)
["Wind":protected]=>
int(0)
["Pos":protected]=>
NULL
["Heading":protected]=>
NULL
["Pitch":protected]=>
NULL
["Roll":protected]=>
NULL
["FOV":protected]=>
NULL
["Time":protected]=>
NULL
["Host"]=>
int(1)
["HName"]=>
string(12) "^2Test server"
["Flags"]=>
int(544)
["NumNodes"]=>
int(323)
["Finish"]=>
int(301)
["Split1"]=>
int(86)
["Split2"]=>
int(213)
["Split3"]=>
int(65535)
["Info":protected]=>
NULL
["NumC":protected]=>
NULL
["AXStart":protected]=>
int(0)
["NumCP":protected]=>
int(0)
["NumO":protected]=>
int(0)
["LName":protected]=>
string(0) ""
["Error":protected]=>
int(2)
["MPR":protected]=>
int(0)
["Paused":protected]=>
int(0)
["Options":protected]=>
int(0)
["CTime":protected]=>
int(0)
["TTime":protected]=>
int(0)
["RName":protected]=>
string(0) ""
["PLID"]=>
array(0) {
}
}
["PRISM"]=>
bool(false)
}
[1]=>
object(ClientHandler)#13 (9) {
["players"]=>
array(0) {
}
["UCID":protected]=>
int(1)
["UName":protected]=>
string(11) "TRUCKER LTU"
["PName":protected]=>
string(9) "^1Trucker"
["Admin":protected]=>
int(1)
["Total":protected]=>
int(2)
["Flags":protected]=>
int(4)
["parent"]=>
object(StateHandler)#12 (47) {
["handles":protected]=>
array(25) {
[1]=>
string(11) "onInSimInit"
[2]=>
string(9) "onVersion"
[3]=>
string(6) "onTiny"
[4]=>
string(7) "onSmall"
[5]=>
string(13) "onStateChange"
[9]=>
string(22) "onCameraPosisionChange"
[10]=>
string(18) "onMultiPlayerStart"
[17]=>
string(11) "onRaceStart"
[36]=>
string(9) "onReorder"
[37]=>
string(15) "onNodeLapPlayer"
[38]=>
string(14) "onMultiCarInfo"
[43]=>
string(11) "onAutoXInfo"
[48]=>
string(19) "onReplayInformation"
[18]=>
string(14) "onClientPacket"
[19]=>
string(14) "onClientPacket"
[20]=>
string(14) "onClientPacket"
[21]=>
string(14) "onPlayerPacket"
[22]=>
string(14) "onPlayerPacket"
[23]=>
string(14) "onPlayerPacket"
[34]=>
string(14) "onPlayerPacket"
[35]=>
string(14) "onPlayerPacket"
[31]=>
array(2) {
[0]=>
string(14) "onClientPacket"
[1]=>
string(14) "onPlayerPacket"
}
[42]=>
string(16) "onButtonFunction"
[46]=>
string(13) "onButtonClick"
[47]=>
string(12) "onButtonText"
}
["clients"]=>
*RECURSION*
["players"]=>
array(0) {
}
["Version":protected]=>
NULL
["Product":protected]=>
NULL
["InSimVer":protected]=>
NULL
["ReplaySpeed":protected]=>
float(1)
["State":protected]=>
int(2560)
["InGameCam":protected]=>
int(0)
["ViewPLID":protected]=>
int(0)
["NumP":protected]=>
int(0)
["NumConns":protected]=>
int(2)
["NumFinished":protected]=>
int(0)
["RaceInProg":protected]=>
int(0)
["QualMins":protected]=>
int(0)
["RaceLaps":protected]=>
int(0)
["Track":protected]=>
string(3) "BL1"
["Weather":protected]=>
int(2)
["Wind":protected]=>
int(0)
["Pos":protected]=>
NULL
["Heading":protected]=>
NULL
["Pitch":protected]=>
NULL
["Roll":protected]=>
NULL
["FOV":protected]=>
NULL
["Time":protected]=>
NULL
["Host"]=>
int(1)
["HName"]=>
string(12) "^2Test server"
["Flags"]=>
int(544)
["NumNodes"]=>
int(323)
["Finish"]=>
int(301)
["Split1"]=>
int(86)
["Split2"]=>
int(213)
["Split3"]=>
int(65535)
["Info":protected]=>
NULL
["NumC":protected]=>
NULL
["AXStart":protected]=>
int(0)
["NumCP":protected]=>
int(0)
["NumO":protected]=>
int(0)
["LName":protected]=>
string(0) ""
["Error":protected]=>
int(2)
["MPR":protected]=>
int(0)
["Paused":protected]=>
int(0)
["Options":protected]=>
int(0)
["CTime":protected]=>
int(0)
["TTime":protected]=>
int(0)
["RName":protected]=>
string(0) ""
["PLID"]=>
array(0) {
}
}
["PRISM"]=>
array(3) {
["accessFlags"]=>
int(2528454)
["connection"]=>
string(6) "Cruise"
["temporary"]=>
bool(true)
}
}
}

Quote from Dygear :Or it could be that the settings are only making the buttons local. I'm pretty sure it's a flag in the ISP_ISI packet.

If your running a host that is also the client in the game, you might be tripping over the ISF_LOCAL flag.

I host with DEDI, if you have this in mind. I think, that defined settings is bad.
How can I define flags in ISP_ISI packet on PRISM?
Quote from TRUCKER LTU :
How can I define flags in ISP_ISI packet on PRISM?

@ /configs/hosts.ini

example;


flags = 72

Of course together with your other settings ip/port/sockettype/password/pps etc.
Thank you, now it is working
But not all functions
When I create button, and click on that button, I get an error:

PHP WARNING:
call_user_func_array() expects parameter 2 to be array, null given in xxxx\modules\prism_button.php on line 52
1 :: call_user_func_array in xxxxmodules\prism_button.php:52
2 :: click in xxxx\modules\prism_buttonmanager.php:152
3 :: onButtonClick in xxxx\modules\prism_statehandler.php:123
4 :: onButtonClick in xxxx\modules\prism_statehandler.php:61
5 :: dispatchPacket in xxxx\modules\prism_hosts.php:576
6 :: inspectPacket in xxxx\modules\prism_hosts.php:487
7 :: handlePacket in xxxx\modules\prism_hosts.php:353
8 :: checkTraffic in xxxx\PHPInSimMod.php:228

Any ideas?
Quote from TRUCKER LTU :Thank you, now it is working
But not all functions
When I create button, and click on that button, I get an error:
Any ideas?

From what I can tell, everything looks right, hmm maybe try doing


<?php 
$btn_close
->registerOnClick($this'click', array()); 
?>

and see if that helps, if not reply, and I'll look further into it..(you shouldn't need the empty array, but that may be a temp fix.)
No that code he posted earlier is correct. It looks good and I tested it and it also works like it should.

@TRUCKER LTU; you probably changed something without telling what you changed to us
Quote from cargame.nl :No that code he posted earlier is correct. It looks good and I tested it and it also works like it should.

@TRUCKER LTU; you probably changed something without telling what you changed to us

I knew it was correct, but I figured worst case scenario, that should fix it... I think... I've coded my own Button Manager, so I'm not 100% sure on how the buttons work in the built in PRISM button manager...

FGED GREDG RDFGDR GSFDG