Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Item Spawn (https://forums.graalonline.com/forums/showthread.php?t=134264484)

Emera 09-05-2011 05:21 PM

Item Spawn
 
I am trying to make an item spawner. I am making it create an NPC at my mouses x and y, and when it is touched, it adds the weapon to the player and destroys itself. However, I can't get it to work. When I fire the weapon, it puts the NPC with the image bcalarmclock.png, and it changes the chat to the players chat. That is all done on created. In the class, this is what I have...
PHP Code:

//Works
function onCreated() {
  
setimg("block.png");
  
this.chat text;
}
//Doesn't work
function onPlayerTouchsMe() {
  
addweapon(this.chat);
  
player.chat "Green";
  
destroy();


Any suggestions?
I think it is something to do with the PlayerTouchsMe

furry_mougle 09-05-2011 05:49 PM

How would the class know you're touching the NPC in the first place?

Emera 09-05-2011 05:52 PM

Nvm now I fixed it. Thanks anyway.

fowlplay4 09-05-2011 05:52 PM

Try giving it a shape:

PHP Code:

function onCreated() {
  
this.image "block.png";
  
setshape(1,32,32);



Emera 09-05-2011 06:07 PM

When you touch it, it destroys on your screen, but not on other players. X_X

Class
PHP Code:

function onCreated() {
  
setimg("block.png");
  
this.chat text;
  
setshape(1,32,32);
}
//#CLIENTSIDE
function onPlayerTouchsMe() {
  
addweapon(this.chat);
  
destroy();


Weapon
PHP Code:

function onActionServerSide() {
  if (
params[0] == "spawn") {
    
temp.npc putnpc2(params[1],params[2], "join(\"emera_spawn\");");
    
text params[3];
  }
}
//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/spawn ")) {
    
triggerserver("gui",this.name,"spawn",mousex,mousey,player.chat.substring(7));
  }



gaben 09-05-2011 06:12 PM

http://gscript.graal.net/onPlayerTouchsMe

Just execute destroy() serverside? wat

Emera 09-05-2011 06:14 PM

Quote:

Originally Posted by gaben (Post 1667150)
http://gscript.graal.net/onPlayerTouchsMe

Just execute destroy() serverside? wat

Whenever I try to execute playertouchsme serverside it doesn't work though.

fowlplay4 09-05-2011 06:15 PM

player.addweapon() is a server-side function, and destroying it on the client-side will only destroying it on your client (screen).

Removing //#CLIENTSIDE should make it work the way you want.

gaben 09-05-2011 06:16 PM

Quote:

Originally Posted by Emera (Post 1667151)
Whenever I try to execute playertouchsme serverside it doesn't work though.

playertouchsme is clientside? also what fp4 said sounds just about right anyway

Emera 09-05-2011 06:17 PM

Quote:

Originally Posted by fowlplay4 (Post 1667152)
player.addweapon() is a server-side function, and destroying it on the client-side will only destroying it on your client (screen).

Removing //#CLIENTSIDE should make it work the way you want.

Then the block doesn't even destroy. It doesn't work if I remove the clientside above onPlayerTouchsMe

Mark Sir Link 09-05-2011 10:01 PM

function onPlayerTouchsme() will work serverside in everything but a weapon, but for what you are describing you should be using a class anyway.

cbk1994 09-05-2011 10:54 PM

Quote:

Originally Posted by Emera (Post 1667155)
Then the block doesn't even destroy. It doesn't work if I remove the clientside above onPlayerTouchsMe

Have you tried putting echoes in relevant locations to try to find the problem?


All times are GMT +2. The time now is 07:11 AM.

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