Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   My Rubbish Trivia Script (help) (https://forums.graalonline.com/forums/showthread.php?t=134268065)

baseman101 04-09-2013 04:32 AM

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.

cbk1994 04-09-2013 05:16 AM

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.

xXziroXx 04-09-2013 12:05 PM

@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.

BlueMelon 04-09-2013 03:46 PM

Ontop of what cbk1994 posted, its also good practice to apply the notions in this thread.

cbk1994 04-09-2013 10:31 PM

Quote:

Originally Posted by xXziroXx (Post 1715973)
@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)

baseman101 04-10-2013 12:28 AM

Thanks for the help. I'll keep this in mind when doing events in the future.

baseman101 05-23-2013 03:05 AM

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



cbk1994 05-23-2013 03:54 AM

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;
  }



baseman101 05-24-2013 01:54 AM

Many thanks. I did not know what was wrong. Thank you :)

I think that's all the help I need.


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

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