Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Help With A Buybable Hat Script Please? (https://forums.graalonline.com/forums/showthread.php?t=134263806)

Gunderak 07-09-2011 04:19 PM

Help With A Buybable Hat Script Please?
 
basically i have a hat setup as a weapon so u equip it and press d
i want to sell it in a level with a npc.
here is the npc script but it doesnt work :/
could someone please tell me what im doing wrong :3?
thanks
gunderak

//#CLIENTSIDE
function onCreated() {
dontblock;
}
function onPlayerChats() {
if (player.chat =="/Buy Gund Dino Hat"){
if(playerrupees>=1000)
addweapon("Hats/Dino Hat");
playerrupees-=1000;
}
}

ffcmike 07-09-2011 04:25 PM

Quote:

Originally Posted by Gunderak (Post 1658056)
basically i have a hat setup as a weapon so u equip it and press d
i want to sell it in a level with a npc.
here is the npc script but it doesnt work :/
could someone please tell me what im doing wrong :3?
thanks
gunderak

//#CLIENTSIDE
function onCreated() {
dontblock;
}
function onPlayerChats() {
if (player.chat =="/Buy Gund Dino Hat"){
if(playerrupees>=1000)
addweapon("Hats/Dino Hat");
playerrupees-=1000;
}
}

Same issue as your previous thread, addweapon (and presumably player.rupees) need to be used serverside, which requires a trigger.

Gunderak 07-09-2011 04:37 PM

could you show me an example of it as a trigger so i can study it and figure out exactly how itd work?

ffcmike 07-09-2011 04:47 PM

Quote:

Originally Posted by Gunderak (Post 1658059)
could you show me an example of it as a trigger so i can study it and figure out exactly how itd work?

Well actually, if you're going to do it entirely by chat it would be better to just have the entire thing serverside rather than use a trigger, the main reason you'd want it clientside is to have something like a GUI prompt.

Otherwise the most basic thing to do would be:

PHP Code:

function onCreated(){
  
//define area inwhich to receive the triggeraction
  
this.setshape(1, 32, 32);
  
this.dontblock();
}

function 
onActionPurchase(){
  if (
player.rupees >= 1000){
    
//ensure you have not already purchased the hat
    
if(player.findweapon("Hats/Dino Hat") == NULL){
      
player.addweapon("Hats/Dino Hat");
      
player.rupees -= 1000;
    }
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat == "/Buy Gund Dino Hat"){
    if (
player.rupees >= 1000){
      
//ensure you have not already purchased the hat
      
if(findweapon("Hats/Dino Hat") == NULL){
        
triggeraction(this.x + 1, this.y + 1, "Purchase", NULL);
      }
    }
  }
} 

The conditions being serverside is important for the sake of security but I personally have it clientside too for the sake of preventing un-necessary triggers.

Gunderak 07-09-2011 05:01 PM

ah so u define the commands on server side bit and clientside uses them
thanks so much man now i understand it so much better =D
i also plan to make a /warn for a warning system... so far no luck rofl

ffcmike 07-09-2011 05:09 PM

Quote:

Originally Posted by Gunderak (Post 1658063)
ah so u define the commands on server side bit and clientside uses them

This isn't how it works, serverside and clientside code is completely separate with the exception of a few built in commands and variables that are automatically synchronised from serverside to clientside (such as dontblock, x, y etc), triggeraction is simply being used to communicate between your client and the server.

Gunderak 07-09-2011 05:10 PM

iv also added
}
else {
player.chat = "You Have Already Purchased This Weapon!";
}
thanks again man you really have helped me =D

Gunderak 07-09-2011 05:11 PM

ooh lol i thought triggeraction was triggering an action defined on creation rofl

ffcmike 07-09-2011 05:17 PM

Quote:

Originally Posted by Gunderak (Post 1658066)
ooh lol i thought triggeraction was triggering an action defined on creation rofl

It's:

PHP Code:

triggeraction(x, y, "Command", parameters); 

Which is invoking "onActionCommand" serverside, you can also use this to pass parameters to the server such as:

PHP Code:

function onActionCommand(temp.param1, temp.param2){
  echo(
temp.param1 SPC temp.param2);
}

//#CLIENTSIDE
function onPlayerTouchsMe(){
  
triggeraction(this.x + 1, this.y + 1, "Command", "hello", "world");
} 

Will echo "hello world" to RC.

cbk1994 07-09-2011 05:33 PM

If it's in a level NPC there's no reason to use a trigger. onPlayerChats (and onPlayerTouchsMe) is called both serverside and clientside in NPCs.

Gunderak 07-10-2011 09:10 AM

its in a weapon, also how would i make it if player.rupees <=1000; player.chat "u dont ave enough money";
iv tried to add it into it but im having no luck :/

fowlplay4 07-10-2011 09:24 AM

Quote:

Originally Posted by Gunderak (Post 1658169)
its in a weapon, also how would i make it if player.rupees <=1000; player.chat "u dont ave enough money";
iv tried to add it into it but im having no luck :/

With an if statement.

http://public.zodiacdev.com/index.ph...#Part_3:_Logic

Gunderak 07-10-2011 09:34 AM

i used an if statement but i am unsure where to put it
:/

fowlplay4 07-10-2011 09:51 AM

Quote:

Originally Posted by Gunderak (Post 1658173)
i used an if statement but i am unsure where to put it
:/

ffcmike pretty much gave you the solution already. I would recommend you read my entire guide and the linked resources on it, and attempt to learn how to script.

Guide Link: http://public.zodiacdev.com/index.php?title=Fowlplay4 (I'm pretty sure you've been linked to it at least 3 times now...)

Programming/scripting in general usually isn't something you can pick up with ease and it will take time.

But here's a visual for you:

http://img38.imageshack.us/img38/7408/thelogic.png

If you understand that image, and you understand what certain pieces of code actually does you should be able to figure out where the logic needs to be placed.

Gunderak 07-10-2011 10:26 AM

so somthing like the first bit then
if player.rupees <=1000;
triggerserver blah blah blah;
}
else {
player.chat = "I Dont Have Enough Money!";
return;

would that do it?
thanks btw for helping.
iv also made a wicked gui =D


function onActionServerSide() {
if (params[0] == "jail") {
findplayerbycommunityname(params[1]).setlevel2("jail.nw", 31.5, 28.5);
}
if (params[0] == "unjail") {
findplayerbycommunityname(params[1]).setlevel2("ge_f2.nw", 0, 24);
}
if (params[0] == "warn") {
findplayerbycommunityname(params[1]).setlevel2("warning_room.nw", 37.5, 16.5);
}
}

//Scripted By Gunderak
//#CLIENTSIDE
function onKeyPressed(code, key, scancode) {
if (key == "3") {
new GuiWindowCtrl("MyGUI_Window1") {
profile = GuiBlueWindowProfile;
clientrelative = true;
clientextent = "161,87";

canmaximize = false;
canminimize = false;
canmove = true;
canresize = true;
closequery = false;
destroyonhide = true;
text = "Tools";
y = 96;

new GuiButtonCtrl("MyGUI_Button1") {
profile = GuiBlueButtonProfile;
text = "Jail";
width = 80;
}
new GuiButtonCtrl("MyGUI_Button2") {
profile = GuiBlueButtonProfile;
text = "Unjail";
width = 80;
y = 29;
}
new GuiButtonCtrl("MyGUI_Button3") {
profile = GuiBlueButtonProfile;
text = "Warn";
width = 80;
y = 58;
}
new GuiTextEditCtrl("MyGUI_TextEdit1") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 80;
x = 80;
y = 5;
}
new GuiTextEditCtrl("MyGUI_TextEdit2") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 80;
x = 80;
y = 34;
}
new GuiTextEditCtrl("MyGUI_TextEdit3") {
profile = GuiBlueTextEditProfile;
height = 20;
width = 80;
x = 80;
y = 64;
}
}
}
}

function MyGUI_Button1.onAction() {
triggerserver("gui",this.name,"jail",MyGUI_TextEdi t1.text);
}

function MyGUI_Button2.onAction() {
triggerserver("gui",this.name,"unjail",MyGUI_TextE dit2.text);
}

function MyGUI_Button3.onAction() {
triggerserver("gui",this.name,"warn",MyGUI_TextEdi t3.text);
}


now i just need to make it open that when u double click a player and automaticly fill the text box's with the players comm name =D

you wouldnt happen to know how to do that would you :3?

thanks again
-Gunderak

cbk1994 07-10-2011 01:52 PM

Quote:

Originally Posted by Gunderak (Post 1658179)
so somthing like the first bit then
if player.rupees <=1000;
triggerserver blah blah blah;
}
else {
player.chat = "I Dont Have Enough Money!";
return;

would that do it?

No, it wouldn't. Please use PHP tags when posting code in the future.

PHP Code:

if player.rupees <=1000;
triggerserver blah blah blah;
} else {
player.chat = "I Dont Have Enough Money!";
return; 

The first line is of an if-statement does not need a semicolon as it is not a command, it's a condition.

If you'd read the guide linked to you, you'd see that the proper syntax for an if-else statement is:

PHP Code:

if (condition) {
  
// do something
} else {
  
// do something else
} 

Your condition was backwards.

player.rupees <= 1000 would be true if they had less than or equal to 1000, so change it to player.rupees >= 1000 and plug that in:

PHP Code:

if (player.rupees >= 1000) {
  
// do something
} else {
  
// do something else
} 

Now all you have to do is either add the weapon or set the player's chat.

PHP Code:

if (player.rupees >= 1000) {
  
player.addWeapon("Hats/Dino Hat");
} else {
  
player.chat = "You don't have enough money!";
} 

You don't need a trigger as you should be doing this serverside.

Emera 07-10-2011 02:50 PM

This is a solution, but if you had lots of hats and you made a weapon for EVERY hat, then your weapons list would start to look like testbeds. Surely there is another way to go about doing this?

callimuc 07-10-2011 03:15 PM

Quote:

Originally Posted by Emera (Post 1658206)
This is a solution, but if you had lots of hats and you made a weapon for EVERY hat, then your weapons list would start to look like testbeds. Surely there is another way to go about doing this?

Use flags instead ;)

Example (using clientr.hats you need to add all the hats you want to your self):

PHP Code:

//#CLIENTSIDE
function onWeaponFired
  
//The following is just GUI stuff
  
new GuiWindowCtrl("TaylorWindow01") {
    
profile = GuiBlueWindowProfile;
    
x = 10;
    
y = 10;
    
canminimize = canmaximize = canresize = false;
    
canclose = canmove = true;
    
width = 180;
    
height = 90;
    
text = "Simple Hat setter";
    
    new 
GuiPopUpMenuCtrl("TaylorLister01") {
      
profile = GuiBluePopUpMenuProfile;
      
textprofile = GuiBlueTextListProfile;
      
scrollprofile = GuiBlueScrollProfile;
      
x = 10;
      
y = 30;
      
width = 160;
      
height = 20;
      
text = player.attr[1];
      
clearRows();
      for (
temp.value: clientr.hats)  //from here
      
{
        
addRow(0, temp.value);
      } 
//to here is the part to list the hats
      
sort();
    }
   
    new 
GuiButtonCtrl("TaylorButton01") {
      
profile = GuiBlueButtonProfile;
      
position = {10, 50};
      
extent = {88, 20};
      
text = "Load";
    }
  }
}


function 
TaylorButton01.onAction(){  //you pressed the button TaylorButton01
  
player.attr[1] = TaylorButton01.text; //sets the hat you choosed
} 

Sure there are a lot of other ways you can do it. This was just a simple one so you see how it generally works.


All times are GMT +2. The time now is 10:57 PM.

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