Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-09-2013, 04:32 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
My Rubbish Trivia Script (help)

I'm in the process of developing a trivia system, but please excuse my bad code. I am very new to GS2.
PHP Code:
//#CLIENTSIDE
function onCreated() {
this.+= 0.5;
}
function 
showTriviaGUI() {
new 
GuiWindowCtrl("EventTrivia_Window1") {
    
profile GuiBlueWindowProfile;
    
style $pref::Video::defaultguistyle;
    
clientrelative true;
    
clientextent "384,164";

    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canclose false;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text "Trivia";
    
288;
    
173;

    new 
GuiTextCtrl("EventTrivia_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Please fill out the  text boxes.";
      
width 167;
      
7;
    }
    new 
GuiTextEditCtrl("EventTrivia_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 300;
      
84;
      
37;
    }
    new 
GuiTextCtrl("EventTrivia_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Question";
      
width 53;
      
34;
    }
    new 
GuiTextCtrl("EventTrivia_Text3") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Answer";
      
width 42;
      
74;
    }
    new 
GuiTextEditCtrl("EventTrivia_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 300;
      
84;
      
77;
    }
    new 
GuiButtonCtrl("EventTrivia_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Submit Quesiton";
      
width 385;
      
134;
    }
  }
}

function 
onPlayerChats() {
  if (
player.chat=="/trivia" && player.guild=="Events Team") {
    
showTriviaGUI();
  }
}
function 
EventTrivia_Button1.onAction() {
  
temp.question EventTrivia_TextEdit1.text;
  
temp.answer EventTrivia_TextEdit2.text;
  
showtext(20129.511"Arial""","Last Winner");
  
setimgpart("head207.png",0,60,32,32);
  
changeimgzoom 201,.7;

Here are my questions as followed:
  1. I have a variable for the answer (temp.answer) already. I don't know how to do the rest, for finding the player's answer.
  2. I'm trying to find a way to make a string into an array, like you can in PHP with explode();. Is there a GS2 alternative?
  3. How do I set an image part, but place the image part in a certain location on the level? setimgpart() will just set the NPC's picture to the image, which I don't want.
Thanks in advanced.

Last edited by baseman101; 04-09-2013 at 04:42 AM..
Reply With Quote
  #2  
Old 04-09-2013, 05:16 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I can't post a reply here because of Incapsula, and I'm not going to waste my time trying to figure out which part of my post is causing it to be rejected. If you're reading this, Stefan, this stuff is absolutely ridiculous.

My post is available here.
__________________

Last edited by Tigairius; 04-09-2013 at 05:40 AM.. Reason: link approved
Reply With Quote
  #3  
Old 04-09-2013, 12:05 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
@cbk1994 does he really need to communicate with other players for something like this...? Just have the Event Team member run everything clientsided, and grab other players chat using onRemotePlayerChats() event.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #4  
Old 04-09-2013, 03:46 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Ontop of what cbk1994 posted, its also good practice to apply the notions in this thread.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #5  
Old 04-09-2013, 10:31 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
@cbk1994 does he really need to communicate with other players for something like this...? Just have the Event Team member run everything clientsided, and grab other players chat using onRemotePlayerChats() event.
I would say so. Inevitably there are situations where the events team member will lag out or want to have multiple ETs hosting the event at once or other weird edge cases. You're right that this kind of thing can be handled clientside but I think events like this really should be done serverside.

(not to mention that things like showing text clientside to other players is very unreliable and will cause a lot of problems—so he'll have to do that via some method involving serverside anyway)
__________________
Reply With Quote
  #6  
Old 04-10-2013, 12:28 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Thanks for the help. I'll keep this in mind when doing events in the future.
Reply With Quote
  #7  
Old 05-23-2013, 03:05 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Hey, thanks for your consideration! I've done some triggers once I've got a hold of them, and here's my current code. The current problem is that it doesn't resister if someone wins. I know the variable gets sent, because I've added this.chat=temp.answer previously from serverside. Also, I'm going to add the tokenize function later once I get the main idea down. Sorry, I've tried looking for scripting resources, but no ado. Thank you!

PHP Code:
function onCreated() {
  
setshape13232 );
  
setimg"zoneiphone_tv.png" );
}

function 
onActionTrivia(temp.question,temp.answer) {
  
showtext(19821.617.5"Arial""","Q: " temp.question);
  
changeimgzoom 198,.8;
  
onTimeout(temp.answer); //calls the timeout function with the temp.answer variable
}
function 
onTimeout(temp.answer) {
  for(
temp.pl allplayers) { //gets player in the level
    
if(temp.pl.level.name != "zone_event-trivia.nw") continue; //doesn't count players outside this level
    
if(temp.pl == temp.answer) { //checks if someone wins the event
      
showtext(19821.617.5"Arial""",temp.pl.nick " has won!");
    }
  }
  
setTimer(0.5); //loops it
}
//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat=="/trivia" && player.guild=="Events Team") {
    
showTriviaGUI();
  }
}
function 
showTriviaGUI() {
    new 
GuiWindowCtrl("EventTrivia_Window1") {
    
profile GuiBlueWindowProfile;
    
style $pref::Video::defaultguistyle;
    
clientrelative true;
    
clientextent "384,164";

    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canclose false;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text "Trivia";
    
288;
    
173;
    new 
GuiTextCtrl("EventTrivia_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Please fill out the  text boxes.";
      
width 167;
      
7;
    }
    new 
GuiTextEditCtrl("EventTrivia_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 300;
      
84;
      
37;
    }
    new 
GuiTextCtrl("EventTrivia_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Question";
      
width 53;
      
34;
    }
    new 
GuiTextCtrl("EventTrivia_Text3") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Answer";
      
width 42;
      
74;
    }
    new 
GuiTextEditCtrl("EventTrivia_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 300;
      
84;
      
77;
    }
    new 
GuiButtonCtrl("EventTrivia_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Submit Quesiton";
      
width 385;
      
134;
    }
  }
}
function 
EventTrivia_Button1.onAction() {
  
temp.question EventTrivia_TextEdit1.text;
  
temp.answer EventTrivia_TextEdit2.text;
  
EventTrivia_Window1.destroy();
  
temp.= (GraalControl.width width) / 2//attempt to make the trivia box half of the screen width. help please?
  
triggeraction(this.x,this.y,"Trivia",temp.question,temp.answer); //triggers the server


Last edited by baseman101; 05-23-2013 at 03:05 AM.. Reason: Added comments to make code easier to understand
Reply With Quote
  #8  
Old 05-23-2013, 03:54 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
The first thing you need to do is store the answer in a variable:

PHP Code:
function onActionTrivia(temp.question,temp.answer) {
  if (
player.guild != "Events Team") { // make sure they're allowed to host
    
return;
  }
  
  
showtext(19821.617.5"Arial""","Q: " temp.question);
  
changeimgzoom(198.8);
  
this.answer temp.answer.trim(); // store the answer

You don't need a timeout here; since this is a level NPC, you can just use onPlayerChats serverside:

PHP Code:
function onPlayerChats() {
  if (
player.chat.trim() == this.answer && this.answer != null) {
    
// the player won!
    
showtext(19821.617.5"Arial"""player.nick " has won!");
    
    
// reset the answer so nobody else can win this round
    
this.answer null;
  }

So, your serverside code can be pretty simple:

PHP Code:
function onCreated() {
  
setshape13232 );
  
setimg"zoneiphone_tv.png" );
}

function 
onActionTrivia(temp.question,temp.answer) {
  if (
player.guild != "Events Team") { // make sure they're allowed to host
    
return;
  }
  
  
showtext(19821.617.5"Arial""","Q: " temp.question);
  
changeimgzoom(198.8);
  
this.answer temp.answer.trim(); // store the answer
}

function 
onPlayerChats() {
  if (
player.chat.trim() == this.answer && this.answer != null) {
    
// the player won!
    
showtext(19821.617.5"Arial"""player.nick " has won!");
    
    
// reset the answer so nobody else can win this round
    
this.answer null;
  }

__________________
Reply With Quote
  #9  
Old 05-24-2013, 01:54 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Many thanks. I did not know what was wrong. Thank you

I think that's all the help I need.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.