Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 05-19-2011, 06:49 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
PHP Code:
function onCreated(){
  
setshape(1,32,32);   //Set the shape of the NPC serverside so the triggeractions work.
}

function 
onActionGiveBombs(bombrequest){   // Executing the GiveBombs action.
  
if((99 player.bombs) > bombrequest){
    
player.bombs += bombrequest;
    
player.chat "You received "@bombrequest SPC "bombs!";
  }
  else {
    
player.bombs += 99 player.bombs;
  }
}

function 
onActionGiveArrows(arrowrequest){   // Executing the GiveArrows action.
  
if((99-player.darts) > arrowrequest){
    
player.darts += arrowrequest;
    
player.chat "You received "@arrowrequest SPC "arrows!";
  }
  else {
    
player.darts += 99-player.darts;
  }
}

//#CLIENTSIDE

function onCreated(){
  
setshape(1,32,32);
}

function 
onPlayerChats(){
  
temp.tokens player.chat.tokenize();   // Tokenizing each word in the player's chat.
  
if(temp.tokens[0] > && temp.tokens[0] <= 99){   // Checking if the requested amount is more than 0 and less than or equal to 99.
    
if(temp.tokens[1] == "bombs"){   // Checking if the player asked for bombs or arrows.
      
triggeraction(this.x+.5,this.y+.5,"GiveBombs",temp.tokens[0]);   // Triggering the GiveBombs function on the serverside.
    
}
    else if(
temp.tokens[1] == "arrows"){
      
triggeraction(this.x+.5,this.y+.5,"GiveArrows",temp.tokens[0]);   // Triggering the GiveArrows function on the serverside.
    
}
  }

This script adds both bombs and arrows, depending on what the second word is in you chat. It works in a level NPC.
Bombs and arrows can only be added serverside, which is why the triggeractions are placed in the script.
Your welcome.
__________________

Intelligence without ambition is like a bird without wings.


Last edited by iBeatz; 05-19-2011 at 07:01 PM.. Reason: Error in script.
Reply With Quote
  #17  
Old 05-19-2011, 06:50 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by mrnothersan View Post
i know i know

where would i put the PHP code...
Well, it's not PHP code, it's GScript2. I used PHP tags because we don't have GScript2 tags on the forums unfortunately.

However, to answer your question, you'd place it in a level. Then when you go to the level, you would say "10 bombs".
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #18  
Old 05-19-2011, 06:52 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by iBeatz View Post
This script adds both bombs and arrows, depending on what the second word is in you chat. It works in a level NPC.
Bombs and arrows can only be added serverside, which is why the triggeractions are placed in the script.
Your welcome.
This script is good if bombs/arrows are not a big deal to your server (like, not a major part of the economy or anything), but the script is bad if you don't want players to get 99 free arrows/bombs. I say this, because the triggers in your script on the clientside are insecure, you shouldn't pass the value of bombs/arrows from the clientside because they can be edited with memory editors by players.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #19  
Old 05-19-2011, 07:06 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
I did it that way because he did not specify that he wanted gralats to be deducted.
And what in God's name is a memory editor? o_o
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #20  
Old 05-19-2011, 07:08 PM
Soala Soala is offline
Ideas on Fire
Soala's Avatar
Join Date: Jun 2007
Location: In my head
Posts: 3,208
Soala is a jewel in the roughSoala is a jewel in the rough
Quote:
Originally Posted by iBeatz View Post
I did it that way because he did not specify that he wanted gralats to be deducted.
And what in God's name is a memory editor? o_o
A memory editor allows you to edit the game, so it's basically a hack.
Reply With Quote
  #21  
Old 05-19-2011, 07:14 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Quote:
Originally Posted by Soala View Post
A memory editor allows you to edit the game, so it's basically a hack.
Gotta love the players...
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #22  
Old 05-19-2011, 07:29 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by Tigairius View Post
PHP Code:
function onPlayerChats() {
  if (
player.chat == "10 bombs") {
    
player.bombs += 10;
  }


I didn't say what i meant very clearly... i mean if the the player says "#amount bombs" they get that many... and charge 1 gralat per bomb
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #23  
Old 05-19-2011, 07:30 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by iBeatz View Post
Gotta love the players...
Yep
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #24  
Old 05-20-2011, 02:29 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
Quote:
Originally Posted by mrnothersan View Post
I didn't say what i meant very clearly... i mean if the the player says "#amount bombs" they get that many... and charge 1 gralat per bomb
D: i still dont know >.<...
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #25  
Old 05-21-2011, 02:39 PM
mrnothersan mrnothersan is offline
Owner of MrNothersan
Join Date: Mar 2011
Location: On the Computer
Posts: 97
mrnothersan is an unknown quantity at this point
Send a message via AIM to mrnothersan Send a message via MSN to mrnothersan
And I still don't know...
__________________

Regards
MrNothersan - Playerworld owner


Staff Hirings Thread for MrNothersan: http://forums.graalonline.com/forums....php?p=1639180

Reply With Quote
  #26  
Old 05-21-2011, 07:35 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by mrnothersan View Post
And I still don't know...
I think you should take a glance at the NPC Scripting forum rules:
"Be clear on your ability level. In other words, do not post asking for scripts, or asking people to fix scripts that are above your ability level. If you are writing a script to aid learning, then try writing a simpler script. If you are looking for a script for a server, then the best solution is probably to hire a scripter."

Tig's script provides a decent base for a solution to your problem. If you want to change gralats, take a look at the variable player.gralats

If you want to split player.chat into two parts, look at the tokenize function.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:10 AM.


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