News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

im stumped sub actions

Started by SA™, May 31, 2008, 12:26:40 AM

Previous topic - Next topic

SA™

ive been reading and reading trying to find out about sub action how do you create theme
ie
index.php?action=multiplayer;sa=poker
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Nathaniel

Are you trying to create a subaction or create a template for a subaction?

If you are trying to mod SMF then you can load different sub templates by using the LoadTemplate() function.

Could you please try to rephrase the question?
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

SA™

sry i should of been more clearer about it i have been developing a simple multiplayer games mod you can see here

http://waynesworld.kicks-ass.net/forum/index.php?action=multiplayer

the onlyy thing is i have the games on there own action ie

/index.php?action=Conquer_Antarctica

and i would like to make them subactions like this

index.php?action=multiplayer;sa=Conquer_Antarctica

http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Nathaniel

#3
This is actually quite simple, you can change the code of the document which has the multiplayer action to something like this.


<?php

if($_REQUEST['sa']=="playgame")
{
// Put code in here for the subaction, or even a link to a separate file or function which contains that code.
}
elseif(
$_REQUEST['sa']=="startgame")
{
// Put code in here for the subaction, or even a link to a separate file or function which contains that code.
}
elseif(
$_REQUEST['sa']=="example")
{
// Put code in here for the subaction, or even a link to a separate file or function which contains that code.
}
else
{
// Show the default page for this overall action.
}

?>



You just need to check the value of subaction each time the user accesses that multiplayer action, you can link between the subactions easily by putting a normal link on the page.

Also remember that you can actually call these variables whatever you want, they don't have to be sa they could be subaction or sub_action or anything else which doesn't interfere with SMF.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

SA™

where would i put that code multiplayer.php?
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Nathaniel

I think so, it really depends on how you are including the multiplayer.php file as an action.

For your case I believe that that is exactly where you should put the code. To me it looks like you are using the Site Integration Mod or you have worked out your own way of including files as actions.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

SA™

ok this is my multiplayer.php

<?php
if (!defined('SMF'))
   die(
'Hacking attempt...');

function 
multiplayer() {
   
// This is gonna be needed...
  
loadTemplate('multiplayer');
}
// Do we have permission?
isAllowedTo('multiplayer_view');

?>





changed it to this

if($_REQUEST['sa']=="poker")
{
//my poker code here
}
elseif($_REQUEST['sa']=="chess")
{
//my chess code
}
elseif($_REQUEST['sa']=="bunny_wars")
{
my bunny_wars code}
else
{
elseif($_REQUEST['sa']=="Conquer_Antarctica")
{
my Conquer_Antarctica code}
else
{

loadTemplate('multiplayer');}


but i get to the multiplayer ok but when i click game it just goes to the forum
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Nathaniel

It looks good to me, except don't forget to comment out the comments otherwise it won't run. ;)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

SA™

http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Nathaniel

Quote{
my bunny_wars code}

Should be

Quote{
//my bunny_wars code
}

It needs to be commented out, and its a comment, so yeah comment out the comment. :)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

SA™

ok now i have this code and its not doing nothing all i can get is the multiplayer main page

when i clck the game it goes to the forum instead


this is the code

<?php
if (!defined('SMF'))
   die(
'Hacking attempt...');
  
// Do we have permission?
isAllowedTo('multiplayer_view'); 
   
if(
$_REQUEST['sa']=="poker")
{
loadTemplate('Texas_Hold_em_Poker_Multiplayer');
}
elseif(
$_REQUEST['sa']=="chess")
{
loadTemplate('Chess_Multiplayer');
}
elseif(
$_REQUEST['sa']=="Conquer_Antarctica")
{
loadTemplate('Conquer_Antarctica_Multiplayer');
}
elseif(
$_REQUEST['sa']=="Bunny_Wars")
{
loadTemplate('Bunny_Wars_Multiplayer');
}
else
{
loadTemplate('multiplayer');
}

?>
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

SA™

woot scratch the last post ive done it dam typo's lol thank you for helping me
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

niko

Code should be in multiplayer function and you should check that subaction is set.
I would also use subtemplates instead of multiple templates.

For example:

<?php
if (!defined('SMF'))
die('Hacking attempt...');

function 
multiplayer()
{
// list is default value for subaction
$_REQUEST['sa'] = !empty($_REQUEST['sa']) ? $_REQUEST['sa'] : 'list';

if ($_REQUEST['sa'] == 'poker')
{
loadTemplate('Texas_Hold_em_Poker_Multiplayer');
}
// other games here
else
{
loadTemplate('multiplayer');
}
}
?>

Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

SA™

whats the difference what are sub templates:D


noobie aleart
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Dragooon

Templates are different files, whereas sub-templates are templates within template files
For example
<?php
function template_xyz_list() {
echo 
'test';
}
function 
template_xyz_view(){
echi 'test';
}
?>

Now that have 2 sub-templates, xyz_list and xyz_view.

You can all them by
<?php
function xyz() {
loadTemplate('xyz');
if(
$_REQUEST['sa'] == 'list')
$context['sub_template'] = 'xyz_list';
else
$context['sub_template'] = 'xyz_view';
}
?>

By default "main" is loaded if no sub_template is defined.

SA™

oh i think iget it now so your saying instead of having this

loadTemplate('Texas_Hold_em_Poker_Multiplayer');

i could put the acuall poker code?


http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Dragooon

No not that
Lets say you got 2 templates multiplayer_poker and multiplayer_roulette, now you want to make them one
So create a template lets say it as multiplayer.template.php and for multiplayer.php do it like this
<?php
function multiplayer() {
global 
$context;
loadTemplate('multiplayer');
if(
$_REQUEST['sa'] == 'poker')
$context['sub_template'] = 'multiplayer_poker';
else
$context['sub_template'] = 'multiplayer_roulette';
}
?>

Now in multiplayer.template.php put
<?php
function template_multiplayer_poker() {
echo 
'YOUR POKER CODE HERE';
}
function 
template_multiplayer_roulette() {
echo 
'YOUR ROULETTE CODE HERE';
}
?>

SA™

sry that last post was dumb :D i think i understand now you saying instead of haviing five template's i could just have one bookmarked this post gonna try it tonight thanks
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

SA™

Quote from: Dragooon on May 31, 2008, 03:07:43 AM
No not that
Lets say you got 2 templates multiplayer_poker and multiplayer_roulette, now you want to make them one
So create a template lets say it as multiplayer.template.php and for multiplayer.php do it like this
<?php
function multiplayer() {
global 
$context;
loadTemplate('multiplayer');
if(
$_REQUEST['sa'] == 'poker')
$context['sub_template'] = 'multiplayer_poker';
else
$context['sub_template'] = 'multiplayer_roulette';
}
?>

Now in multiplayer.template.php put
<?php
function template_multiplayer_poker() {
echo 
'YOUR POKER CODE HERE';
}
function 
template_multiplayer_roulette() {
echo 
'YOUR ROULETTE CODE HERE';
}
?>



ive done tha now im getting this error

Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\test\Sources\multiplayer.php on line 18

my code

<?php
function multiplayer() {

global 
$context;
if (!
defined('SMF'))
   die(
'Hacking attempt...');
  
// Do we have permission?
isAllowedTo('multiplayer_view'); 
//load the template
loadTemplate('multiplayer');

if(
$_REQUEST['sa']=="Poker")
// Do we have permission?
isAllowedTo('multiplayer_play');
//load up the games 
$context['sub_template'] = 'Texas_Hold_em_Poker_Multiplayer';

else

// Do we have permission?
isAllowedTo('multiplayer_play');
//load up the games 
$context['sub_template'] = 'Chess_Multiplayer';

else

// Do we have permission?
isAllowedTo('multiplayer_play');
//load up the games 
$context['sub_template'] = 'Conquer_Antarctica_Multiplayer';

else

// Do we have permission?
isAllowedTo('multiplayer_play');
//load up the games 
$context['sub_template'] = 'Bunny_Wars_Multiplayer';
}
?>
[code]
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Dragooon

You forgot the braces { }

It should be
<?php
function multiplayer() {

global 
$context;
if (!
defined('SMF'))
   die(
'Hacking attempt...');
  
// Do we have permission?
   
isAllowedTo('multiplayer_view'); 
//load the template
   
loadTemplate('multiplayer');

if(
$_REQUEST['sa']=="Poker")
{
// Do we have permission?
   
isAllowedTo('multiplayer_play');
   
//load up the games 
$context['sub_template'] = 'Texas_Hold_em_Poker_Multiplayer';
}
else
{
// Do we have permission?
   
isAllowedTo('multiplayer_play');
   
//load up the games 
$context['sub_template'] = 'Chess_Multiplayer';
}
else
{
// Do we have permission?
   
isAllowedTo('multiplayer_play');
   
//load up the games 
$context['sub_template'] = 'Conquer_Antarctica_Multiplayer';
}
else
{
// Do we have permission?
   
isAllowedTo('multiplayer_play');
   
//load up the games 
$context['sub_template'] = 'Bunny_Wars_Multiplayer';
}
}
?>

Advertisement: