Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Bombs and Bows (https://forums.graalonline.com/forums/showthread.php?t=134263223)

iBeatz 05-19-2011 06:49 PM

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.

Tigairius 05-19-2011 06:50 PM

Quote:

Originally Posted by mrnothersan (Post 1650597)
i know i know :p

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

Tigairius 05-19-2011 06:52 PM

Quote:

Originally Posted by iBeatz (Post 1650599)
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.

iBeatz 05-19-2011 07:06 PM

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

Soala 05-19-2011 07:08 PM

Quote:

Originally Posted by iBeatz (Post 1650608)
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.

iBeatz 05-19-2011 07:14 PM

Quote:

Originally Posted by Soala (Post 1650609)
A memory editor allows you to edit the game, so it's basically a hack.

Gotta love the players... :rolleyes:

mrnothersan 05-19-2011 07:29 PM

Quote:

Originally Posted by Tigairius (Post 1650591)
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

mrnothersan 05-19-2011 07:30 PM

Quote:

Originally Posted by iBeatz (Post 1650612)
Gotta love the players... :rolleyes:

Yep >_<

mrnothersan 05-20-2011 02:29 PM

Quote:

Originally Posted by mrnothersan (Post 1650616)
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 >.<...

mrnothersan 05-21-2011 02:39 PM

And I still don't know...

WhiteDragon 05-21-2011 07:35 PM

Quote:

Originally Posted by mrnothersan (Post 1650865)
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.


All times are GMT +2. The time now is 03:39 PM.

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