Page 1 of 1

Designing a basic school

Posted: Sun Oct 14, 2012 2:24 pm
by Omni
So I've been designing schools with OSDs on my world. Here I will include the basic implementation of the code for one of them. Everything runs on OSDs. When a player chooses to learn a skill, a playervar is set to a value. So that they're not able to learn said skill again. If they try, and OSD pops up telling they already know the skill. This is all decided with an if else statement. However, I've run into a problem. And I did on purpose. When I choose to forget said skill. The playervar is not reset. And so the server still thinks I know the skill. And I can't learn it again. The OSD pops up telling me I already know the skill, because the player var has not been reset.

How can I tell the server to reset the playervar in quiestion once choosing to forget the skill?

Apart from that, the script works perfectly.

Code: Select all

Event( "OSDSelect", "Drill:Lskill1" ) 
   { 
    
    if($playervar1 = 1)
{

osdcreate(OSDLIST,"No1","Sorry")
osdadditem(OSDTEXT,"","Sorry, but you're already a Drillmaster. There's nothing new we can teach you. Perhaps you could teach us.")
osdadditem(OSDEXITBUTTON,"Exit","Leave the temple")
osdactivate()

}

else

{
    *grantskill %PLAYER% Drillmaster
    *msg %PLAYER% You are now a Drillmaster
     $playervar1=1

}
    
   }

Event( "OSDSelect", "Mush:Lskill2" ) 
   { 
    
    if($playervar2 = 2)
{

osdcreate(OSDLIST,"No2","Sorry")
osdadditem(OSDTEXT,"","Sorry, but you're already a Mushroom Farmer. There's nothing new we can teach you. Perhaps you could teach us.")
osdadditem(OSDEXITBUTTON,"Exit","Leave the temple")
osdactivate()

}

else

{
    *grantskill %PLAYER% Mushroom Farmer
    *msg %PLAYER% You are now a Mushroom Farmer
     $playervar2=2

}
    
   }

Event( "OSDSelect", "Chance:Lskill3" ) 
   { 
    
    if($playervar3 = 3)
{

osdcreate(OSDLIST,"No3","Sorry")
osdadditem(OSDTEXT,"","Sorry, but you're already a Chancellor. There's nothing new we can teach you. Perhaps you could teach us.")
osdadditem(OSDEXITBUTTON,"Exit","Leave the temple")
osdactivate()

}

else

{
    *grantskill %PLAYER% Chancellor
    *msg %PLAYER% You are now a Chancellor
     $playervar3=3

}
    
   }


Event( "OSDSelect", "Cook:Lskill4" ) 
   { 
    
    if($playervar4 = 4)
{

osdcreate(OSDLIST,"No4","Sorry")
osdadditem(OSDTEXT,"","Sorry, but you're already a Cook. There's nothing new we can teach you. Perhaps you could teach us.")
osdadditem(OSDEXITBUTTON,"Exit","Leave the temple")
osdactivate()

}

else

{
    *grantskill %PLAYER% Cook
    *msg %PLAYER% You are now a Cook
     $playervar4=4

}
    
   }

Posted: Sun Oct 14, 2012 4:53 pm
by Omni
Well, after a bit of research. I found the solution. The event "SkillRemoved" does the job. For future coders, here's the code which fixed the issue:

Code: Select all

Event( "SkillRemoved", "Drillmaster" ) 
{

$playervar1=0


}

Event( "SkillRemoved", "Mushroom Farmer" ) 
{

$playervar2=0


}


Event( "SkillRemoved", "Chancellor" ) 
{

$playervar3=0


}

Event( "SkillRemoved", "Cook" ) 
{

$playervar4=0


}

Posted: Sun Oct 14, 2012 8:40 pm
by Mit
thats a solution, but you don't really need to use player vars afaik. (Unless you're going to be doing something particularly custom or 'interesting' in your school or skill system).

sysPlayerSkillLevel can be used to find the player's current level of any skill - 0 means the player has not tried to learn this yet. (so you could replace all your 'if playervar ==... ' with if sysPlayerSkillLevel("Mushroom Farmer") > 0 ... etc, and not need the SkillRemoved events.)

Posted: Mon Oct 15, 2012 11:11 am
by Omni
I see.

Well, a possible use of that implementation would be for the case of skills related to each other. For example, if you have Skill1 you can't obtain Skill2, and so forth. The playervars would serve as the relation, or the restriction so to speak, of the skills.

Thanks Mit.

Posted: Mon Oct 15, 2012 11:19 am
by Omni
Here's another question though. I want them to learn the skills after a set amount of time. And print a message "Skill will be learned in X hours". How do I do that? I need to make the script wait a set amount of time before executing. The first thing that pops into my mind is the sleep() function. But how does it work? If I want to make it wait 2 hours, what number should I put in the argument?

Posted: Mon Oct 15, 2012 12:43 pm
by Mit
its possible to use sleep() for that kinda thing, but its not what they're really intended for. (They're intended for shorter-term things like pausing a script for 10 seconds or something). Main issues with sleeps are they aren't 'persistent', and are terminated when you reload the script or restart the server. They also have an internal overhead for the server program, and can become very confusing to develop with if you've got loads of events all sleeping - especially if people are continually triggering new ones.
Timers are more suitable for longer term things like events that happen in a few hours, but again they're limited by not being persistent and you have to be careful to make sure you don't end up with hundreds of timers all queued up. (Timers are used to run the automatic crow tournament on civ).

Anyway, for the specific case of skills you can again just make use of the built in functionality for having a learn-time for each skill. Rather than *grantskill, use *addskill which has the format of :

Code: Select all

*addskill [PLAYER_NAME] [SKILL_NUMBER] [GAMEDAYS_TO_LEARN]
which is how all the skill buildings like the Academy work in Civilization. ding.

p.s. Still not quite sure why you'd need to use PlayerVars to do things for linking skills.. i.e. you could do "if you have Skill1 you can't obtain Skill2" with a bit of script that checks whether the user has one skill, and if so, doesn't call the addskill command for the second. (Being able to do custom things like that is certainly the big advantage of the scripting language, rather than just doing everything in config files and settings, as we used to). Its not that i've got something against PlayerVars, its just that theres a finite amount and if you can avoid using them it means you've still got plenty available for when you want to do something that can't be done in the standard systems.