ID:269172
 
heya all I'm new to coding and I'm planning to make a RGP game, I read the tutorital of zilal ( it worked XD)
first of all I want to make some NPC's
but how can I program the NPC's so they can move and use some verbs?
plz I really need sum help with this game....
O-matic wrote:
heya all I'm new to coding and I'm planning to make a RGP game, I read the tutorital of zilal ( it worked XD)
first of all I want to make some NPC's
but how can I program the NPC's so they can move and use some verbs?
plz I really need sum help with this game....

NPC's can't really use verbs because verbs are meant to only be used by players. You can make it look as if they're using verbs though.

Here's an example NPC:
mob
NPC
icon='npc.dmi'
New() // New is called when the NPC is created
spawn() // spawn() is used to schedule code to execute at a future time
// It's used here so that the AI_Loop(), which never finishes, won't
// cause the other code in New() to never be run
AI_Loop() // Runs src's AI_Loop() procedure.
view(src) << "I am born!"

proc/AI_Loop()
while(src) // While the NPC still exists, keep doing the following, repeating it forever:
// Here's where you'd have the NPC do stuff.
// In this example, the NPC will walk around randomly
// and say something every few seconds.

step_rand(src) // This causes src, the NPC, to take a step in a random direction

if(prob(10)) // prob() deals with probabilities. Because of the 10, 10 percent of the time it
// will return true, and the stuff inside the if() will happen
// So 1 out of every 10 steps the NPC will say "Hello world!"
view(src) << "Hello world!" // The NPC says hello to everyone in its view

sleep(rand(10, 40)) // sleep() causes the procedure to pause for the amount of
// time it was passed. rand() randomly chooses a number
// between the two numbers it's passed.
// So in this example, the NPC pauses between 1 and 4 seconds every time
// it moves
In response to Jon88
thanks thats an example I begin to understand it, but I still dont understand what I have to put on the empty places you set....
and could you please make the code so the NPC will attack every1 who comes close to him?

Thanks in REAL advance