![]() |
| Let me know how you like these tutorials, and feel free to suggest corrections or new topics..... |
| AIM: Aylad2001 |
| The triggeraction command is used for making npcw's interact with other players and/or npcs. For the npcw to interact with another player that player must also have the npc. If you want it to work with all players put the scripting into a system npc or make players pick up the npcw. Ill use bread making for the example of npcw to npc interaction as nothing else springs to mind. ------------------------------------------------- //The NPC Weapon if(playertouchsme) //or another event happens { toweapons itemname; //name of the npcw breadmaking=2; //This is used to set how quick the bread making will go. At the moment it will increase by 2 each time the npcw is used. } //anything else added in there is optional eg. hide; if(weaponfired) //when the player uses the npcw { freezeplayer 0.5; //This is used so the player can only use the npcw every so often so that the bread is not made in a couple of seconds. //Other things could be added here. eg. setani triggeraction playerx+1.5+vecx(playerdir)*2,playery+1+vecy(playerdir)*2 //the coordinates npcs needs to be at to interact. The coordinates stated are for if the npc is just in front of the player. ,bread //the name of the action ,#v(breadmaking); //The variable that sets how quick the bread making will go. This was set earlier. } ------------------------------------------------- Then you need the npcs. ------------------------------------------------- //The NPC if (actionbread //the action that was set in the npcw && this.breadpercent<=99) //Only increases the this.flag while it is less than 100. { breadmaking = strtofloat(#p(0)); //sets the action paremeter. this.breadpercent+=breadmaking; //increases the this.breadpercent flag by 2 (as this is what the breadmaking variable is set to) message #v(this.breadpercent)%; //optional - shows the perecentage done } if (this.breadpercent>=100) //when the percentage reaches 100 (or more) { setstring bread,#v(strtofloat(#s(bread))+1); //adds 1 to a bread string. destroy; //removes the npc } ------------------------------------------------- That is a basic script which could be improved up on. For example changing the graphic file at a certain stage(s). eg. if (this.breadpercent>=50) {setimg bread50percent.gif;} The NPC script could also be placed in a text file and then use putnpc. eg. if(playerchats&&strequals(#c,bread)) {putnpc bread.gif,bread.txt,30,30} Here is an example of a npcw that interacts with other players. Only the npcw is needed for npcw to player interaction. ------------------------------------------------- //The NPC Weapon if (playertouchsme) { toweapons Money Steal; //name of the npcw. } if (weaponfired) { triggeraction playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2 ,steal,; //same as before but this time there is no variable set and the action is called steal } if (actionsteal) //action was set above { this.steal=random(0,9); //sets a this.flag; if(this.steal<=4 && playerrupees>=1) //If the this.flag is less than 5 (50% chance) and the players rupees are more than 0 then steal will work { playerrupees-=1; //the player who is stolen from loses 1 gralat lay2 greenrupee,x,y; //1 gralat is dropped onto the floor. } } |
| This tutorial was not written by me. I'm not sure I understand 'triggeraction' myself. Questions or comments about this tutorial should be posted on the Haven Forum. See the link at the bottom of the page. The author told me he didn't want the credit for this, so here it is. |