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 07-09-2011, 04:19 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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;
}
}
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 07-09-2011, 04:25 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.
Reply With Quote
  #3  
Old 07-09-2011, 04:37 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
could you show me an example of it as a trigger so i can study it and figure out exactly how itd work?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 07-09-2011, 04:47 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.
Reply With Quote
  #5  
Old 07-09-2011, 05:01 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #6  
Old 07-09-2011, 05:09 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.
Reply With Quote
  #7  
Old 07-09-2011, 05:10 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
iv also added
}
else {
player.chat = "You Have Already Purchased This Weapon!";
}
thanks again man you really have helped me =D
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #8  
Old 07-09-2011, 05:11 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
ooh lol i thought triggeraction was triggering an action defined on creation rofl
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #9  
Old 07-09-2011, 05:17 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Gunderak View Post
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.
Reply With Quote
  #10  
Old 07-09-2011, 05:33 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
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.
__________________
Reply With Quote
  #11  
Old 07-10-2011, 09:10 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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 :/
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #12  
Old 07-10-2011, 09:24 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Gunderak View Post
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
__________________
Quote:
Reply With Quote
  #13  
Old 07-10-2011, 09:34 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
i used an if statement but i am unsure where to put it
:/
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #14  
Old 07-10-2011, 09:51 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Gunderak View Post
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:



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.
__________________
Quote:
Reply With Quote
  #15  
Old 07-10-2011, 10:26 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #16  
Old 07-10-2011, 01:52 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 Gunderak View Post
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.
__________________
Reply With Quote
  #17  
Old 07-10-2011, 02:50 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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?
__________________
Reply With Quote
  #18  
Old 07-10-2011, 03:15 PM
callimuc callimuc is offline
ジ
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Emera View Post
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.
__________________
MEEP!

Last edited by callimuc; 07-10-2011 at 03:41 PM..
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 01:12 AM.


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